From 01e4fd3b6b2fe162e1d2d5b0deb9a647063c8136 Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Wed, 19 Mar 2025 16:15:34 +0100 Subject: [PATCH 1/2] Send continuous zero setpoints until landing in ramp examples In ramp examples where motors are gradually ramped, the supervisor assumes the drone is flying and requires continuous updated setpoints. Previously, a single zero setpoint was sent before sleeping, which leads to supervisor intervention due to missing regular setpoints. Now, zero setpoints are continuously sent for 3 seconds, and the drone is considered landed, preventing locking. Currently, this does not directly check with the supervisor if the drone has landed. Investigating a way to do this revealed that it is not straightforward. In the client, we check the supervisor states through a bitfield check, but there is no direct and easy way to access this information from the library. I will open a new issue to propose adding supervisor state reading functionality to the library, making it easier to access this information directly. --- examples/motors/multiramp.py | 9 +++++---- examples/motors/ramp.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/motors/multiramp.py b/examples/motors/multiramp.py index df77fec51..3adfc8cdf 100644 --- a/examples/motors/multiramp.py +++ b/examples/motors/multiramp.py @@ -101,10 +101,11 @@ def _ramp_motors(self): if thrust >= 25000: thrust_mult = -1 thrust += thrust_step * thrust_mult - self._cf.commander.send_setpoint(0, 0, 0, 0) - # Make sure that the last packet leaves before the link is closed - # since the message queue is not flushed before closing - time.sleep(0.1) + for _ in range(30): + # Continuously send the zero setpoint until the drone is recognized as landed + # to prevent the supervisor from intervening due to missing regular setpoints + self._cf.commander.send_setpoint(0, 0, 0, 0) + time.sleep(0.1) self._cf.close_link() diff --git a/examples/motors/ramp.py b/examples/motors/ramp.py index a91d87bac..c95f5cdea 100644 --- a/examples/motors/ramp.py +++ b/examples/motors/ramp.py @@ -99,10 +99,11 @@ def _ramp_motors(self): if thrust >= 25000: thrust_mult = -1 thrust += thrust_step * thrust_mult - self._cf.commander.send_setpoint(0, 0, 0, 0) - # Make sure that the last packet leaves before the link is closed - # since the message queue is not flushed before closing - time.sleep(1) + for _ in range(30): + # Continuously send the zero setpoint until the drone is recognized as landed + # to prevent the supervisor from intervening due to missing regular setpoints + self._cf.commander.send_setpoint(0, 0, 0, 0) + time.sleep(0.1) self._cf.close_link() From 5fb3f592d2754dcb51e227dec66d69c483d8f8c8 Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Wed, 19 Mar 2025 16:35:16 +0100 Subject: [PATCH 2/2] Restore comment about sleeping before closing the link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-added a slightly modified comment explaining that sleeping before closing the link ensures the last packet is sent, as the message queue is not flushed before closing. While it’s somewhat arbitrary that this information is only found in this example, it’s still valuable to have it documented somewhere. In practice, we don’t care as much about this delay anymore since the new method’s delay is more focused on the setpoint sending loop rather than guaranteeing message delivery, but the comment is still worth keeping. --- examples/motors/multiramp.py | 3 +++ examples/motors/ramp.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/examples/motors/multiramp.py b/examples/motors/multiramp.py index 3adfc8cdf..8c3e9340f 100644 --- a/examples/motors/multiramp.py +++ b/examples/motors/multiramp.py @@ -106,6 +106,9 @@ def _ramp_motors(self): # to prevent the supervisor from intervening due to missing regular setpoints self._cf.commander.send_setpoint(0, 0, 0, 0) time.sleep(0.1) + # Sleeping before closing the link makes sure the last + # packet leaves before the link is closed, since the + # message queue is not flushed before closing self._cf.close_link() diff --git a/examples/motors/ramp.py b/examples/motors/ramp.py index c95f5cdea..b0f78831f 100644 --- a/examples/motors/ramp.py +++ b/examples/motors/ramp.py @@ -104,6 +104,9 @@ def _ramp_motors(self): # to prevent the supervisor from intervening due to missing regular setpoints self._cf.commander.send_setpoint(0, 0, 0, 0) time.sleep(0.1) + # Sleeping before closing the link makes sure the last + # packet leaves before the link is closed, since the + # message queue is not flushed before closing self._cf.close_link()