commit 597f5bc8e8ddd03c8779c7ce95e2fc06c2703aa3 Author: Andreas Gaeb Date: Fri Jul 23 16:08:06 2010 +0200 allow JSBSim to run multiple times per control loop execution diff --git a/sw/simulator/sim_ac_jsbsim.c b/sw/simulator/sim_ac_jsbsim.c index d7591e1..82e6282 100644 --- a/sw/simulator/sim_ac_jsbsim.c +++ b/sw/simulator/sim_ac_jsbsim.c @@ -69,6 +69,7 @@ static void sim_init(void) { } static gboolean sim_periodic(gpointer data __attribute__ ((unused))) { + static uint8_t ncalls = 0; /* read actuators positions and feed JSBSim inputs */ copy_inputs_to_jsbsim(FDMExec); @@ -84,11 +85,15 @@ static gboolean sim_periodic(gpointer data __attribute__ ((unused))) { /* read outputs from model state (and display ?) */ copy_outputs_from_jsbsim(FDMExec); - /* run the airborne code */ - + /* run the airborne code + with 60 Hz, even if JSBSim runs with a multiple of this */ + if (ncalls == 0) { // airborne_run_one_step(); autopilot_event_task(); autopilot_periodic_task(); + } + ++ncalls; + if (ncalls == JSBSIM_SPEEDUP) ncalls = 0; return result; } diff --git a/sw/simulator/sim_ac_jsbsim.h b/sw/simulator/sim_ac_jsbsim.h index e5c72a2..8984e4c 100644 --- a/sw/simulator/sim_ac_jsbsim.h +++ b/sw/simulator/sim_ac_jsbsim.h @@ -38,11 +38,13 @@ #include -/* 60Hz <-> 17ms */ #ifndef JSBSIM_PERIOD -#define JSBSIM_PERIOD 17 +#define JSBSIM_SPEEDUP 4 ///< how many JSBSim calls per A/P control loop call? +#define JSBSIM_PERIOD (1000.0/CONTROL_RATE/JSBSIM_SPEEDUP) ///< JSBSim timestep in milliseconds +#else +#define JSBSIM_SPEEDUP ((uint8_t) (1000./CONTROL_RATE/JSBSIM_PERIOD)) #endif -#define DT (JSBSIM_PERIOD*1e-3) +#define DT (JSBSIM_PERIOD*1e-3) ///< JSBSim timestep in seconds #define RAD2DEG 57.29578 #define FT2M 0.3048