From 419f68b0f2ead6fdc04b05a8aed9d03bac36881c Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Wed, 23 Jan 2013 19:00:48 +0100 Subject: [PATCH 1/6] [supervision] add a simple popup to choose the simtype and launch via the new ppzsim-launch python script --- conf/control_panel.xml.example | 2 +- sw/supervision/pc_control_panel.ml | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/conf/control_panel.xml.example b/conf/control_panel.xml.example index cca9f6c51c6..ac8b4520efe 100644 --- a/conf/control_panel.xml.example +++ b/conf/control_panel.xml.example @@ -49,7 +49,7 @@ - + diff --git a/sw/supervision/pc_control_panel.ml b/sw/supervision/pc_control_panel.ml index 661d3013ac4..0df7e7fcd24 100644 --- a/sw/supervision/pc_control_panel.ml +++ b/sw/supervision/pc_control_panel.ml @@ -141,13 +141,28 @@ let double_quote = fun s -> else s +let get_simtype = fun () -> + match GToolbox.question_box ~title:"Simulator type" ~buttons:["Simple (fixedwing)"; "JSBSim"; "NPS (rotorcraft)"] "Choose the simulator type:" with + 1 -> "simple_fw" + | 2 -> "jsbsim" + | 3 -> "nps" + | _ -> "none" + let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) -> let run_gcs = fun () -> run_and_monitor ?file gui log "GCS" "" and run_server = fun args -> run_and_monitor ?file gui log "Server" args and run_sitl = fun ac_name -> - let args = sprintf "-a %s -boot -norc" ac_name in + let get_args = fun simtype ac_name-> + match simtype with + "simple_fw" -> sprintf "-a %s -t %s --boot --norc" ac_name simtype + | "jsbsim" -> sprintf "-a %s -t %s" ac_name simtype + | "nps" -> sprintf "-a %s -t %s" ac_name simtype + | _ -> sprintf "-a %s" ac_name + in + let sim_type = get_simtype () in + let args = get_args sim_type ac_name in run_and_monitor ?file gui log "Simulator" args in @@ -196,9 +211,9 @@ let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) -> (* Simulations *) let simulation = fun () -> + run_sitl (Gtk_tools.combo_value ac_combo); run_gcs (); - run_server "-n"; - run_sitl (Gtk_tools.combo_value ac_combo) in + run_server "-n" in (* Run session *) let callback = fun () -> From c3f63ca63ba1465d54f0a18fb48e9a0a10e4c68d Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Thu, 24 Jan 2013 11:35:41 +0100 Subject: [PATCH 2/6] [sim] check targets and ask which simulator to use --- sw/lib/ocaml/gtk_tools.ml | 8 ++++++++ sw/lib/ocaml/gtk_tools.mli | 1 + sw/simulator/ppzsim-launch | 8 ++++---- sw/supervision/paparazzicenter.ml | 2 +- sw/supervision/pc_control_panel.ml | 29 +++++++++++++++++++---------- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/sw/lib/ocaml/gtk_tools.ml b/sw/lib/ocaml/gtk_tools.ml index 140b7312e44..f42f89bf915 100644 --- a/sw/lib/ocaml/gtk_tools.ml +++ b/sw/lib/ocaml/gtk_tools.ml @@ -68,6 +68,14 @@ let combo_value = fun ((combo: #GEdit.combo_box), (_,column)) -> | None -> raise Not_found | Some row -> combo#model#get ~row ~column +let combo_values_list = fun (combo : combo) -> + let (store, column) = combo_model combo in + let values = ref [] in + store#foreach (fun _ row -> + values := !values @ [store#get ~row ~column]; + false); + !values + let combo_separator = "--" let combo = fun strings vbox -> diff --git a/sw/lib/ocaml/gtk_tools.mli b/sw/lib/ocaml/gtk_tools.mli index f0980b13d1b..737f1120405 100644 --- a/sw/lib/ocaml/gtk_tools.mli +++ b/sw/lib/ocaml/gtk_tools.mli @@ -54,6 +54,7 @@ val add_to_combo : combo -> string -> unit val combo_separator : string val combo_value : combo -> string +val combo_values_list : combo -> string list val select_in_combo : combo -> string -> unit val combo_connect : combo -> (string -> unit) -> unit diff --git a/sw/simulator/ppzsim-launch b/sw/simulator/ppzsim-launch index 3ae6532c150..ea1a1b276cd 100755 --- a/sw/simulator/ppzsim-launch +++ b/sw/simulator/ppzsim-launch @@ -39,9 +39,9 @@ def main(): action="store", help="aircraft name to use") parser.add_option("-t", "--type", dest="simtype", - type='choice', choices=['simple_fw', 'jsbsim', 'nps'], - action="store", default="simple_fw", - help="Simlator type to start: simple_fw, jsbsim or nps (Default: %default)") + type='choice', choices=['sim', 'jsbsim', 'nps'], + action="store", default="sim", + help="Simlator type to start: sim, jsbsim or nps (Default: %default)") parser.add_option("-b", "--ivy_bus", dest="ivy_bus", action="store", help="Ivy Bus broadcast address.") parser.add_option("-f", "--fg_host", dest="fg_host", action="store", @@ -84,7 +84,7 @@ def main(): simargs = [] - if options.simtype == "simple_fw": + if options.simtype == "sim": simdir = "sim" if options.boot: simargs.append("-boot") diff --git a/sw/supervision/paparazzicenter.ml b/sw/supervision/paparazzicenter.ml index 63358ef104c..cc4b8dc333f 100644 --- a/sw/supervision/paparazzicenter.ml +++ b/sw/supervision/paparazzicenter.ml @@ -236,7 +236,7 @@ let () = AC.build_handler ~file gui ac_combo target_combo log; - let session_combo, execute_session = CP.supervision ~file gui log ac_combo in + let session_combo, execute_session = CP.supervision ~file gui log ac_combo target_combo in (* Quit button *) ignore (gui#menu_item_quit#connect#activate ~callback:(quit_button_callback gui ac_combo session_combo target_combo)); diff --git a/sw/supervision/pc_control_panel.ml b/sw/supervision/pc_control_panel.ml index 0df7e7fcd24..ca0f464e480 100644 --- a/sw/supervision/pc_control_panel.ml +++ b/sw/supervision/pc_control_panel.ml @@ -141,27 +141,36 @@ let double_quote = fun s -> else s -let get_simtype = fun () -> - match GToolbox.question_box ~title:"Simulator type" ~buttons:["Simple (fixedwing)"; "JSBSim"; "NPS (rotorcraft)"] "Choose the simulator type:" with - 1 -> "simple_fw" - | 2 -> "jsbsim" - | 3 -> "nps" - | _ -> "none" +let get_simtype = fun (target_combo : Gtk_tools.combo) -> + (* get the list of possible targets *) + let targets = Gtk_tools.combo_values_list target_combo in + (* filter non simulator targets *) + let sim_targets = ["sim"; "jsbsim"; "nps"] in + let targets = List.filter (fun t -> List.mem t sim_targets) targets in + (* open question box and return corresponding simulator type *) + match targets with + [] -> "none" + | [t] -> t + | l -> + match GToolbox.question_box ~title:"Simulator type" ~buttons:l "Choose the simulator type:" with + | 0 -> "none" + | choice -> List.nth targets (choice-1) -let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) -> +let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) (target_combo : Gtk_tools.combo) -> let run_gcs = fun () -> run_and_monitor ?file gui log "GCS" "" and run_server = fun args -> run_and_monitor ?file gui log "Server" args and run_sitl = fun ac_name -> - let get_args = fun simtype ac_name-> + let get_args = fun simtype ac_name -> match simtype with - "simple_fw" -> sprintf "-a %s -t %s --boot --norc" ac_name simtype + "sim" -> sprintf "-a %s -t %s --boot --norc" ac_name simtype | "jsbsim" -> sprintf "-a %s -t %s" ac_name simtype | "nps" -> sprintf "-a %s -t %s" ac_name simtype | _ -> sprintf "-a %s" ac_name in - let sim_type = get_simtype () in + let sim_type = get_simtype target_combo in + prerr_endline sim_type; let args = get_args sim_type ac_name in run_and_monitor ?file gui log "Simulator" args in From bab3e018afd9994630022e369d334eb48383efd2 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 24 Jan 2013 11:54:40 +0100 Subject: [PATCH 3/6] [simulators] renamed ppzsim-launch to pprzsim-launch, minor updates to help --- .../{ppzsim-launch => pprzsim-launch} | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) rename sw/simulator/{ppzsim-launch => pprzsim-launch} (84%) diff --git a/sw/simulator/ppzsim-launch b/sw/simulator/pprzsim-launch similarity index 84% rename from sw/simulator/ppzsim-launch rename to sw/simulator/pprzsim-launch index ea1a1b276cd..c126dc90bb7 100755 --- a/sw/simulator/ppzsim-launch +++ b/sw/simulator/pprzsim-launch @@ -36,16 +36,16 @@ def main(): usage = "usage: %prog -a -t [sim arguments]\nRun %prog --help to list the options." parser = OptionParser(usage) parser.add_option("-a", "--aircraft", dest="ac_name", - action="store", - help="aircraft name to use") + action="store", metavar="NAME", + help="Aircraft name to use") parser.add_option("-t", "--type", dest="simtype", type='choice', choices=['sim', 'jsbsim', 'nps'], action="store", default="sim", help="Simlator type to start: sim, jsbsim or nps (Default: %default)") parser.add_option("-b", "--ivy_bus", dest="ivy_bus", action="store", - help="Ivy Bus broadcast address.") - parser.add_option("-f", "--fg_host", dest="fg_host", action="store", - help="FlightGear host to connect to for visualization, e.g. 127.0.0.1") + metavar="BUS", help="Ivy Bus broadcast address (127.255.255.255)") + parser.add_option("-f", "--fg_host", dest="fg_host", action="store", metavar="HOST", + help="Host for FlightGear visualization (e.g. 127.0.0.1)") parser.add_option("-v", "--verbose", action="store_true", dest="verbose") @@ -59,19 +59,23 @@ def main(): # special options for NPS nps_opts = OptionGroup(parser, "NPS Options", "These are only relevant to the NPS sim") - nps_opts.add_option("-p", "--fg_port", dest="fg_port", type="int", default=5501, - help="Port on FlightGear host to connect to (default %default)") - nps_opts.add_option("--fg_time_offset", type="int", action="store", - help="Time offset in seconds for FlightGear, e.g. 21600 for 6h.") - nps_opts.add_option("-j", "--js_dev", dest="js_dev", metavar="DEVICE_INDEX", action="store", type="int", default=-1, + nps_opts.add_option("-p", "--fg_port", dest="fg_port", metavar="PORT", + type="int", default=5501, action="store", + help="Port on FlightGear host to connect to (Default: %default)") + nps_opts.add_option("--fg_time_offset", type="int", action="store", metavar="SEC", + help="FlightGear time offset in seconds (e.g. 21600 for 6h)") + nps_opts.add_option("-j", "--js_dev", dest="js_dev", metavar="IDX", + type="int", default=-1, action="store", help="Use joystick with specified index (e.g. 0)") - nps_opts.add_option("--spektrum_dev", type="string", action="callback", callback=spektrum_callback, - help="Spektrum device to use, e.g. /dev/ttyUSB0") - nps_opts.add_option("--rc_script", type="int", action="store", - help="Number of RC script to use.") + nps_opts.add_option("--spektrum_dev", type="string", action="callback", + callback=spektrum_callback, metavar="DEV", + help="Spektrum device to use (e.g. /dev/ttyUSB0)") + nps_opts.add_option("--rc_script", type="int", action="store", metavar="NO", + help="Number of RC script to use") # special options for the JSBSim sim (without sensor models) - #jsbsim_opts = OptionGroup(parser, "JSBSim options", "These are only relevant to the jsbsim sim") + #jsbsim_opts = OptionGroup(parser, "JSBSim options", + # "These are only relevant to the jsbsim sim") parser.add_option_group(ocamlsim_opts) parser.add_option_group(nps_opts) From 17c6cf2cac7d92e9968513f817aab6f3c336a5c2 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 24 Jan 2013 13:01:44 +0100 Subject: [PATCH 4/6] [sim] removed launchsitl and replaced it with symlink to pprzsim-launch --- .gitignore | 1 - Makefile | 12 ++--------- Makefile.install | 2 +- conf/control_panel.xml.example | 2 +- src/launchsitl | 37 ---------------------------------- sw/simulator/Makefile | 6 +----- tests/sim/01_Microjet.t | 14 ++++++------- 7 files changed, 12 insertions(+), 62 deletions(-) delete mode 100755 src/launchsitl diff --git a/.gitignore b/.gitignore index 92f45690aa3..65869e83e67 100644 --- a/.gitignore +++ b/.gitignore @@ -138,7 +138,6 @@ # /sw/simulator/ /sw/simulator/gaia /sw/simulator/simhitl -/sw/simulator/launchsitl # /sw/supervision/ /sw/supervision/gtk_process.ml diff --git a/Makefile b/Makefile index a164982bd7d..d0ddb697472 100644 --- a/Makefile +++ b/Makefile @@ -208,18 +208,12 @@ sim: sim_static include Makefile.lpctools lpctools: lpc21iap usb_lib -commands: paparazzi sw/simulator/launchsitl +commands: paparazzi paparazzi: cat src/paparazzi | sed s#OCAMLRUN#$(OCAMLRUN)# | sed s#OCAML#$(OCAML)# > $@ chmod a+x $@ -sw/simulator/launchsitl: - cat src/$(@F) | sed s#OCAMLRUN#$(OCAMLRUN)# | sed s#OCAML#$(OCAML)# > $@ - chmod a+x $@ - -run_sitl : - $(PAPARAZZI_HOME)/var/$(AIRCRAFT)/sim/simsitl install : $(MAKE) -f Makefile.install PREFIX=$(PREFIX) @@ -238,7 +232,6 @@ clean: $(Q)find . -mindepth 2 -name Makefile -a ! -path "./sw/ext/*" -exec sh -c 'echo "Cleaning {}"; $(MAKE) -C `dirname {}` $@' \; $(Q)$(MAKE) -C $(EXT) clean $(Q)find . -name '*~' -exec rm -f {} \; - $(Q)rm -f paparazzi sw/simulator/launchsitl cleanspaces: find sw -path sw/ext -prune -o -name '*.[ch]' -exec sed -i {} -e 's/[ \t]*$$//' \; @@ -279,7 +272,6 @@ test: all replace_current_conf_xml run_tests restore_conf_xml .PHONY: all print_build_version update_google_version ground_segment \ subdirs $(SUBDIRS) conf ext lib multimon cockpit tmtc tools\ -static sim_static lpctools \ -commands run_sitl install uninstall \ +static sim_static lpctools commands install uninstall \ clean cleanspaces ab_clean dist_clean distclean dist_clean_irreversible \ test replace_current_conf_xml run_tests restore_conf_xml diff --git a/Makefile.install b/Makefile.install index 059a7280426..9cea7867acf 100644 --- a/Makefile.install +++ b/Makefile.install @@ -90,7 +90,7 @@ install_bin: $(INSTALL) paparazzi-make $(PREFIX)/usr/bin/ $(INSTALLDATA) -d $(DESTDIR)/sw/simulator $(INSTALL) sw/simulator/*.cmo $(DESTDIR)/sw/simulator - $(INSTALL) sw/simulator/launchsitl $(DESTDIR)/sw/simulator + $(INSTALL) sw/simulator/pprzsim-launch $(DESTDIR)/sw/simulator $(INSTALL) -d $(DESTDIR)/sw/ground_segment/cockpit $(INSTALL) -d $(DESTDIR)/sw/ground_segment/tmtc $(INSTALL) -d $(DESTDIR)/sw/ground_segment/multimon diff --git a/conf/control_panel.xml.example b/conf/control_panel.xml.example index ac8b4520efe..ac01febe429 100644 --- a/conf/control_panel.xml.example +++ b/conf/control_panel.xml.example @@ -49,7 +49,7 @@ - + diff --git a/src/launchsitl b/src/launchsitl deleted file mode 100755 index 261de6c4775..00000000000 --- a/src/launchsitl +++ /dev/null @@ -1,37 +0,0 @@ -#!OCAMLRUN OCAML -#load "unix.cma";; -let (//) = Filename.concat -let paparazzi_home = - try - Sys.getenv "PAPARAZZI_HOME" - with - _ -> Filename.concat (Sys.getenv "HOME") "paparazzi" - -let () = - let n = Array.length Sys.argv in - try - let rec loop = fun i -> - if Sys.argv.(i) = "-a" && (i+1) < n then - let ac = Sys.argv.(i+1) in - (* Shift other args *) - for j = i+2 to n-1 do Sys.argv.(j-2) <- Sys.argv.(j) done; - ac - else if i = n then raise Not_found - else loop (i+1) in - let ac = loop 0 in - let rec sim_type = fun i -> - if Sys.argv.(i) = "-jsbsim" then "jsbsim" - else if i = (n-2) then "sim" - else sim_type (i+1) in - let sim = sim_type 0 in - let com = paparazzi_home // "var" // ac // sim // "simsitl" in - if not (Sys.file_exists com) then begin - Printf.fprintf stderr "Error: '%s' is missing. Build target sim for A/C %s ?\n" com ac; - exit 1 - end; - let args = Array.sub Sys.argv 0 (n-2) in - args.(0) <- com; - prerr_endline com; - Unix.execv com args - with _ -> - failwith "Usage: launchsitl -a " diff --git a/sw/simulator/Makefile b/sw/simulator/Makefile index 90cf799fc17..d80a46552d8 100644 --- a/sw/simulator/Makefile +++ b/sw/simulator/Makefile @@ -53,7 +53,7 @@ VARINCLUDE=$(PAPARAZZI_HOME)/var/include ACINCLUDE = $(PAPARAZZI_HOME)/var/$(AIRCRAFT) -all : gaia sitl.cma $(LAUNCHSITL) simhitl +all : gaia sitl.cma simhitl simhitl : fg.o $(SIMHCMO) simhitl.cmo @echo OL $@ @@ -90,10 +90,6 @@ diffusion : stdlib.cmo diffusion.cmo @echo OC $< $(Q)$(OCAMLC) $(INCLUDES) -c $< -launchsitl : - cat ../../src/$(@F) | sed s#OCAMLRUN#$(OCAMLRUN)# | sed s#OCAML#$(OCAML)# > $@ - chmod a+x $@ - # dependency on lib-pprz simhitl diffusion gaia: $(LIBPPRZCMA) diff --git a/tests/sim/01_Microjet.t b/tests/sim/01_Microjet.t index 13d04f89c0a..a993920d71d 100644 --- a/tests/sim/01_Microjet.t +++ b/tests/sim/01_Microjet.t @@ -25,12 +25,12 @@ my $server = Proc::Background->new($server_command, @server_options); sleep 2; # The service should die in this time if there's an error ok($server->alive(), "The server process started successfully"); -# Start the launchsitl process -my $launchsitl_command = "$ENV{'PAPARAZZI_HOME'}/sw/simulator/launchsitl"; -my @launchsitl_options = qw(-a Microjet -boot -norc); +# Start the pprzsim-launch process +my $pprzsim_command = "$ENV{'PAPARAZZI_HOME'}/sw/simulator/pprzsim-launch"; +my @pprzsim_options = qw(-a Microjet --boot --norc); sleep 2; # The service should die in this time if there's an error -my $launchsitl = Proc::Background->new($launchsitl_command, @launchsitl_options); -ok($launchsitl->alive(), "The launchsitl process started successfully"); +my $pprzsim = Proc::Background->new($pprzsim_command, @pprzsim_options); +ok($pprzsim->alive(), "The pprzsim-launch process started successfully"); # Open the Ivy bus and read from it... SKIP : { @@ -39,9 +39,9 @@ SKIP : { # TODO: learn how to read and write to the Ivy bus } -# Shutdown the server and launchsitl processes +# Shutdown the server and pprzsim-launch processes ok($server->die(), "The server process shutdown successfully."); -ok($launchsitl->die(), "The launchsitl process shutdown successfully."); +ok($pprzsim->die(), "The pprzsim-launch process shutdown successfully."); ################################################################################ # functions used by this test script. From e4e9d7e2dde80a055facc1b642ba4d598a8235a7 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 24 Jan 2013 13:19:51 +0100 Subject: [PATCH 5/6] [supervision] removed debug print when launching sim --- sw/supervision/pc_control_panel.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/sw/supervision/pc_control_panel.ml b/sw/supervision/pc_control_panel.ml index ca0f464e480..5b5d4cf03d2 100644 --- a/sw/supervision/pc_control_panel.ml +++ b/sw/supervision/pc_control_panel.ml @@ -170,7 +170,6 @@ let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) (target_combo : | _ -> sprintf "-a %s" ac_name in let sim_type = get_simtype target_combo in - prerr_endline sim_type; let args = get_args sim_type ac_name in run_and_monitor ?file gui log "Simulator" args in From d5a843ef9182b6d434fa5450626ae105533a091d Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 24 Jan 2013 13:20:18 +0100 Subject: [PATCH 6/6] [nps] disable buffering for stdout, so it works nicely in paparazzi center --- sw/simulator/nps/nps_main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sw/simulator/nps/nps_main.c b/sw/simulator/nps/nps_main.c index 314a7fd2070..5d2433e8fb2 100644 --- a/sw/simulator/nps/nps_main.c +++ b/sw/simulator/nps/nps_main.c @@ -88,6 +88,13 @@ int main ( int argc, char** argv) { if (!nps_main_parse_options(argc, argv)) return 1; + /* disable buffering for stdout, + * so it properly works in paparazzi center + * where it is not detected as interactive + * and hence fully buffered instead of line buffered + */ + setbuf(stdout, NULL); + nps_main_init(); signal(SIGCONT, cont_hdl);