Skip to content

Commit

Permalink
[simulator] NPS: add --time_factor command line option
Browse files Browse the repository at this point in the history
  • Loading branch information
flixr committed Nov 11, 2014
1 parent 29a59d8 commit b44051c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sw/simulator/nps/nps_main.c
Expand Up @@ -39,7 +39,6 @@
#define SIM_DT (1./SYS_TIME_FREQUENCY)
#define DISPLAY_DT (1./30.)
#define HOST_TIMEOUT_MS 40
#define HOST_TIME_FACTOR 1.

static struct {
double real_initial_time;
Expand Down Expand Up @@ -117,7 +116,6 @@ static void nps_main_init(void) {
gettimeofday (&t, NULL);
nps_main.real_initial_time = time_to_double(&t);
nps_main.scaled_initial_time = time_to_double(&t);
nps_main.host_time_factor = HOST_TIME_FACTOR;

nps_ivy_init(nps_main.ivy_bus);
nps_fdm_init(SIM_DT);
Expand Down Expand Up @@ -257,6 +255,7 @@ static bool_t nps_main_parse_options(int argc, char** argv) {
nps_main.spektrum_dev = NULL;
nps_main.rc_script = 0;
nps_main.ivy_bus = NULL;
nps_main.host_time_factor = 1.0;

static const char* usage =
"Usage: %s [options]\n"
Expand All @@ -268,7 +267,8 @@ static bool_t nps_main_parse_options(int argc, char** argv) {
" -j --js_dev <optional joystick index> e.g. 1 (default 0)\n"
" --spektrum_dev <spektrum device> e.g. /dev/ttyUSB0\n"
" --rc_script <number> e.g. 0\n"
" --ivy_bus <ivy bus> e.g. 127.255.255.255\n";
" --ivy_bus <ivy bus> e.g. 127.255.255.255\n"
" --time_factor <factor> e.g. 2.5\n";


while (1) {
Expand All @@ -281,6 +281,7 @@ static bool_t nps_main_parse_options(int argc, char** argv) {
{"spektrum_dev", 1, NULL, 0},
{"rc_script", 1, NULL, 0},
{"ivy_bus", 1, NULL, 0},
{"time_factor", 1, NULL, 0},
{0, 0, 0, 0}
};
int option_index = 0;
Expand Down Expand Up @@ -308,6 +309,8 @@ static bool_t nps_main_parse_options(int argc, char** argv) {
nps_main.rc_script = atoi(optarg); break;
case 6:
nps_main.ivy_bus = strdup(optarg); break;
case 7:
nps_main.host_time_factor = atof(optarg); break;
}
break;

Expand Down
5 changes: 5 additions & 0 deletions sw/simulator/pprzsim-launch
Expand Up @@ -76,6 +76,8 @@ def main():
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")
nps_opts.add_option("--time_factor", type="float", action="store", metavar="factor",
help="Time factor (default 1.0)")

# special options for the JSBSim sim (without sensor models)
#jsbsim_opts = OptionGroup(parser, "JSBSim options",
Expand Down Expand Up @@ -138,6 +140,9 @@ def main():
if options.ivy_bus:
simargs.append("--ivy_bus")
simargs.append(options.ivy_bus)
if options.time_factor:
simargs.append("--time_factor")
simargs.append(str(options.time_factor))
else:
parser.error("Please specify a valid sim type.")

Expand Down

1 comment on commit b44051c

@OpenUAS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Please sign in to comment.