|
28 | 28 | import collections |
29 | 29 | import logging |
30 | 30 | import struct |
| 31 | +import warnings |
31 | 32 |
|
32 | 33 | from cflib.crtp.crtpstack import CRTPPacket |
33 | 34 | from cflib.crtp.crtpstack import CRTPPort |
@@ -58,8 +59,8 @@ class Localization(): |
58 | 59 | RANGE_STREAM_REPORT = 0 |
59 | 60 | RANGE_STREAM_REPORT_FP16 = 1 |
60 | 61 | 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() |
63 | 64 | COMM_GNSS_NMEA = 6 |
64 | 65 | COMM_GNSS_PROPRIETARY = 7 |
65 | 66 | EXT_POSE = 8 |
@@ -169,25 +170,53 @@ def send_short_lpp_packet(self, dest_id, data): |
169 | 170 |
|
170 | 171 | def send_emergency_stop(self): |
171 | 172 | """ |
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) |
180 | 195 |
|
181 | 196 | def send_emergency_stop_watchdog(self): |
182 | 197 | """ |
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) |
191 | 220 |
|
192 | 221 | def send_lh_persist_data_packet(self, geo_list, calib_list): |
193 | 222 | """ |
|
0 commit comments