This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
doc:crazyflie:client:cfzmq:index [2015-03-11 09:40] macke |
doc:crazyflie:client:cfzmq:index [2021-06-24 16:42] (current) kimberly |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP center round important 60%> | ||
+ | This page has deprecated and will be archived. Please go to [[https:// | ||
+ | </ | ||
+ | |||
+ | //This page is about the stand-alone console ZMQ server. For Crazyflie client GUI ZMQ input see [[doc: | ||
+ | |||
+ | ====== ZMQ server ====== | ||
+ | The [[http:// | ||
+ | |||
+ | The application uses 4 ports for communicating: | ||
+ | * 2000: Main command/ | ||
+ | * 2001: Logging data and events (publish) | ||
+ | * 2002: Param events and values(publish) | ||
+ | * 2003: Connection events (publish) | ||
+ | * 2004: Control data (pull) | ||
+ | |||
+ | All communication is done using JSON. To test the implementation we have a [[https:// | ||
+ | |||
+ | ====== cfzmq ====== | ||
+ | The client is run using the command line: | ||
+ | < | ||
+ | $ bin/cfzmq -h | ||
+ | usage: cfzmq [-h] [-u URL] [-d] | ||
+ | |||
+ | optional arguments: | ||
+ | -h, --help | ||
+ | -u URL, --url URL URL where ZMQ will accept connections | ||
+ | -d, --debug | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | The default URL is set to only allow local connections: | ||
+ | < | ||
+ | tcp:// | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | <WRAP half column> | ||
+ | The following commandline will allow remote control: | ||
+ | < | ||
+ | $bin/cfqmq --url " | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== Command socket ====== | ||
+ | The command messages are implemented as server/ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | Example command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response of **successful** command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | For each command there' | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response of **unsuccessful** command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | ===== scan ===== | ||
+ | The scan command will trigger a scanning of all of the available interfaces on the server (USB and Crazyradio) and return all the Crazyflies found. If no interfaces are available (no Crazyradio or Crazyflie) the command will return an empty list. Therefore there' | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | Example command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | [ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | ===== connect ===== | ||
+ | The connect command will connect to the supplied URI, download the logging TOC and parameter TOC/values and return everything. There' | ||
+ | |||
+ | The log TOC will be found in the //log// dictionary, where the first level is group, the second level is name and the third is the attributes (see below). So the type of // | ||
+ | |||
+ | The param TOC will be found in the //param// dictionary, where the first level is group, the second level is name and the third is the attributes (see blow). So the RO/RW attribute for // | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | Example command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response of **successful** command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | If no Crazyflie is found status 1 will be returned and an error message will be supplied from the driver. | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response of **unsuccessful** command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | For the log variables (found in //log//) the following attributes are set: | ||
+ | ^ Field ^ Type ^ Comment | ||
+ | | type | string | (u)int8, (u)int16, (u)int32, float | | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | For the parameters (found in //param//) the following attributes are set: | ||
+ | ^ Field ^ Type ^ Comment | ||
+ | | access | ||
+ | | type | string | (u)int8_t, (u)int16_t, (u)int32_t, float | | ||
+ | | value | string | String representation of the current parameter value | | ||
+ | </ | ||
+ | </ | ||
+ | ===== log ===== | ||
+ | Logging data from the Crazyflie is done by setting up log configurations that will push log data at a specified interval ([[doc: | ||
+ | |||
+ | **Note**: When a host connects to a Crazyflie the log configurations are all deleted. So if you connect, set up log configurations, | ||
+ | |||
+ | Below is an example for creating a logging configuration and starting it. The configuration contains the two variables //pm.vbat// and // | ||
+ | |||
+ | Each action for log configurations (create, start, stop, delete) will be broadcasted on the log data socket. Log data will also be boardcasted on the same socket. | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | First create the configuration: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | Then start the configuration: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | The following attributes should be set in the request packet: | ||
+ | ^ Field ^ Type ^ Comment | ||
+ | | name | string | Name of configuration | all | | ||
+ | | action | ||
+ | | period | ||
+ | | variables | list | List of variables " | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | The following errors can be seen in the response packet: | ||
+ | ^ Action | ||
+ | | create | 0x01 | One or more variables were not found in the TOC | | ||
+ | | create | 0x02 | The period is either too small/large of the configuration too large | | ||
+ | | create | 0x03 | Timeout was hit when performing action. | ||
+ | | start/ | ||
+ | | start/ | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP center round info 80%> | ||
+ | The Python API supports logging variables using different types than what the variables is declared as in the firmware. I.e you can log a uint32_t as a uint8_t, retaining the 8 MSB ([[doc: | ||
+ | </ | ||
+ | ===== param ===== | ||
+ | During run-time it's possible to set parameters that are mapped directly to variables in the firmware ([[doc: | ||
+ | |||
+ | Below is an example command to set the // | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | Example command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response of **successful** command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | The following errors can be seen in the response packet: | ||
+ | ^ Status | ||
+ | | 0x01 | The parameter was not found in the TOC | | ||
+ | | 0x02 | The parameter is RO and cannot be set | | ||
+ | | 0x03 | The timeout was reached | | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example response of **un-successful** command: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | The API accepts values as unsigned/ | ||
+ | to a number (0 for false, 1 for true). The type should match the type that is in the TOC (i.e don't try to set a float for a uint_8 variable). | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | ^ Field ^ Type ^ Comment | ||
+ | | name | string | Name of parameter (group.name) | | ||
+ | | value | unsigned/ | ||
+ | </ | ||
+ | </ | ||
+ | ====== Log socket ====== | ||
+ | This socket is used for sending log configuration events as well as log data. The events that are sent is for creating, starting, stopping and deleting a configuration. For every started configuration the log data will be sent over this socket. To control this see the [[doc: | ||
+ | |||
+ | Each message contains an //event// field (see below) and a //name// field referring to the log configuration name. | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | The following events are sent: | ||
+ | ^ Event ^ Comment | ||
+ | | created | ||
+ | | started | ||
+ | | stopped | ||
+ | | deleted | ||
+ | | data | Log data (see below) | | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example of a //started// event: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | The following fields is in the data event: | ||
+ | ^ Field ^ Type ^ Comment | ||
+ | | name | string | ||
+ | | timestamp | int | Time since system start (in ms) | | ||
+ | | variables | dict | Dictionary where the keys are variable names (group.name) and the values are the variable values | | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example of a data event: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | ====== Param socket ====== | ||
+ | This socket is used to broadcast parameter updates done on the [[doc: | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | For each update the variable name and value is sent. | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== Connection socket ====== | ||
+ | This socket is used to broadcast changes in the connection state as events. Connecting the Crazyflie is a synchronous call to the [[doc: | ||
+ | |||
+ | Each event has a name and uri, there might also be an optional message. Note that disconnected is always sent no matter the reason. So a requested disconnect will send a // | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | There' | ||
+ | ^ Event ^ Comment | ||
+ | | requested | ||
+ | | connected | ||
+ | | failed | ||
+ | | disconnected | A Crazyflie has been disconnected | No | | ||
+ | | lost | An open connection has been lost | Yes | | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | Example of a lost connection: | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | ====== Control socket ====== | ||
+ | Control commands can be sent at any time after the Crazyflie has been connected and has the following scaling/ | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | ^ Param ^ Unit ^ Limit ^ | ||
+ | | roll | degrees| N/A | | ||
+ | | pitch | degrees| N/A | | ||
+ | | yaw | degrees/s| N/A | | ||
+ | | thrust | ||
+ | </ | ||
+ | </ |