Skip to content

Conversation

ArisMorgens
Copy link
Member

@ArisMorgens ArisMorgens commented Sep 16, 2025

Based on #530, there is currently no direct access to the supervisor states, making it difficult to determine whether the drone is considered landed or flying.
This PR adds a SupervisorState util that makes it easy to read the state of the Crazyflie through the supervisor.

Instead of continuously logging supervisor.info, functions in the SupervisorState class read the value of supervisor.info only once. This is done by creating a new LogConfig, wait until the first value arrives and then stop it.

Specifically:

  • read_supervisor_state_bitfield() returns the value of supervisor.info.
  • read_supervisor_state_list() returns the list of all active states.
  • All the individual state checks return True if they're active and False if they're not. can_be_armed(), is_armed(), is_auto_armed(), can_fly(), is_flying(), is_tumbled(), is_locked(), is_crashed(), active_hl_control(), finished_hl_traj(), disabled_hl_control()

If the users want to continuously read supervisor.info, they can still create their log block and use the decode_bitfield() function to turn the integer into a list with the names of all states whose bits are set.

Finally, this PR also adds a simple example where we use SupervisorState to read the state of a Crazyflie and fly based on that.

@ArisMorgens ArisMorgens requested a review from enyanil October 6, 2025 12:47
@ArisMorgens ArisMorgens force-pushed the Aris/SupervisorState branch from 237ec6c to 666c372 Compare October 6, 2025 12:59
Copy link
Contributor

@enyanil enyanil left a comment

Choose a reason for hiding this comment

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

Super nice addition and really nicely done! I left some small suggestions for updates if there is something you want to check out.



class SupervisorState:
STATES = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe replace "can be" with "ready to" (for example ready to fly)? Matches with other places and might be a bit more clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted the states to match the corresponding firmware ones. Changed "Auto armed" to "Is_auto_armed"

returns the names of all states whose bits are set.
Bit 0 corresponds to states[0], Bit 1 to states[1], etc.
* Bit 0 = Can be armed - the system can be armed and will accept an arming command
Copy link
Contributor

Choose a reason for hiding this comment

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

Picky, but finish all points with a period, right now some have a period at the end and some don't.

from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie


Copy link
Contributor

Choose a reason for hiding this comment

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

Not a must but could be nice with a short explanation on how this class is intended to be used/what it is good for.


try:
if sup.can_be_armed():
safety_check(sup)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a print similar to: print('The Crazyflie can arm...arming!') to match the other states.

@ArisMorgens ArisMorgens removed the request for review from ataffanel October 7, 2025 11:53
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.

2 participants