Skip to content

Commit c4334b5

Browse files
BaardrwLuka Dragar
authored andcommitted
GZ: Update GZMixingInterfaceESC to support more than 8 ESCs (PX4#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 PX4#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
1 parent bbf293f commit c4334b5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/modules/simulation/gz_bridge/GZMixingInterfaceESC.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,20 @@ void GZMixingInterfaceESC::motorSpeedCallback(const gz::msgs::Actuators &actuato
109109
pthread_mutex_lock(&_node_mutex);
110110

111111
esc_status_s esc_status{};
112-
// Limit to max supported ESCs while allowing for a larger number of system actuators
113-
esc_status.esc_count = math::min(actuators.velocity_size(), static_cast<int>(esc_status_s::CONNECTED_ESC_MAX));
112+
int limited_escs = math::min(actuators.velocity_size(), (int)esc_status_s::CONNECTED_ESC_MAX);
113+
esc_status.esc_count = limited_escs;
114114

115-
for (int i = 0; i < esc_status.esc_count; i++) {
115+
for (int i = 0; i < limited_escs; i++) {
116116
esc_status.esc[i].timestamp = hrt_absolute_time();
117117
esc_status.esc[i].esc_rpm = actuators.velocity(i);
118118
esc_status.esc_online_flags |= 1 << i;
119119

120+
// This is a race condition with the failure detector, for smaller models it always resolves before
121+
// the failure detector runs, but for larger models (with more than 8 ESCs) the failure detector
122+
// can run before the velocity of some escs is set > 0. To mitigate this, if one esc has a velocity > 0,
123+
// we assume all escs are armed.
120124
if (actuators.velocity(i) > 0) {
121-
esc_status.esc_armed_flags |= 1 << i;
125+
esc_status.esc_armed_flags = (1 << limited_escs) - 1;
122126
}
123127
}
124128

src/modules/simulation/gz_bridge/module.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__max_num_motors: &max_num_motors 12
1+
__max_num_motors: &max_num_motors 16
22
__max_num_servos: &max_num_servos 8
33
__max_num_tilts: &max_num_tilts 4
44

0 commit comments

Comments
 (0)