Skip to content

Commit 1532485

Browse files
authored
Merge pull request #581 from bitcraze/Aris/crtp_supervisor_lib
Supervisor subsystem
2 parents 6f5f8d4 + 7d7441d commit 1532485

11 files changed

Lines changed: 387 additions & 41 deletions

File tree

cflib/crazyflie/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from .mem import Memory
5252
from .param import Param
5353
from .platformservice import PlatformService
54+
from .supervisor import Supervisor
5455
from .toccache import TocCache
5556
from cflib.crazyflie.high_level_commander import HighLevelCommander
5657
from cflib.utils.callbacks import Caller
@@ -124,6 +125,7 @@ def __init__(self, link=None, ro_cache=None, rw_cache=None):
124125
self.platform = PlatformService(self)
125126
self.appchannel = Appchannel(self)
126127
self.link_statistics = LinkStatistics(self)
128+
self.supervisor = Supervisor(self)
127129

128130
self.link_uri = ''
129131

cflib/crazyflie/localization.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import collections
2929
import logging
3030
import struct
31+
import warnings
3132

3233
from cflib.crtp.crtpstack import CRTPPacket
3334
from cflib.crtp.crtpstack import CRTPPort
@@ -58,8 +59,8 @@ class Localization():
5859
RANGE_STREAM_REPORT = 0
5960
RANGE_STREAM_REPORT_FP16 = 1
6061
LPS_SHORT_LPP_PACKET = 2
61-
EMERGENCY_STOP = 3
62-
EMERGENCY_STOP_WATCHDOG = 4
62+
EMERGENCY_STOP = 3 # Deprecated: use supervisor.send_emergency_stop()
63+
EMERGENCY_STOP_WATCHDOG = 4 # Deprecated: use supervisor.send_emergency_stop_watchdog()
6364
COMM_GNSS_NMEA = 6
6465
COMM_GNSS_PROPRIETARY = 7
6566
EXT_POSE = 8
@@ -169,25 +170,53 @@ def send_short_lpp_packet(self, dest_id, data):
169170

170171
def send_emergency_stop(self):
171172
"""
172-
Send emergency stop
173-
"""
174-
175-
pk = CRTPPacket()
176-
pk.port = CRTPPort.LOCALIZATION
177-
pk.channel = self.GENERIC_CH
178-
pk.data = struct.pack('<B', self.EMERGENCY_STOP)
179-
self._cf.send_packet(pk)
173+
Send emergency stop (deprecated).
174+
175+
Deprecated:
176+
Use ``cf.supervisor.send_emergency_stop()`` instead.
177+
If the connected Crazyflie does not support CRTP protocol version 12
178+
or later, the legacy localization channel is used as a fallback.
179+
"""
180+
warnings.warn(
181+
'localization.send_emergency_stop() is deprecated. '
182+
'Use cf.supervisor.send_emergency_stop() instead. '
183+
'Update your Crazyflie firmware to use CRTP protocol version 12 or later.',
184+
DeprecationWarning,
185+
stacklevel=2,
186+
)
187+
if self._cf.platform.get_protocol_version() >= 12:
188+
self._cf.supervisor.send_emergency_stop()
189+
else:
190+
pk = CRTPPacket()
191+
pk.port = CRTPPort.LOCALIZATION
192+
pk.channel = self.GENERIC_CH
193+
pk.data = struct.pack('<B', self.EMERGENCY_STOP)
194+
self._cf.send_packet(pk)
180195

181196
def send_emergency_stop_watchdog(self):
182197
"""
183-
Send emergency stop watchdog
184-
"""
185-
186-
pk = CRTPPacket()
187-
pk.port = CRTPPort.LOCALIZATION
188-
pk.channel = self.GENERIC_CH
189-
pk.data = struct.pack('<B', self.EMERGENCY_STOP_WATCHDOG)
190-
self._cf.send_packet(pk)
198+
Send emergency stop watchdog (deprecated).
199+
200+
Deprecated:
201+
Use ``cf.supervisor.send_emergency_stop_watchdog()`` instead.
202+
If the connected Crazyflie does not support CRTP protocol version 12
203+
or later, the legacy localization channel is used as a fallback.
204+
"""
205+
warnings.warn(
206+
'localization.send_emergency_stop_watchdog() is deprecated. '
207+
'Use cf.supervisor.send_emergency_stop_watchdog() instead. '
208+
'Update your Crazyflie firmware to use CRTP protocol version 12 or later.',
209+
DeprecationWarning,
210+
stacklevel=2,
211+
)
212+
if self._cf.platform.get_protocol_version() >= 12:
213+
self._cf.supervisor.send_emergency_stop_watchdog()
214+
else:
215+
pk = CRTPPacket()
216+
pk.port = CRTPPort.LOCALIZATION
217+
pk.channel = self.GENERIC_CH
218+
pk.data = struct.pack('<B', self.EMERGENCY_STOP_WATCHDOG)
219+
self._cf.send_packet(pk)
191220

192221
def send_lh_persist_data_packet(self, geo_list, calib_list):
193222
"""

cflib/crazyflie/platformservice.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Used for sending control setpoints to the Crazyflie
2727
"""
2828
import logging
29+
import warnings
2930

3031
from cflib.crtp.crtpstack import CRTPPacket
3132
from cflib.crtp.crtpstack import CRTPPort
@@ -40,8 +41,6 @@
4041
APP_CHANNEL = 2
4142

4243
PLATFORM_SET_CONT_WAVE = 0
43-
PLATFORM_REQUEST_ARMING = 1
44-
PLATFORM_REQUEST_CRASH_RECOVERY = 2
4544

4645
VERSION_GET_PROTOCOL = 0
4746
VERSION_GET_FIRMWARE = 1
@@ -90,25 +89,38 @@ def set_continous_wave(self, enabled):
9089

9190
def send_arming_request(self, do_arm: bool):
9291
"""
93-
Send system arm/disarm request
92+
Send system arm/disarm request (deprecated).
9493
9594
Args:
9695
do_arm (bool): True = arm the system, False = disarm the system
96+
97+
Deprecated:
98+
Use `supervisor.send_arming_request(do_arm)` instead.
9799
"""
98-
pk = CRTPPacket()
99-
pk.set_header(CRTPPort.PLATFORM, PLATFORM_COMMAND)
100-
pk.data = (PLATFORM_REQUEST_ARMING, do_arm)
101-
self._cf.send_packet(pk)
100+
warnings.warn(
101+
'platform.send_arming_request is deprecated. '
102+
'Use supervisor.send_arming_request(do_arm) instead.',
103+
category=DeprecationWarning,
104+
stacklevel=2
105+
)
106+
107+
self._cf.supervisor.send_arming_request(do_arm)
102108

103109
def send_crash_recovery_request(self):
104110
"""
105-
Send crash recovery request
111+
Send crash recovery request (deprecated).
106112
113+
Deprecated:
114+
Use `supervisor.send_crash_recovery_request()` instead.
107115
"""
108-
pk = CRTPPacket()
109-
pk.set_header(CRTPPort.PLATFORM, PLATFORM_COMMAND)
110-
pk.data = (PLATFORM_REQUEST_CRASH_RECOVERY, )
111-
self._cf.send_packet(pk)
116+
warnings.warn(
117+
'platform.send_crash_recovery_request is deprecated. '
118+
'Use supervisor.send_crash_recovery_request() instead.',
119+
category=DeprecationWarning,
120+
stacklevel=2
121+
)
122+
123+
self._cf.supervisor.send_crash_recovery_request()
112124

113125
def get_protocol_version(self):
114126
"""

0 commit comments

Comments
 (0)