Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rawcommand bug #28

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions Src/dronecan_application/modules/PWMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ PWMModule::PWMModule() {
init();
}

PwmChannelInfo PWMModule::params[static_cast<uint8_t>(PwmPin::PWM_AMOUNT)] = {
std::array<PwmChannelInfo, static_cast<uint8_t>(PwmPin::PWM_AMOUNT)> PWMModule::params = {{
{.pin = PwmPin::PWM_1}, // PWM1
{.pin = PwmPin::PWM_2}, // PWM2
{.pin = PwmPin::PWM_3}, // PWM3
{.pin = PwmPin::PWM_4}, // PWM4
};
}};

PwmChannelsParamsNames
PWMModule::params_names[static_cast<uint8_t>(PwmPin::PWM_AMOUNT)] = {
Expand Down Expand Up @@ -204,25 +204,18 @@ 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) {
if (module_status != ModuleStatus::MODULE_OK || pwm_cmd_type != 0) {
return;
}
for (int i = 0; i < static_cast<uint8_t>(PwmPin::PWM_AMOUNT); i++) {
auto pwm = &params[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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Src/dronecan_application/modules/PWMModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PWMModule {
public:
void spin_once();
static PWMModule &get_instance();
static PwmChannelInfo params[static_cast<uint8_t>(PwmPin::PWM_AMOUNT)];
static std::array<PwmChannelInfo, static_cast<uint8_t>(PwmPin::PWM_AMOUNT)> params;
static PwmChannelsParamsNames params_names[static_cast<uint8_t>(PwmPin::PWM_AMOUNT)];
static ModuleStatus module_status;

Expand Down
Loading