Skip to content

Commit 9fc8563

Browse files
authored
Merge pull request #16 from bitcraze/rik/supervisor
Supervisor subsystem
2 parents b1c7afe + 33fede6 commit 9fc8563

24 files changed

Lines changed: 500 additions & 174 deletions

cflib2/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

cflib2/_rust.pyi

Lines changed: 143 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ class Crazyflie:
411411
r"""
412412
Get the platform subsystem
413413
"""
414+
def supervisor(self) -> Supervisor:
415+
r"""
416+
Get the supervisor subsystem
417+
"""
414418
def __str__(self) -> builtins.str: ...
415419
def __repr__(self) -> builtins.str: ...
416420

@@ -428,30 +432,6 @@ class DisconnectedError(CrazyflieError):
428432

429433
...
430434

431-
@typing.final
432-
class EmergencyControl:
433-
r"""
434-
Emergency control interface
435-
436-
Provides emergency stop functionality that immediately stops all motors.
437-
"""
438-
async def send_emergency_stop(self) -> None:
439-
r"""
440-
Send emergency stop command
441-
442-
Immediately stops all motors and puts the Crazyflie into a locked state.
443-
The drone will require a reboot before it can fly again.
444-
"""
445-
async def send_emergency_stop_watchdog(self) -> None:
446-
r"""
447-
Send emergency stop watchdog
448-
449-
Activates/resets a watchdog failsafe that will automatically emergency stop
450-
the drone if this message isn't sent every 1000ms. Once activated by the first
451-
call, you must continue sending this periodically forever or the drone will
452-
automatically emergency stop. Use only if you need automatic failsafe behavior.
453-
"""
454-
455435
@typing.final
456436
class ExternalPose:
457437
r"""
@@ -797,10 +777,7 @@ class LedRingColor:
797777
Intensity percentage (0-100); values above 100 are clamped to 100
798778
"""
799779
@intensity.setter
800-
def intensity(self, value: builtins.int) -> None:
801-
r"""
802-
Intensity percentage (0-100); values above 100 are clamped to 100
803-
"""
780+
def intensity(self, value: builtins.int) -> None: ...
804781
def __new__(
805782
cls,
806783
r: builtins.int = 0,
@@ -815,7 +792,7 @@ class LedRingColor:
815792
* `r` - Red component (0-255, default 0)
816793
* `g` - Green component (0-255, default 0)
817794
* `b` - Blue component (0-255, default 0)
818-
* `intensity` - Intensity percentage (0-100, default 100); clamped to 100 if higher
795+
* `intensity` - Intensity percentage (0-100, default 100); values above 100 are clamped to 100
819796
"""
820797
def set(
821798
self,
@@ -970,10 +947,6 @@ class Localization:
970947
r"""
971948
Localization subsystem wrapper
972949
"""
973-
def emergency(self) -> EmergencyControl:
974-
r"""
975-
Get the emergency control interface
976-
"""
977950
def external_pose(self) -> ExternalPose:
978951
r"""
979952
Get the external pose interface
@@ -1480,22 +1453,6 @@ class Platform:
14801453
14811454
As such, this shall only be used for test purpose in a controlled environment.
14821455
"""
1483-
async def send_arming_request(self, do_arm: builtins.bool) -> None:
1484-
r"""
1485-
Send system arm/disarm request
1486-
1487-
Arms or disarms the Crazyflie's safety systems. When disarmed, the motors
1488-
will not spin even if thrust commands are sent.
1489-
1490-
# Arguments
1491-
* `do_arm` - true to arm, false to disarm
1492-
"""
1493-
async def send_crash_recovery_request(self) -> None:
1494-
r"""
1495-
Send crash recovery request
1496-
1497-
Requests recovery from a crash state detected by the Crazyflie.
1498-
"""
14991456
async def get_app_channel(self) -> typing.Optional[AppChannel]:
15001457
r"""
15011458
Get the bidirectional app channel for custom communication
@@ -1578,6 +1535,143 @@ class ProtocolVersionNotSupportedError(CrazyflieError):
15781535

15791536
...
15801537

1538+
@typing.final
1539+
class Supervisor:
1540+
r"""
1541+
Supervisor subsystem
1542+
1543+
Monitors the Crazyflie state and exposes arming, crash recovery,
1544+
and emergency stop controls. Obtain via `crazyflie.supervisor()`.
1545+
"""
1546+
async def read(self) -> SupervisorState:
1547+
r"""
1548+
Read a consistent snapshot of the supervisor state
1549+
1550+
All flags on the returned snapshot are decoded from a single bitfield
1551+
read, so they are from the same moment and mutually consistent. Uses
1552+
time-based caching to avoid flooding the link.
1553+
1554+
The snapshot does not update itself: re-read to get fresh state, for
1555+
example on every iteration when polling.
1556+
1557+
Example:
1558+
state = await cf.supervisor().read()
1559+
if state.can_be_armed and not state.is_armed:
1560+
await cf.supervisor().send_arming_request(True)
1561+
1562+
# When polling, read inside the loop:
1563+
while not (await cf.supervisor().read()).is_armed:
1564+
await asyncio.sleep(0.5)
1565+
"""
1566+
async def send_arming_request(self, do_arm: builtins.bool) -> None:
1567+
r"""
1568+
Send arm/disarm request
1569+
1570+
Arms or disarms the Crazyflie's motors. When disarmed, the motors
1571+
will not spin even if thrust commands are sent.
1572+
1573+
Args:
1574+
do_arm: True to arm, False to disarm
1575+
"""
1576+
async def send_crash_recovery_request(self) -> None:
1577+
r"""
1578+
Send crash recovery request
1579+
1580+
Requests recovery from a crash state detected by the Crazyflie.
1581+
"""
1582+
async def send_emergency_stop(self) -> None:
1583+
r"""
1584+
Send emergency stop
1585+
1586+
Immediately stops all motors and puts the Crazyflie into a locked state.
1587+
The drone will require a reboot before it can fly again.
1588+
"""
1589+
async def send_emergency_stop_watchdog(self) -> None:
1590+
r"""
1591+
Send emergency stop watchdog
1592+
1593+
Activates/resets a watchdog failsafe that will automatically emergency
1594+
stop the drone if this message is not sent every 1000 ms. Once
1595+
activated, you must keep sending this periodically or the drone will
1596+
stop. Use only when you need automatic failsafe behaviour on
1597+
communication loss.
1598+
"""
1599+
1600+
@typing.final
1601+
class SupervisorState:
1602+
r"""
1603+
A snapshot of the supervisor state
1604+
1605+
Decoded from a single supervisor bitfield read: all flags on one snapshot
1606+
are from the same moment and mutually consistent. The snapshot does not
1607+
update itself - call `Supervisor.read()` again for fresh state.
1608+
"""
1609+
@property
1610+
def raw(self) -> builtins.int:
1611+
r"""
1612+
Raw bitfield value
1613+
"""
1614+
@property
1615+
def can_be_armed(self) -> builtins.bool:
1616+
r"""
1617+
The Crazyflie can be armed - will accept an arming command
1618+
"""
1619+
@property
1620+
def is_armed(self) -> builtins.bool:
1621+
r"""
1622+
The Crazyflie is armed
1623+
"""
1624+
@property
1625+
def is_auto_armed(self) -> builtins.bool:
1626+
r"""
1627+
The Crazyflie is configured to automatically arm
1628+
"""
1629+
@property
1630+
def can_fly(self) -> builtins.bool:
1631+
r"""
1632+
The Crazyflie is ready to fly
1633+
"""
1634+
@property
1635+
def is_flying(self) -> builtins.bool:
1636+
r"""
1637+
The Crazyflie is flying
1638+
"""
1639+
@property
1640+
def is_tumbled(self) -> builtins.bool:
1641+
r"""
1642+
The Crazyflie is tumbled (upside down)
1643+
"""
1644+
@property
1645+
def is_locked(self) -> builtins.bool:
1646+
r"""
1647+
The Crazyflie is in the locked state and must be restarted
1648+
"""
1649+
@property
1650+
def is_crashed(self) -> builtins.bool:
1651+
r"""
1652+
The Crazyflie has crashed
1653+
"""
1654+
@property
1655+
def hl_control_active(self) -> builtins.bool:
1656+
r"""
1657+
High level commander is actively flying the drone
1658+
"""
1659+
@property
1660+
def hl_traj_finished(self) -> builtins.bool:
1661+
r"""
1662+
High level commander trajectory has finished
1663+
"""
1664+
@property
1665+
def hl_control_disabled(self) -> builtins.bool:
1666+
r"""
1667+
High level commander is disabled and not producing setpoints
1668+
"""
1669+
def active_states(self) -> builtins.list[builtins.str]:
1670+
r"""
1671+
Names of all active states in this snapshot
1672+
"""
1673+
def __repr__(self) -> builtins.str: ...
1674+
15811675
class SystemError(CrazyflieError):
15821676
r"""
15831677
Async executor error.

cflib2/commander.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

cflib2/console.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

cflib2/error.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

cflib2/high_level_commander.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

cflib2/localization.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
@@ -23,7 +21,6 @@
2321
"""Localization subsystem types"""
2422

2523
from cflib2._rust import (
26-
EmergencyControl,
2724
ExternalPose,
2825
Lighthouse,
2926
LighthouseAngleData,
@@ -33,7 +30,6 @@
3330
)
3431

3532
__all__ = [
36-
"EmergencyControl",
3733
"ExternalPose",
3834
"Lighthouse",
3935
"LighthouseAngleData",

cflib2/log.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

cflib2/memory.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

cflib2/param.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# ,---------, ____ _ __
42
# | ,-^-, | / __ )(_) /_______________ _____ ___
53
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \

0 commit comments

Comments
 (0)