Skip to content

Supervisor subsystem - #16

Merged
gemenerik merged 9 commits into
mainfrom
rik/supervisor
Jul 16, 2026
Merged

Supervisor subsystem#16
gemenerik merged 9 commits into
mainfrom
rik/supervisor

Conversation

@gemenerik

@gemenerik gemenerik commented Jul 16, 2026

Copy link
Copy Markdown
Member

What

Adds a dedicated Supervisor subsystem, reachable via cf.supervisor(), and consolidates all supervisor-related commands there. Previously these were scattered across Platform (arming, crash recovery) and Localization (emergency stop), which didn't match the firmware's supervisor concept or the structure of the underlying crazyflie-lib-rs.

The new subsystem also exposes the supervisor state: Supervisor.read() returns a SupervisorState snapshot decoded from a single bitfield read, so all flags (is_armed, can_fly, is_tumbled, …) are from the same moment and mutually consistent. Reads are cached briefly by the underlying lib to avoid flooding the link. A new examples/reading_supervisor.py demonstrates polling the state.

Breaking changes

The old locations are removed without a deprecation path:

Old New
cf.platform().send_arming_request(do_arm) cf.supervisor().send_arming_request(do_arm)
cf.platform().send_crash_recovery_request() cf.supervisor().send_crash_recovery_request()
cf.localization().emergency().send_emergency_stop() cf.supervisor().send_emergency_stop()
cf.localization().emergency().send_emergency_stop_watchdog() cf.supervisor().send_emergency_stop_watchdog()

The EmergencyControl class is removed entirely. All examples have been migrated.

ArisMorgens and others added 4 commits July 16, 2026 13:27
The previous commits moved these commands to the supervisor subsystem
and kept deprecated copies under platform and localization.emergency
with runtime warnings. There is no released version of this library
yet, so nobody depends on the old locations - remove them instead of
carrying deprecation shims from the first release onward.
The example is correct, but it is a fairly involved flight scenario -
arming, takeoff, in-flight state monitoring, landing - which makes it
more of a demo than a focused API example. reading_supervisor.py
already shows the supervisor API without flying; move this one to the
demos repo instead.
Fix the crash recovery description: it claimed recovery depends on the
crash type, but the firmware only has a single crashed state. Use the
crazyflie-lib wording instead.

Also use "The Crazyflie" consistently instead of mixing it with "the
system", and drop the cache duration from read_bitfield's docstring —
it hardcoded a crazyflie-lib internal constant that can change without
this binding noticing.

Regenerate the type stubs accordingly.
Each state query method independently awaited a bitfield read, so two
consecutive checks could decode different radio reads and report
mutually inconsistent flags - exactly what supervisor-based safety
logic must not do. Replace them with a single read() returning a
SupervisorState snapshot: all flags on one snapshot decode the same
bitfield, so they are consistent by construction, and compound checks
need one await instead of several.

This also mirrors the crazyflie-lib design, where read_bitfield()
returns a SupervisorInfo value that is queried synchronously. The raw
bitfield is available as SupervisorState.raw.
@gemenerik
gemenerik marked this pull request as ready for review July 16, 2026 12:23
@gemenerik
gemenerik requested a review from Copilot July 16, 2026 12:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a dedicated Supervisor subsystem to expose Crazyflie safety/state functionality (arming, crash recovery, emergency stop, and supervisor state snapshot) via the Rust PyO3 bindings, and migrates the previously scattered APIs (Platform arming + Localization emergency control) to the new subsystem.

Changes:

  • Added Supervisor + SupervisorState Rust/Python API, including a cached bitfield snapshot read and safety control commands.
  • Removed deprecated/misplaced APIs: arming + crash recovery from Platform, and emergency stop from Localization.
  • Updated examples and Python type exports/stubs to use cf.supervisor().

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/src/subsystems/supervisor.rs New Supervisor subsystem wrapper + SupervisorState snapshot exposed to Python.
rust/src/subsystems/platform.rs Removes arming/crash-recovery methods from Platform wrapper.
rust/src/subsystems/mod.rs Registers and re-exports the new supervisor module; removes EmergencyControl re-export.
rust/src/subsystems/localization.rs Removes emergency control interface from Localization subsystem.
rust/src/lib.rs Exposes Supervisor and SupervisorState to the Python module.
rust/src/crazyflie.rs Adds Crazyflie.supervisor() accessor returning the Supervisor subsystem.
examples/trajectory.py Updates arming call site to use cf.supervisor().
examples/reading_supervisor.py New example demonstrating supervisor state polling via Supervisor.read().
examples/emergency_watchdog.py Migrates watchdog and arming usage to Supervisor subsystem.
examples/emergency_stop.py Migrates emergency stop and arming usage to Supervisor subsystem.
examples/arming.py Migrates arming/disarming example to Supervisor subsystem.
cflib2/supervisor.py New Python module exporting Supervisor types from the Rust extension.
cflib2/localization.py Removes EmergencyControl from Python-level localization exports.
cflib2/_rust.pyi Updates generated stubs: adds Supervisor API, removes EmergencyControl and removed Platform methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemenerik
gemenerik merged commit 9fc8563 into main Jul 16, 2026
1 check passed
@gemenerik
gemenerik deleted the rik/supervisor branch July 16, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants