From 34509e9b056d169dbe25300acb8b003be3595120 Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Tue, 7 May 2024 00:17:45 +0300 Subject: [PATCH] fix bug with raw command deserialization --- .../modules/PWMModule.cpp | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Src/dronecan_application/modules/PWMModule.cpp b/Src/dronecan_application/modules/PWMModule.cpp index 0bf33d6..3743a90 100644 --- a/Src/dronecan_application/modules/PWMModule.cpp +++ b/Src/dronecan_application/modules/PWMModule.cpp @@ -205,24 +205,15 @@ void PWMModule::publish_actuator_status() { void PWMModule::raw_command_callback(CanardRxTransfer* transfer) { if (module_status != ModuleStatus::MODULE_OK || pwm_cmd_type != 0) return; - RawCommand_t command; - int8_t ch_num = - dronecan_equipment_esc_raw_command_deserialize(transfer, &command); - if (ch_num <= 0) { - return; - } - for (int i = 0; i < static_cast(PwmPin::PWM_AMOUNT); i++) { - auto pwm = ¶ms[i]; - if (pwm->channel < 0) { + + for (auto& pwm : params) { + int16_t cmd; + if (!dronecan_equipment_esc_raw_command_channel_deserialize(transfer, pwm.channel, &cmd)) { continue; } - if (command.raw_cmd[pwm->channel] >= 0) { - pwm->cmd_end_time_ms = HAL_GetTick() + ttl_cmd; - pwm->command_val = mapRawCommandToPwm(command.raw_cmd[pwm->channel], - pwm->min, pwm->max, pwm->def); - } else { - pwm->command_val = pwm->def; - } + + pwm.cmd_end_time_ms = HAL_GetTick() + ttl_cmd; + pwm.command_val = mapRawCommandToPwm(cmd, pwm.min, pwm.max, pwm.def); } }