GZ: Update GZMixingInterfaceESC to support more than 8 ESCs (#25081)

* Changed GZMixingInterfaceESC to GZMixingInterfaceMotor
- GZMixingInterfaceMotor checks if there are more than 8 motors configured if its less than 8 it behaves exactly the same as GZMixingInterfaceESC, else it behaves as a PWM motor interface
- This change allows drones with more than 8 motors to be simulated by Gazebo

Fixes #25080

* code quality fix

* Changed GZMixingInterfacMotor back to GZMixingInterfaceESC and changed variable names to match ESC terminology

* formatting issue resolved

* updated interface to support 16 ESCs, allowing the first 8 to report telemetry

* rebased
This commit is contained in:
Baardrw
2026-01-15 20:37:35 +01:00
committed by GitHub
parent 0b834dd0e7
commit fe30ef7f16
2 changed files with 9 additions and 5 deletions
@@ -109,16 +109,20 @@ void GZMixingInterfaceESC::motorSpeedCallback(const gz::msgs::Actuators &actuato
pthread_mutex_lock(&_node_mutex);
esc_status_s esc_status{};
// Limit to max supported ESCs while allowing for a larger number of system actuators
esc_status.esc_count = math::min(actuators.velocity_size(), static_cast<int>(esc_status_s::CONNECTED_ESC_MAX));
int limited_escs = math::min(actuators.velocity_size(), (int)esc_status_s::CONNECTED_ESC_MAX);
esc_status.esc_count = limited_escs;
for (int i = 0; i < esc_status.esc_count; i++) {
for (int i = 0; i < limited_escs; i++) {
esc_status.esc[i].timestamp = hrt_absolute_time();
esc_status.esc[i].esc_rpm = actuators.velocity(i);
esc_status.esc_online_flags |= 1 << i;
// This is a race condition with the failure detector, for smaller models it always resolves before
// the failure detector runs, but for larger models (with more than 8 ESCs) the failure detector
// can run before the velocity of some escs is set > 0. To mitigate this, if one esc has a velocity > 0,
// we assume all escs are armed.
if (actuators.velocity(i) > 0) {
esc_status.esc_armed_flags |= 1 << i;
esc_status.esc_armed_flags = (1 << limited_escs) - 1;
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
__max_num_motors: &max_num_motors 12
__max_num_motors: &max_num_motors 16
__max_num_servos: &max_num_servos 8
__max_num_tilts: &max_num_tilts 4