From fe30ef7f1682c73326d55b9d3ae87fad08c881b8 Mon Sep 17 00:00:00 2001 From: Baardrw <98158027+Baardrw@users.noreply.github.com> Date: Thu, 15 Jan 2026 20:37:35 +0100 Subject: [PATCH] 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 --- .../simulation/gz_bridge/GZMixingInterfaceESC.cpp | 12 ++++++++---- src/modules/simulation/gz_bridge/module.yaml | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/modules/simulation/gz_bridge/GZMixingInterfaceESC.cpp b/src/modules/simulation/gz_bridge/GZMixingInterfaceESC.cpp index 3da5ba0f18..f989434068 100644 --- a/src/modules/simulation/gz_bridge/GZMixingInterfaceESC.cpp +++ b/src/modules/simulation/gz_bridge/GZMixingInterfaceESC.cpp @@ -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(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; } } diff --git a/src/modules/simulation/gz_bridge/module.yaml b/src/modules/simulation/gz_bridge/module.yaml index e6cd8d65b0..cb860db2da 100644 --- a/src/modules/simulation/gz_bridge/module.yaml +++ b/src/modules/simulation/gz_bridge/module.yaml @@ -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