Skip to content

Commit

Permalink
Merge pull request #354 from flixr/sim_chooser
Browse files Browse the repository at this point in the history
Sim chooser in paparazzi center
  • Loading branch information
gautierhattenberger committed Jan 24, 2013
2 parents f8d6328 + d5a843e commit 4f3ad42
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 86 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -138,7 +138,6 @@
# /sw/simulator/
/sw/simulator/gaia
/sw/simulator/simhitl
/sw/simulator/launchsitl

# /sw/supervision/
/sw/supervision/gtk_process.ml
Expand Down
12 changes: 2 additions & 10 deletions Makefile
Expand Up @@ -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)
Expand All @@ -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]*$$//' \;
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile.install
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion conf/control_panel.xml.example
Expand Up @@ -49,7 +49,7 @@
<arg flag="-b" variable="ivy_bus"/>
</program>

<program name="Simulator" command="sw/simulator/launchsitl">
<program name="Simulator" command="sw/simulator/pprzsim-launch">
<arg flag="-b" variable="ivy_bus"/>
</program>

Expand Down
37 changes: 0 additions & 37 deletions src/launchsitl

This file was deleted.

8 changes: 8 additions & 0 deletions sw/lib/ocaml/gtk_tools.ml
Expand Up @@ -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 ->
Expand Down
1 change: 1 addition & 0 deletions sw/lib/ocaml/gtk_tools.mli
Expand Up @@ -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

Expand Down
6 changes: 1 addition & 5 deletions sw/simulator/Makefile
Expand Up @@ -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 $@
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions sw/simulator/nps/nps_main.c
Expand Up @@ -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);
Expand Down
42 changes: 23 additions & 19 deletions sw/simulator/ppzsim-launch → sw/simulator/pprzsim-launch
Expand Up @@ -36,16 +36,16 @@ def main():
usage = "usage: %prog -a <ac_name> -t <sim_type> [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=['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",
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")

Expand All @@ -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)
Expand All @@ -84,7 +88,7 @@ def main():

simargs = []

if options.simtype == "simple_fw":
if options.simtype == "sim":
simdir = "sim"
if options.boot:
simargs.append("-boot")
Expand Down
2 changes: 1 addition & 1 deletion sw/supervision/paparazzicenter.ml
Expand Up @@ -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));
Expand Down
31 changes: 27 additions & 4 deletions sw/supervision/pc_control_panel.ml
Expand Up @@ -141,13 +141,36 @@ let double_quote = fun s ->
else
s

let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) ->
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) (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 args = sprintf "-a %s -boot -norc" ac_name in
let get_args = fun simtype ac_name ->
match simtype with
"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 target_combo in
let args = get_args sim_type ac_name in
run_and_monitor ?file gui log "Simulator" args
in

Expand Down Expand Up @@ -196,9 +219,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 () ->
Expand Down
14 changes: 7 additions & 7 deletions tests/sim/01_Microjet.t
Expand Up @@ -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 : {
Expand All @@ -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.
Expand Down

0 comments on commit 4f3ad42

Please sign in to comment.