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

DroneCAN: fix dangerous bug for twin-motor Planes #27610

Merged
merged 3 commits into from
Sep 16, 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
2 changes: 2 additions & 0 deletions ArduPlane/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ void Plane::set_control_channels(void)
// setup correct scaling for ESCs like the UAVCAN ESCs which
// take a proportion of speed. For quadplanes we use AP_Motors
// scaling
g2.servo_channels.set_esc_scaling_for(SRV_Channel::k_throttleLeft);
g2.servo_channels.set_esc_scaling_for(SRV_Channel::k_throttleRight);
g2.servo_channels.set_esc_scaling_for(SRV_Channel::k_throttle);
}
}
Expand Down
13 changes: 8 additions & 5 deletions libraries/AP_DroneCAN/AP_DroneCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,14 +709,17 @@ void AP_DroneCAN::handle_node_info_request(const CanardRxTransfer& transfer, con

int16_t AP_DroneCAN::scale_esc_output(uint8_t idx){
static const int16_t cmd_max = ((1<<13)-1);
float scaled = 0;

float scaled = hal.rcout->scale_esc_to_unity(_SRV_conf[idx].pulse);
// Prevent invalid values (from misconfigured scaling parameters) from sending non-zero commands
if (!isfinite(scaled)) {
return 0;
}
scaled = constrain_float(scaled, -1, 1);
//Check if this channel has a reversible ESC. If it does, we can send negative commands.
if ((((uint32_t) 1) << idx) & _esc_rv) {
scaled = cmd_max * (hal.rcout->scale_esc_to_unity(_SRV_conf[idx].pulse));
scaled *= cmd_max;
} else {
scaled = cmd_max * (hal.rcout->scale_esc_to_unity(_SRV_conf[idx].pulse) + 1.0) / 2.0;
scaled = constrain_float(scaled, 0, cmd_max);
scaled = cmd_max * (scaled + 1.0) / 2.0;
}

return static_cast<int16_t>(scaled);
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_HAL/RCOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,6 @@ class AP_HAL::RCOutput {
void append_to_banner(char banner_msg[], uint8_t banner_msg_len, output_mode out_mode, uint8_t low_ch, uint8_t high_ch) const;
const char* get_output_mode_string(enum output_mode out_mode) const;

uint16_t _esc_pwm_min;
uint16_t _esc_pwm_max;
uint16_t _esc_pwm_min = 1000;
uint16_t _esc_pwm_max = 2000;
};
Loading