Skip to content

Commit 6e0af91

Browse files
committed
Updated supervisor callback to include the commands
1 parent d03c5ff commit 6e0af91

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

cflib/crazyflie/supervisor.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self, crazyflie):
8787
self._last_fetch_time = 0
8888
self._bitfield = None
8989
self._cf.add_port_callback(CRTPPort.SUPERVISOR, self._supervisor_callback)
90-
self._response_received = False
90+
self._bitfield_response_received = False
9191

9292
def _supervisor_callback(self, pk: CRTPPacket):
9393
"""
@@ -101,9 +101,19 @@ def _supervisor_callback(self, pk: CRTPPacket):
101101
orig_cmd = cmd & 0x7F
102102
if orig_cmd == CMD_GET_STATE_BITFIELD:
103103
self._bitfield = int.from_bytes(pk.data[1:], byteorder='little')
104-
self._response_received = True
104+
self._bitfield_response_received = True
105105
logger.info(f'Supervisor bitfield received: 0x{self._bitfield:04X}')
106106

107+
elif orig_cmd == CMD_ARM_SYSTEM:
108+
success = bool(pk.data[1])
109+
is_armed = bool(pk.data[2])
110+
logger.info(f'Arm response: success={success}, is_armed={is_armed}')
111+
112+
elif orig_cmd == CMD_RECOVER_SYSTEM:
113+
success = bool(pk.data[1])
114+
recovered = bool(pk.data[2])
115+
logger.info(f'Recovery response: success={success}, recovered={recovered}')
116+
107117
def _fetch_bitfield(self, timeout=0.2):
108118
"""
109119
Request the bitfield and wait for response (blocking).
@@ -116,15 +126,15 @@ def _fetch_bitfield(self, timeout=0.2):
116126
return self._bitfield
117127

118128
# Send a new request
119-
self._response_received = False
129+
self._bitfield_response_received = False
120130
pk = CRTPPacket()
121131
pk.set_header(CRTPPort.SUPERVISOR, SUPERVISOR_CH_INFO)
122132
pk.data = [CMD_GET_STATE_BITFIELD]
123133
self._cf.send_packet(pk)
124134

125135
# Wait for response
126136
start_time = now
127-
while not self._response_received:
137+
while not self._bitfield_response_received:
128138
if time.time() - start_time > timeout:
129139
logger.warning('Timeout waiting for supervisor bitfield response')
130140
return self._bitfield or 0 # still return last known value

0 commit comments

Comments
 (0)