-
Notifications
You must be signed in to change notification settings - Fork 920
Added SupervisorState util #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
237ec6c
to
666c372
Compare
There was a problem hiding this 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 = [ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | ||
|
||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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 ofsupervisor.info
only once. This is done by creating a newLogConfig
, wait until the first value arrives and then stop it.Specifically:
read_supervisor_state_bitfield()
returns the value ofsupervisor.info
.read_supervisor_state_list()
returns the list of all active states.True
if they're active andFalse
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 thedecode_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.