From e584a07610d5ef3499f93261390392520551ae31 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 18 Aug 2022 17:22:01 +1000 Subject: [PATCH] HAL_SITL: use motor mask for noise checking for motors --- libraries/AP_HAL_SITL/SITL_State.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/AP_HAL_SITL/SITL_State.cpp b/libraries/AP_HAL_SITL/SITL_State.cpp index e728ab2204..ca03aaf360 100644 --- a/libraries/AP_HAL_SITL/SITL_State.cpp +++ b/libraries/AP_HAL_SITL/SITL_State.cpp @@ -808,8 +808,12 @@ void SITL_State::_simulator_servos(struct sitl_input &input) // do a little quadplane dance float hover_throttle = 0.0f; uint8_t running_motors = 0; - for (uint8_t i=0; i < sitl_model->get_num_motors() - 1; i++) { - float motor_throttle = constrain_float((input.servos[sitl_model->get_motors_offset() + i] - 1000) / 1000.0f, 0.0f, 1.0f); + uint32_t mask = _sitl->state.motor_mask; + uint8_t bit; + while ((bit = __builtin_ffs(mask)) != 0) { + uint8_t motor = bit-1; + mask &= ~(1U<get_num_motors(); i++) { - float motor_throttle = constrain_float((input.servos[i] - 1000) / 1000.0f, 0.0f, 1.0f); + uint32_t mask = _sitl->state.motor_mask; + uint8_t bit; + while ((bit = __builtin_ffs(mask)) != 0) { + const uint8_t motor = bit-1; + mask &= ~(1U<