Crazyflie console is used to receive characters printed using printf from the firmware.
The Crazyflie can have several consoles. Each one has a path, such as
cf:stm32 for the Crazyflie’s own STM32 or deck:bcCam for the Camera Deck.
Console.list() returns the paths of the connected Crazyflie and
Console.open() starts receiving one of them:
print(cf.console.list()) # ['cf:stm32', 'deck:bcCam']
with cf.console.open('deck:bcCam', line_cb=print):
time.sleep(10)
Consoles other than cf:stm32 are only sent while they are open. When
connecting, the library asks the Crazyflie to stop sending them, in case an
earlier connection left them open.
Classes
Console
Console(crazyflie)
Crazyflie console is used to receive characters printed using printf from the firmware.
Initialize the console and register it to receive data from the copter.
Instance variables
receivedChar
This member variable is used to setup a callback that will be called when text is received from the Crazyflie’s own console (CRTP port 0, channel 0). This works with every firmware version.
The text arrives in chunks of up to 30 bytes. A chunk can end in the middle of a line, so do not add a newline after each one.
Example:
[...]
def log_console(self, text):
self.log_file.write(text)
[...]
self.cf.console.receivedChar.add_callback(self.log_console)
Methods
def list(self, timeout=5.0)
Return the paths of the consoles of the connected Crazyflie, for
example ['cf:stm32', 'deck:bcCam'].
cf:stm32 is always first. Other consoles require CRTP protocol
version 13; with older firmware only cf:stm32 is returned. The list
is read from the Crazyflie once per connection.
This blocks, so do not call it from a cflib callback. Raises ConsoleError if the list cannot be read within timeout seconds.
def open(self, path, text_cb=None, line_cb=None, history=True, timeout=5.0)
Start receiving the console with this path and return its ConsoleHandle.
text_cb is called with text as it arrives, in chunks that can end in the middle of a line. line_cb is called with each complete line, without its line ending. Both are called from a cflib thread.
With history=True, the output received since connection is passed to the callbacks before this returns, followed by new output. This shows startup messages. With history=False, only new output is passed.
This blocks, so do not call it from a cflib callback. Raises ConsoleError if the Crazyflie has no console with this path, rejects the request, or does not answer within timeout seconds.
ConsoleError
ConsoleError(message, errno=None)
Error from a console operation.
errno holds the firmware’s error number when the Crazyflie rejected the
request, and is None otherwise.
Ancestors (in MRO)
- builtins.Exception
- builtins.BaseException
ConsoleHandle
ConsoleHandle(console, session, state, text_cb, line_cb)
An open console, returned by Console.open().
Output is passed to the callbacks given to Console.open() until the
handle is closed or the Crazyflie disconnects. Close it with close() or
use it in a with statement.
Instance variables
closed
True after close() or when the Crazyflie has disconnected.
path
The path of this console, for example deck:bcCam.
Methods
def close(self, timeout=5.0)
Stop receiving this console.
When this is the last open handle of a console other than cf:stm32,
the Crazyflie is asked to stop sending it and this waits for its
answer. Closing does not lose output: the console keeps buffering on
its side and a later Console.open() replays the history.
Raises ConsoleError if the Crazyflie rejects the request or does not answer within timeout seconds.