mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 20:23:33 +08:00
fix(mixer_module): change MixingOutput to use float outputs (#26724)
* refactor(mixer_module): change MixingOutput to use float outputs MixingOutput now passes float values to output drivers instead of uint16_t. This removes the need for the 8192 offset encoding and allows reversible motors to receive negative values directly. * fix(mixer_module): fix float safety issues -EscClient and voxl2_io: replace outputs[i] with fabs(outputs[i]) > 0.fto fix compilation issues -GZMixingInterface: add explicit double cast to prevent compilation error -PWMSim: replaced unit16 cast with lroundf given that now motors outputs can be negative and casting a negative float to unit16 is undefinder behaviour -mixer_module: same fix of PWM (unit126 cast on negative float is undefined behaviour) * refactor(mixer_module): float rounding suggestions * fix(pwm_sim): fix inverted disarmed condition * fix(mixer_module): more float rounding improvements * fix(mixer_module_tests): use casting method which are now in drivers for rounding tests --------- Co-authored-by: Matthias Grob <maetugr@gmail.com>
This commit is contained in:
co-authored by
Matthias Grob
parent
26c9ca115f
commit
00b27c56a8
@@ -243,7 +243,7 @@ void TAP_ESC::send_tune_packet(EscbusTunePacket &tune_packet)
|
||||
tap_esc_common::send_packet(_uart_fd, buzzer_packet, -1);
|
||||
}
|
||||
|
||||
bool TAP_ESC::updateOutputs(uint16_t outputs[MAX_ACTUATORS], unsigned num_outputs,
|
||||
bool TAP_ESC::updateOutputs(float outputs[MAX_ACTUATORS], unsigned num_outputs,
|
||||
unsigned num_control_groups_updated)
|
||||
{
|
||||
if (_initialized) {
|
||||
@@ -252,26 +252,26 @@ bool TAP_ESC::updateOutputs(uint16_t outputs[MAX_ACTUATORS], unsigned num_output
|
||||
// We need to remap from the system default to what PX4's normal scheme is
|
||||
switch (num_outputs) {
|
||||
case 4:
|
||||
motor_out[0] = outputs[2];
|
||||
motor_out[1] = outputs[1];
|
||||
motor_out[2] = outputs[3];
|
||||
motor_out[3] = outputs[0];
|
||||
motor_out[0] = static_cast<uint16_t>(lroundf(outputs[2]));
|
||||
motor_out[1] = static_cast<uint16_t>(lroundf(outputs[1]));
|
||||
motor_out[2] = static_cast<uint16_t>(lroundf(outputs[3]));
|
||||
motor_out[3] = static_cast<uint16_t>(lroundf(outputs[0]));
|
||||
break;
|
||||
|
||||
case 6:
|
||||
motor_out[0] = outputs[3];
|
||||
motor_out[1] = outputs[0];
|
||||
motor_out[2] = outputs[4];
|
||||
motor_out[3] = outputs[2];
|
||||
motor_out[4] = outputs[1];
|
||||
motor_out[5] = outputs[5];
|
||||
motor_out[0] = static_cast<uint16_t>(lroundf(outputs[3]));
|
||||
motor_out[1] = static_cast<uint16_t>(lroundf(outputs[0]));
|
||||
motor_out[2] = static_cast<uint16_t>(lroundf(outputs[4]));
|
||||
motor_out[3] = static_cast<uint16_t>(lroundf(outputs[2]));
|
||||
motor_out[4] = static_cast<uint16_t>(lroundf(outputs[1]));
|
||||
motor_out[5] = static_cast<uint16_t>(lroundf(outputs[5]));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
// Use the system defaults
|
||||
for (uint8_t i = 0; i < num_outputs; ++i) {
|
||||
motor_out[i] = outputs[i];
|
||||
motor_out[i] = static_cast<uint16_t>(lroundf(outputs[i]));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -101,8 +101,7 @@ public:
|
||||
|
||||
int init();
|
||||
|
||||
bool updateOutputs(uint16_t outputs[MAX_ACTUATORS],
|
||||
unsigned num_outputs, unsigned num_control_groups_updated) override;
|
||||
bool updateOutputs(float outputs[MAX_ACTUATORS], unsigned num_outputs, unsigned num_control_groups_updated) override;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user