|
|
@ -81,6 +81,14 @@ const unsigned mode_flag_custom = 1; |
|
|
|
|
|
|
|
|
|
|
|
using namespace time_literals; |
|
|
|
using namespace time_literals; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Simulator::Simulator() |
|
|
|
|
|
|
|
: ModuleParams(nullptr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int32_t sys_ctrl_alloc = 0; |
|
|
|
|
|
|
|
param_get(param_find("SYS_CTRL_ALLOC"), &sys_ctrl_alloc); |
|
|
|
|
|
|
|
_use_dynamic_mixing = sys_ctrl_alloc >= 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Simulator::actuator_controls_from_outputs(mavlink_hil_actuator_controls_t *msg) |
|
|
|
void Simulator::actuator_controls_from_outputs(mavlink_hil_actuator_controls_t *msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
memset(msg, 0, sizeof(mavlink_hil_actuator_controls_t)); |
|
|
|
memset(msg, 0, sizeof(mavlink_hil_actuator_controls_t)); |
|
|
@ -91,6 +99,14 @@ void Simulator::actuator_controls_from_outputs(mavlink_hil_actuator_controls_t * |
|
|
|
|
|
|
|
|
|
|
|
int _system_type = _param_mav_type.get(); |
|
|
|
int _system_type = _param_mav_type.get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_use_dynamic_mixing) { |
|
|
|
|
|
|
|
if (armed) { |
|
|
|
|
|
|
|
for (unsigned i = 0; i < actuator_outputs_s::NUM_ACTUATOR_OUTPUTS; i++) { |
|
|
|
|
|
|
|
msg->controls[i] = _actuator_outputs.output[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
/* 'pos_thrust_motors_count' indicates number of motor channels which are configured with 0..1 range (positive thrust)
|
|
|
|
/* 'pos_thrust_motors_count' indicates number of motor channels which are configured with 0..1 range (positive thrust)
|
|
|
|
all other motors are configured for -1..1 range */ |
|
|
|
all other motors are configured for -1..1 range */ |
|
|
|
unsigned pos_thrust_motors_count; |
|
|
|
unsigned pos_thrust_motors_count; |
|
|
@ -172,7 +188,7 @@ void Simulator::actuator_controls_from_outputs(mavlink_hil_actuator_controls_t * |
|
|
|
msg->controls[i] = (_actuator_outputs.output[i] - pwm_center) / pwm_delta; |
|
|
|
msg->controls[i] = (_actuator_outputs.output[i] - pwm_center) / pwm_delta; |
|
|
|
msg->controls[i] = math::constrain(msg->controls[i], -1.f, 1.f); |
|
|
|
msg->controls[i] = math::constrain(msg->controls[i], -1.f, 1.f); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
msg->mode = mode_flag_custom; |
|
|
|
msg->mode = mode_flag_custom; |
|
|
@ -694,7 +710,12 @@ void Simulator::send() |
|
|
|
|
|
|
|
|
|
|
|
// Subscribe to topics.
|
|
|
|
// Subscribe to topics.
|
|
|
|
// Only subscribe to the first actuator_outputs to fill a single HIL_ACTUATOR_CONTROLS.
|
|
|
|
// Only subscribe to the first actuator_outputs to fill a single HIL_ACTUATOR_CONTROLS.
|
|
|
|
|
|
|
|
if (_use_dynamic_mixing) { |
|
|
|
|
|
|
|
_actuator_outputs_sub = orb_subscribe_multi(ORB_ID(actuator_outputs_sim), 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
_actuator_outputs_sub = orb_subscribe_multi(ORB_ID(actuator_outputs), 0); |
|
|
|
_actuator_outputs_sub = orb_subscribe_multi(ORB_ID(actuator_outputs), 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Before starting, we ought to send a heartbeat to initiate the SITL
|
|
|
|
// Before starting, we ought to send a heartbeat to initiate the SITL
|
|
|
|
// simulator to start sending sensor data which will set the time and
|
|
|
|
// simulator to start sending sensor data which will set the time and
|
|
|
|