mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 06:13:35 +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
@@ -183,11 +183,11 @@ void VertiqIo::parameters_update()
|
||||
}
|
||||
}
|
||||
|
||||
void VertiqIo::OutputControls(uint16_t outputs[MAX_ACTUATORS])
|
||||
void VertiqIo::OutputControls(float outputs[MAX_ACTUATORS])
|
||||
{
|
||||
//Put the mixer outputs into the output message
|
||||
for (uint8_t i = 0; i < _transmission_message.num_cvs; i++) {
|
||||
_transmission_message.commands[i] = outputs[i];
|
||||
_transmission_message.commands[i] = static_cast<uint16_t>(lroundf(outputs[i]));
|
||||
}
|
||||
|
||||
_operational_ifci.PackageIfciCommandsForTransmission(&_transmission_message, _output_message, &_output_len);
|
||||
@@ -195,8 +195,7 @@ void VertiqIo::OutputControls(uint16_t outputs[MAX_ACTUATORS])
|
||||
_serial_interface.ProcessSerialTx();
|
||||
}
|
||||
|
||||
bool VertiqIo::updateOutputs(uint16_t outputs[MAX_ACTUATORS], unsigned num_outputs,
|
||||
unsigned num_control_groups_updated)
|
||||
bool VertiqIo::updateOutputs(float outputs[MAX_ACTUATORS], unsigned num_outputs, unsigned num_control_groups_updated)
|
||||
{
|
||||
#ifdef CONFIG_USE_IFCI_CONFIGURATION
|
||||
|
||||
|
||||
@@ -94,14 +94,13 @@ public:
|
||||
void print_info();
|
||||
|
||||
/** @see OutputModuleInterface */
|
||||
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;
|
||||
|
||||
/**
|
||||
* @brief Used to package and transmit controls via IQUART
|
||||
* @param outputs The output throttles calculated by the mixer
|
||||
*/
|
||||
void OutputControls(uint16_t outputs[MAX_ACTUATORS]);
|
||||
void OutputControls(float outputs[MAX_ACTUATORS]);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -1237,8 +1237,7 @@ void VoxlEsc::mix_turtle_mode(uint16_t outputs[MAX_ACTUATORS])
|
||||
}
|
||||
|
||||
/* OutputModuleInterface */
|
||||
bool VoxlEsc::updateOutputs(uint16_t outputs[MAX_ACTUATORS],
|
||||
unsigned num_outputs, unsigned num_control_groups_updated)
|
||||
bool VoxlEsc::updateOutputs(float outputs[MAX_ACTUATORS], unsigned num_outputs, unsigned num_control_groups_updated)
|
||||
{
|
||||
//in Run() we call _mixing_output.update(), which calls MixingOutput::limitAndUpdateOutputs which calls _interface.updateOutputs (this function)
|
||||
//So, if Run() is blocked by a custom command, this function will not be called until Run is running again
|
||||
@@ -1247,9 +1246,16 @@ bool VoxlEsc::updateOutputs(uint16_t outputs[MAX_ACTUATORS],
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert float outputs to uint16_t hardware values
|
||||
uint16_t hw_outputs[VOXL_ESC_OUTPUT_CHANNELS] {};
|
||||
|
||||
for (int i = 0; i < VOXL_ESC_OUTPUT_CHANNELS; i++) {
|
||||
hw_outputs[i] = static_cast<uint16_t>(lroundf(outputs[i]));
|
||||
}
|
||||
|
||||
// don't use mixed values... recompute now.
|
||||
if (_turtle_mode_en) {
|
||||
mix_turtle_mode(outputs);
|
||||
mix_turtle_mode(hw_outputs);
|
||||
}
|
||||
|
||||
for (int i = 0; i < VOXL_ESC_OUTPUT_CHANNELS; i++) {
|
||||
@@ -1259,24 +1265,24 @@ bool VoxlEsc::updateOutputs(uint16_t outputs[MAX_ACTUATORS],
|
||||
} else {
|
||||
if ((_turtle_mode_en) || (_parameters.cmd_type == VOXL_ESC_RPM_CMDS)) {
|
||||
if (_extended_rpm) {
|
||||
if (outputs[i] > VOXL_ESC_RPM_MAX_EXT) { outputs[i] = VOXL_ESC_RPM_MAX_EXT; }
|
||||
if (hw_outputs[i] > VOXL_ESC_RPM_MAX_EXT) { hw_outputs[i] = VOXL_ESC_RPM_MAX_EXT; }
|
||||
|
||||
} else {
|
||||
if (outputs[i] > VOXL_ESC_RPM_MAX) { outputs[i] = VOXL_ESC_RPM_MAX; }
|
||||
if (hw_outputs[i] > VOXL_ESC_RPM_MAX) { hw_outputs[i] = VOXL_ESC_RPM_MAX; }
|
||||
}
|
||||
|
||||
} else if (_parameters.cmd_type == VOXL_ESC_PWM_CMDS) {
|
||||
if (outputs[i] > VOXL_ESC_PWM_MAX) { outputs[i] = VOXL_ESC_PWM_MAX; }
|
||||
if (hw_outputs[i] > VOXL_ESC_PWM_MAX) { hw_outputs[i] = VOXL_ESC_PWM_MAX; }
|
||||
|
||||
else if (outputs[i] < _min_active_pwm) { outputs[i] = _min_active_pwm; }
|
||||
else if (hw_outputs[i] < _min_active_pwm) { hw_outputs[i] = _min_active_pwm; }
|
||||
}
|
||||
|
||||
if (!_turtle_mode_en) {
|
||||
_esc_chans[i].rate_req = outputs[i] * _output_map[i].direction;
|
||||
_esc_chans[i].rate_req = hw_outputs[i] * _output_map[i].direction;
|
||||
|
||||
} else {
|
||||
// mapping updated in mixTurtleMode, no remap needed here, but reverse direction
|
||||
_esc_chans[i].rate_req = outputs[i] * _output_map[i].direction * (-1);
|
||||
_esc_chans[i].rate_req = hw_outputs[i] * _output_map[i].direction * (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +83,7 @@ public:
|
||||
void print_params();
|
||||
|
||||
/** @see OutputModuleInterface */
|
||||
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;
|
||||
|
||||
virtual int init();
|
||||
int device_init(); // function where uart port is opened and ESC queried
|
||||
|
||||
Reference in New Issue
Block a user