Skip to content

Commit 79a434b

Browse files
committed
Re-implemented ground handling in multirotor step method
1 parent a8597f4 commit 79a434b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

rotorpy/vehicles/multirotor.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,31 @@ def _s_dot_fn(self, t, s, cmd_rotor_speeds):
292292
# Rotate the force from the body frame to the inertial frame
293293
Ftot = R@FtotB
294294

295+
# Ground contact handling
296+
if self._enable_ground and self._on_ground(state):
297+
# Calculate the total force without ground contact
298+
total_force_no_ground = self.weight + Ftot
299+
300+
# If the vehicle is on the ground and the total downward force would cause
301+
# further descent, apply a normal force to counteract it
302+
if total_force_no_ground[2] < 0: # Downward force (negative z)
303+
# Apply normal force to prevent going through ground
304+
ground_normal_force = np.array([0, 0, -total_force_no_ground[2]])
305+
Ftot += ground_normal_force
306+
295307
# Velocity derivative.
296308
v_dot = (self.weight + Ftot) / self.mass
297-
309+
310+
# Additional ground contact constraints
311+
if self._enable_ground and self._on_ground(state):
312+
# Prevent downward velocity when on ground
313+
if v_dot[2] < 0: # Downward acceleration
314+
v_dot[2] = 0.0
315+
# Also damp any existing downward velocity when on ground
316+
if state['v'][2] < 0: # Currently moving downward
317+
v_dot[2] = max(v_dot[2], -10.0 * state['v'][2]) # Damping term
318+
319+
298320
# Angular velocity derivative.
299321
w = state['w']
300322
w_hat = Multirotor.hat_map(w)

0 commit comments

Comments
 (0)