diff --git a/sw/simulator/nps/nps_autopilot.h b/sw/simulator/nps/nps_autopilot.h index 04d8304d0b..12b3052c4a 100644 --- a/sw/simulator/nps/nps_autopilot.h +++ b/sw/simulator/nps/nps_autopilot.h @@ -5,8 +5,22 @@ #include "nps_radio_control.h" +/** + * Number of commands sent to the FDM of NPS. + * If MOTOR_MIXING_NB_MOTOR is defined (usually rotorcraft firmware) + * we have that many commands (one per motor), + * otherwise we default to the number of high level commands (COMMANDS_NB). + */ +#ifndef NPS_COMMANDS_NB +#if defined MOTOR_MIXING_NB_MOTOR +#define NPS_COMMANDS_NB MOTOR_MIXING_NB_MOTOR +#else +#define NPS_COMMANDS_NB COMMANDS_NB +#endif +#endif + struct NpsAutopilot { - double commands[COMMANDS_NB]; + double commands[NPS_COMMANDS_NB]; }; extern struct NpsAutopilot autopilot; diff --git a/sw/simulator/nps/nps_autopilot_fixedwing.c b/sw/simulator/nps/nps_autopilot_fixedwing.c index 409a0c3a43..8f1952e0fd 100644 --- a/sw/simulator/nps/nps_autopilot_fixedwing.c +++ b/sw/simulator/nps/nps_autopilot_fixedwing.c @@ -134,7 +134,7 @@ void nps_autopilot_run_step(double time) { Ap(handle_periodic_tasks); /* scale final motor commands to 0-1 for feeding the fdm */ - for (uint8_t i=0; i < COMMANDS_NB; i++) + for (uint8_t i=0; i < NPS_COMMANDS_NB; i++) autopilot.commands[i] = (double)commands[i]/MAX_PPRZ; } diff --git a/sw/simulator/nps/nps_autopilot_rotorcraft.c b/sw/simulator/nps/nps_autopilot_rotorcraft.c index 681d5bf5d8..ce0b529012 100644 --- a/sw/simulator/nps/nps_autopilot_rotorcraft.c +++ b/sw/simulator/nps/nps_autopilot_rotorcraft.c @@ -52,6 +52,9 @@ bool_t nps_bypass_ins; #define NPS_BYPASS_INS FALSE #endif +#if NPS_COMMANDS_NB != MOTOR_MIXING_NB_MOTOR +#error "NPS_COMMANDS_NB does not match MOTOR_MIXING_NB_MOTOR!" +#endif void nps_autopilot_init(enum NpsRadioControlType type_rc, int num_rc_script, char* rc_dev) { @@ -114,8 +117,7 @@ void nps_autopilot_run_step(double time) { handle_periodic_tasks(); /* scale final motor commands to 0-1 for feeding the fdm */ - /* FIXME: autopilot.commands is of length NB_COMMANDS instead of number of motors */ - for (uint8_t i=0; iGetPropertyManager()->SetDouble(property,commands[i]); diff --git a/sw/simulator/nps/nps_main.c b/sw/simulator/nps/nps_main.c index 6686beb324..fd1475b97c 100644 --- a/sw/simulator/nps/nps_main.c +++ b/sw/simulator/nps/nps_main.c @@ -158,7 +158,7 @@ static void nps_main_run_sim_step(void) { nps_autopilot_run_systime_step(); - nps_fdm_run_step(autopilot.commands); + nps_fdm_run_step(autopilot.commands, NPS_COMMANDS_NB); nps_sensors_run_step(nps_main.sim_time);