This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
projects:crazyflie:firmware:comm_protocol [2012-08-07 19:53] macke |
projects:crazyflie:firmware:comm_protocol [2021-06-24 16:49] (current) kimberly |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP center round important 60%> | ||
+ | This page has deprecated and will be archived. Please go to [[https:// | ||
+ | </ | ||
====== Overview ====== | ====== Overview ====== | ||
- | ===== CRTP ===== | + | CRTP is the protocol used to communicate |
- | The CRTP (Crazy RealTime Protocol) | + | |
- | * [[comm_protocol# | + | CRTP is implemented in 3 layers: |
- | | + | |
- | | + | < |
- | * ... | + | |
+ | | ||
+ | | ||
+ | | CRTP packets handling | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | * **CRTP Link** is responsible for transferring the packets between the copter and the PC. It will typically handles packet size and error detection. | ||
+ | * **CRTP Packet handling** delivers the packet to the right subsystem in the copter and in the PC control software. | ||
+ | * **Application/ | ||
+ | |||
+ | Implemented link drivers: | ||
+ | ^ **Link** | ||
+ | | [[comm_protocol# | ||
+ | | [[comm_protocol# | ||
+ | | [[comm_protocol# | ||
+ | |||
+ | Current port allocation: | ||
+ | ^ **Port** | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
====== Communication ====== | ====== Communication ====== | ||
Line 13: | Line 42: | ||
7 | 7 | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | R | | + | | |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
| DATA 0 | | | DATA 0 | | ||
Line 21: | Line 50: | ||
| DATA 30 | | | DATA 30 | | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
+ | |||
</ | </ | ||
+ | ^ **Field** ^ **Byte** ^ **Bit** ^ | ||
+ | | | ||
+ | | ::: | | ||
+ | | ::: | | ||
+ | | Data | ||
+ | |||
+ | A port maps to a major function in the Crazyflie that is normally implemented as a separate task. When a CRTP packet is received in the Crazyflie the packet is routed according to the port. The channel can be seen as a sub-set for the port where and can be used to further define commands for the receiving function but no routing will be done using the channel. | ||
===== Physical layers ===== | ===== Physical layers ===== | ||
Line 27: | Line 64: | ||
==== 2.4 GHz NordicSemi Radio ==== | ==== 2.4 GHz NordicSemi Radio ==== | ||
- | The wireless interface will add additional header data like CRC when sending the packet and therefore the packet sent to the wireless interface is only a CRTP packet. | + | The wireless interface will add additional header data like CRC when sending the packet and therefore the packet sent to the wireless interface is only a CRTP packet |
==== USB port ==== | ==== USB port ==== | ||
Line 33: | Line 70: | ||
==== Serial port ==== | ==== Serial port ==== | ||
+ | The serial port is configured in 115200 8N1. CRTP packets are sent and received asynchronously using the following packet format: | ||
+ | |||
< | < | ||
7 | 7 | ||
Line 40: | Line 79: | ||
| | | | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | R | | + | | |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
| | | | ||
Line 50: | Line 89: | ||
| DATA 30 | | | DATA 30 | | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | | + | | |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
+ | |||
+ | +--------+--------+--------+--------+--------+--....--+--------+ | ||
+ | | 0xAA | 0xAA | Header | Length | Data0 | Packet | Cksum | | ||
+ | +--------+--------+--------+--------+--------+--....--+--------+ | ||
+ | |||
</ | </ | ||
+ | ^ **Field** ^ **Byte** ^ **Bit** ^ | ||
+ | | | ||
+ | | | ||
+ | | ::: | | ||
+ | | ::: | | ||
+ | | Size | ||
+ | | Data | ||
+ | | | ||
+ | === Examples === | ||
+ | To send setpoints to the [[projects: | ||
+ | < | ||
+ | 0xaa 0xaa 0x30 0x0e 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3e | ||
+ | </ | ||
+ | |||
+ | To ping Crazyflie: | ||
+ | < | ||
+ | | ||
+ | < | ||
+ | </ | ||
===== Ports ===== | ===== Ports ===== | ||
- | | *Port* | ||
- | | [[comm_protocol# | ||
- | | [[comm_protocol# | ||
- | | [[comm_protocol# | ||
- | | [[comm_protocol# | ||
- | | 0: | ||
- | | [[comm_protocol# | ||
- | | 3: | ||
- | | 3: | ||
- | | 3: | ||
- | | 3: | ||
- | ==== Console | + | ==== Logging |
- | This port is used as a one-way text console. Printouts | + | The purpose of the logging |
+ | |||
+ | ^ **Port** | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | |||
+ | === Table of content access (Port 5 channel 0) === | ||
+ | This channel is used to access the loggable variables table of content. | ||
+ | |||
+ | == Messages == | ||
+ | Each message uses an additional command byte that is followed by 0 to 31 bytes of data depending of the command. For every command byte there' | ||
+ | |||
+ | The logging variables are requested by the receiver until all variables are returned. When the variable index is out of range, empty reply is returned (1 byte reply with 0x00 identifying the command). The Get CRC command returns the number of loggable variables N, individual variables are indexed from 0 to N-1. | ||
+ | |||
+ | The CRC32 is a hash of the copter' | ||
+ | |||
+ | The following messages are sent from the Client to the Crazyflie: | ||
+ | ^ **Request for** ^ **Byte** | ||
+ | | TOC item | | ||
+ | | ::: | ||
+ | | TOC CRC and count | 0 | 0x01 (CMD_GET_INFO) Request the TOC CRC and item count | | ||
+ | |||
+ | The following messages are sent from the Crazyflie to the Client: | ||
+ | ^ **Reply for** ^ **Byte** | ||
+ | | TOC item | ||
+ | | ::: | ||
+ | | ::: | ||
+ | | ::: | ||
+ | | ::: | ||
+ | | TOC CRC and count | | ||
+ | | ::: | ||
+ | | ::: | ||
+ | | ::: | ||
+ | | ::: | ||
+ | |||
+ | == Usage == | ||
+ | Example of checking the CRC of a TOC to determine | ||
+ | < | ||
+ | | ||
+ | | ||
+ | Get TOC CRC32 ---> | ||
+ | < | ||
+ | [Compare CRC] | ||
+ | </ | ||
+ | |||
+ | Example of downloading TOC contents from Crazyflie. | ||
+ | < | ||
+ | | ||
+ | | ||
+ | Request for TOC item 0 | ||
+ | < | ||
+ | Request for TOC item 1 | ||
+ | < | ||
+ | | ||
+ | | ||
+ | Request for TOC item N-1 ---> | ||
+ | where N is Number of | ||
+ | total variables in TOC | ||
+ | < | ||
+ | [optional] | ||
+ | Request for TOC item N | ||
+ | (or any higher) | ||
+ | < | ||
+ | [Fetch complete] | ||
+ | </ | ||
+ | |||
+ | === Log settings access (Port 5 channel 1) === | ||
+ | This channel is used to access the log settings to add/ | ||
+ | |||
+ | == Messages == | ||
+ | The following messages are sent from the Client to the Crazyflie: | ||
+ | ^ **Request for** ^ **Byte** | ||
+ | | Create a new log block | ||
+ | | ::: | | ||
+ | | ::: | 2-31 | [[comm_protocol# | ||
+ | | Append to existing log block | ||
+ | | ::: | | ||
+ | | ::: | 2-31 | [[comm_protocol# | ||
+ | | Delete a log block | ||
+ | | ::: | | ||
+ | | Start a log block | ||
+ | | ::: | | ||
+ | | ::: | | ||
+ | | Stop a log block | ||
+ | | ::: | | ||
+ | | Reset log | ||
+ | |||
+ | |||
+ | |||
+ | The response for all of the above messages is sent from the Crazyflie to the Client: | ||
+ | ^ **Byte** | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | |||
+ | |||
+ | == Variable format == | ||
+ | The following format is used to identify a variable that is to be logged from the Crazyflie | ||
+ | |||
+ | Log Type represents type of value sent in packet. Logged value is converted to this type before storing into log packet. Upper bytes will be discarded if Log Type is integer and value does not fit. | ||
+ | |||
+ | ^ **Log Type** | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | |||
+ | ^ **Storage Type** | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | TOC variable request (Storage type is ignored, it is taken from Crazyflie internal TOC): | ||
< | < | ||
7 | 7 | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | CHAR 0 | + | | Storage type | Log type | |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | : : | + | | Variable ID | |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | CHAR 30 | | + | </ |
+ | |||
+ | Arbitrary memory address request: | ||
+ | < | ||
+ | 7 | ||
+ | +---+---+---+---+---+---+---+---+ | ||
+ | | | ||
+ | +---+---+---+---+---+---+---+---+ | ||
+ | | 0xff | ||
+ | +---+---+---+---+---+---+---+---+ | ||
+ | | Mem Address 0 | | ||
+ | +---+---+---+---+---+---+---+---+ | ||
+ | | Mem Address 1 | | ||
+ | +---+---+---+---+---+---+---+---+ | ||
+ | | Mem Address 2 | | ||
+ | +---+---+---+---+---+---+---+---+ | ||
+ | | Mem Address 3 | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
</ | </ | ||
- | The contents of the buffer on the copter side is sent if any of the following is fulfulled: | ||
- | * The output buffer (of 31 bytes) is full | ||
- | * A " | ||
- | * A flush command as been issued | ||
- | ==== Logging ==== | + | == List of return codes ( errno.h codes are used, returned values are positive ) == |
- | The purpose of the logging | + | ^ **Error** |
+ | | 0 | No error | | ||
+ | | ENOENT (2) | Block or variable not found | | ||
+ | | E2BIG (7) | Log block is too long | | ||
+ | | ENOEXEC (8) | Unknown command received | ||
+ | | ENOMEM (12) | No memory | ||
- | | **Port** | + | == Usage == |
- | | (0, | + | Adding a new log block with id 0x0a with variable 0x55 type uint32_t and variable 0x66 type float32 |
- | | (0, | + | < |
- | | (0, | + | |
- | + | | |
- | === TOC access === | + | Add log block ---> |
- | This port is used to access | + | < |
+ | [DONE] | ||
- | | **Message ID** | **Meaning in upstream packets** | **Meaning in downstream packets** | | + | Packet structure: |
- | | 0 | Reset TOC pointer | + | Computer -> CF : 0x[5,1] 0x00 0x0a 0x03 0x55 0x07 0x66 |
- | | | + | CF -> Computer |
- | | 3 | Get TOC CRC32 | TOC CRC32 | | + | </ |
- | + | ||
- | The upstream ID are commands and are sent alone. The downstream have the following formats: | + | |
+ | Deleting an existing log block 0x55 from the settings: | ||
< | < | ||
- | Bytes | + | Computer |
- | +---+------------+------+----------+--------------+ | + | |
- | | 0 | | | | | | + | Delete log packet |
- | +---+ Var ID | Type | Group | + | <--- Log packet deleted ok |
- | | 1 | | | | | | + | [DONE] |
- | | + | |
- | | 3 | Num. Vars | CRC32 | | + | Packet structure: |
- | +---+------------+----------+ | + | Computer |
- | Bytes | + | CF -> Computer : 0x[5,1] 0x02 0x55 0x00 |
</ | </ | ||
- | The logging variables are sequentially requested by the receiver until the end. When the last loggable variable | + | === Log data access (Port 5 channel 2) === |
+ | Logging data is sent back to the copter as raw data with only the block id. This means that the lookup of what data is for what variable | ||
+ | block header contains 3 byte timestamp, its value is number of microseconds from Crazyflie system start (it will wrap around in about 16 seconds. Is is also currently based on xTaskGetTickCount, | ||
- | The CRC32 is a hash of the copter' | + | ^ **Byte** |
+ | | | ||
+ | | 1-3 | Block send time timestamp in us, LSB first | | ||
+ | | 4-31 | Logged | ||
- | === Block access === | + | < |
- | **TODO** | + | Adding a log block 0xbb at 100ms interval logging variable ID 0x55 of type uint16: |
- | === Logging data === | + | Computer -> CF : 0x[5,1] 0x00 0xbb 0x02 0x55 // create logging block |
- | **TODO** | + | CF -> Computer : 0x[5,1] 0x00 0x55 0x00 // OK |
+ | Computer -> CF : 0x[5,1] 0x03 0xbb 0x0A // start sending block with 100ms interval | ||
+ | CF -> Computer : 0x[5,1] 0x03 0x55 0x00 // OK | ||
+ | Receiving a log block 0xbb with timestamp 130.532s (0x1FDE4 ms), logging uint16 variable with value 0xBABE: | ||
+ | CF -> Computer : 0x[5,2] 0xBB 0xE4 0xFD 0x01 0xBE 0xBA | ||
+ | </ | ||
==== Parameters ==== | ==== Parameters ==== | ||
- | The parameters system | + | The parameters system |
- | | **Port** | **Function** | | + | ^ Port ^ Channel |
- | | | + | | |
- | | | + | | |
- | | | + | | 2 | 2 | Parameter write | |
- | === TOC access === | + | === TOC access |
- | This ports permits | + | These messages permit |
- | | **Message ID** | **Meaning in upstream packets** | **Meaning in downstream packets** | | + | ^ |
- | | 0 | Reset TOC pointer | + | | 0 | Reset TOC pointer |
- | | 1 | Get next TOC element | + | | 1 | Get next TOC element |
- | | 3 | Get TOC CRC32 | TOC CRC32 | + | | 3 | Get TOC CRC32 |
- | The upstream ID are commands and are sent alone. The downstream | + | The upstream ID are commands and are sent alone. The downstream |
< | < | ||
Line 155: | Line 355: | ||
</ | </ | ||
- | The parameters are sequentially requested by the PC until the end. When the last parameter is reached it has the ID 0 'Last TOC element' | + | The parameters are sequentially requested by the PC until the end. When the last parameter is reached it has the ID 0 'Last TOC element' |
- | The CRC32 is a hash of the copter TOC. This is aim at implementing caching of the TOC in the PC Utils to avoid fetching the full TOC each time the copter is connected. | + | The CRC32 is a hash of the copter TOC. This is aimed at implementing caching of the TOC in the PC Utils to avoid fetching the full TOC each time the copter is connected. |
- | === Parameter read === | + | === Parameter read (Port 2 channel 1) and parameter write (Port 2 channel 2)=== |
- | **TODO** | + | |
- | === Parameter write === | + | The following messages are sent from the client to the Crazyflie: |
- | **TODO** | + | ^ |
+ | | Parameter read | | ||
+ | | | ||
+ | | ::: | ||
+ | |||
+ | The following messages are sent from the Crazyflie to the client: | ||
+ | ^ | ||
+ | | Parameter read & write | ||
+ | | ::: | ||
=== Fight control ==== | === Fight control ==== | ||
**TODO** | **TODO** | ||
+ | |||
+ | === Link layer === | ||
+ | | 3: | ||
+ | | 3: | ||
+ | | 3: | ||
+ | | 3: |