This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
projects:crazyflie:firmware:comm_protocol [2012-09-26 13:41] macke |
projects:crazyflie:firmware:comm_protocol [2013-09-17 10:39] ledvinap [Logging] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== 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 21: | Line 47: | ||
| DATA 30 | | | DATA 30 | | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | |||
- | +--------+--------+--------+--------+--------+--....--+--------+ | ||
- | | 0xAA | 0xAA | Header | Length | Data0 | Packet | CRC32 | | ||
- | +--------+--------+--------+--------+--------+--....--+--------+ | ||
</ | </ | ||
Line 39: | Line 61: | ||
==== 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 45: | Line 67: | ||
==== 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 52: | Line 76: | ||
| | | | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | R | | + | | |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
| | | | ||
Line 62: | Line 86: | ||
| DATA 30 | | | DATA 30 | | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | | + | | |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
+--------+--------+--------+--------+--------+--....--+--------+ | +--------+--------+--------+--------+--------+--....--+--------+ | ||
- | | 0xAA | 0xAA | Header | Length | Data0 | Packet | CRC32 | | + | | 0xAA | 0xAA | Header | Length | Data0 | Packet | Cksum | |
+--------+--------+--------+--------+--------+--....--+--------+ | +--------+--------+--------+--------+--------+--....--+--------+ | ||
Line 72: | Line 96: | ||
^ **Field** ^ **Byte** ^ **Bit** ^ | ^ **Field** ^ **Byte** ^ **Bit** ^ | ||
| | | | ||
- | | | + | | |
- | | ::: | | + | | ::: | |
- | | ::: | | + | | ::: | |
- | | Size | + | | Size |
- | | Data | + | | Data |
- | | | + | | Cksum | |
- | ===== Ports ===== | + | === Examples |
- | The following ports are used during | + | To send setpoints to the [[projects: |
- | ^ | + | < |
- | | [[comm_protocol# | + | 0xaa 0xaa 0x30 0x0e 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3e |
- | | | + | </ |
- | | | + | |
- | | | + | |
- | | | + | |
- | + | ||
- | ==== Console ==== | + | |
- | This port is used as a one-way text console. Printouts using printf will be sent on this port and can be read by a receiver if connected. | + | |
+ | To ping Crazyflie: | ||
< | < | ||
- | | + | |
- | +---+---+---+---+---+---+---+---+ | + | <- 0xaa 0xaa 0xf0 0x01 0x01 0xf2 # Received from the copter |
- | | CHAR 0 | | + | |
- | +---+---+---+---+---+---+---+---+ | + | |
- | : | + | |
- | +---+---+---+---+---+---+---+---+ | + | |
- | | CHAR 30 | | + | |
- | +---+---+---+---+---+---+---+---+ | + | |
- | + | ||
- | +--------+--------+--------+--------+--------+--....--+--------+ | + | |
- | | 0xAA | 0xAA | Header | Length | Data0 | | Data30 | | + | |
- | +--------+--------+--------+--------+--------+--....--+--------+ | + | |
</ | </ | ||
- | + | ===== Ports ===== | |
- | 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 ==== | ==== Logging ==== | ||
Line 120: | Line 124: | ||
| | | | ||
- | === Table of content access === | + | === Table of content access |
This channel is used to access the loggable variables table of content. | This channel is used to access the loggable variables table of content. | ||
Line 126: | Line 130: | ||
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' | 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 sequentially | + | The logging variables are requested by the receiver until all variables are returned. When the variable |
- | The CRC32 is a hash of the copter' | + | The CRC32 is a hash of the copter' |
The following messages are sent from the Client to the Crazyflie: | The following messages are sent from the Client to the Crazyflie: | ||
- | ^ **Command** ^ **Byte** | + | ^ **Request for** ^ **Byte** |
- | | TOC item request | + | | TOC item | |
- | | | + | | |
- | | TOC CRC and count | 0 | Request the TOC CRC and item count | | + | | TOC CRC and count | 0 |
The following messages are sent from the Crazyflie to the Client: | The following messages are sent from the Crazyflie to the Client: | ||
- | ^ **Command** ^ **Byte** | + | ^ **Reply for** ^ **Byte** |
- | | TOC item | + | | TOC item |
- | | ::: | + | | ::: |
- | | ::: | + | | ::: |
- | | ::: | + | | ::: |
- | | ::: | + | |
| ::: | | ::: | ||
- | | TOC CRC and count | | + | | TOC CRC and count | |
| ::: | | ::: | ||
- | | ::: | + | | ::: |
+ | | ::: | ||
+ | | ::: | ||
== Usage == | == Usage == | ||
Line 162: | Line 167: | ||
| | ||
| | ||
- | Request for TOC item ---> | + | Request for TOC item 0 ---> |
- | with ID omitted | + | |
- | < | + | Request for TOC item 1 ---> |
- | Request for TOC item ---> | + | |
- | | + | |
- | | + | |
- | | + | Request for TOC item N-1 ---> |
- | Request for TOC item ---> | + | where N is Number of |
- | | + | total variables in TOC |
+ | < | ||
+ | [optional] | ||
+ | Request for TOC item N | ||
+ | (or any higher) | ||
+ | < | ||
[Fetch complete] | [Fetch complete] | ||
</ | </ | ||
- | === Log settings access === | + | |
+ | === Log settings access | ||
This channel is used to access the log settings to add/ | This channel is used to access the log settings to add/ | ||
== Messages == | == Messages == | ||
The following messages are sent from the Client to the Crazyflie: | The following messages are sent from the Client to the Crazyflie: | ||
- | ^ **Command byte** ^ **Byte** | + | ^ **Request for** ^ **Byte** |
- | | 0 | + | | |
- | | ::: | + | | ::: | |
- | | ::: | + | | ::: | 2-31 | [[comm_protocol# |
- | | ::: | + | | |
- | | 1 | + | | ::: | |
- | | ::: | + | | ::: | 2-31 | [[comm_protocol# |
- | | ::: | + | | |
- | | 2 | + | | ::: | |
- | | ::: | + | | Start a log block | |
- | | 3 | + | | ::: | |
- | | ::: | + | | ::: |
- | | 4 | + | | Stop a log block | |
- | | ::: | + | | ::: | |
+ | | Reset log | ||
+ | |||
The response for all of the above messages is sent from the Crazyflie to the Client: | The response for all of the above messages is sent from the Crazyflie to the Client: | ||
^ **Byte** | ^ **Byte** | ||
| | | | ||
- | | | + | | |
| | | | ||
Line 203: | Line 217: | ||
The following format is used to identify a variable that is to be logged from the Crazyflie | 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** | ^ **Log Type** | ||
Line 214: | Line 229: | ||
| | | | ||
- | ^ **Storage Type** | + | ^ **Storage Type** |
- | | | + | | |
| | | | ||
| | | | ||
Line 224: | Line 239: | ||
| | | | ||
+ | TOC variable request (Storage type is ignored, it is taken from Crazyflie internal TOC): | ||
< | < | ||
7 | 7 | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | Log type | Storage type | + | | Storage type |
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
| Variable ID | | | Variable ID | | ||
Line 233: | Line 249: | ||
</ | </ | ||
+ | Arbitrary memory address request: | ||
< | < | ||
7 | 7 | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
- | | Log type | + | | Storage type | Log type | |
+ | +---+---+---+---+---+---+---+---+ | ||
+ | | 0xff | | ||
+---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ | ||
| Mem Address 0 | | | Mem Address 0 | | ||
Line 249: | Line 268: | ||
- | == List of return codes == | + | == List of return codes ( errno.h codes are used, returned values are positive ) == |
- | ^ **Error** | + | ^ **Error** |
- | | 0x00 | + | | |
- | | 0x01 | + | | |
- | | 0x02 | + | | E2BIG (7) |
- | | 0xFF | + | | |
+ | | ENOMEM (12) | No memory to allocate Log Block or Log Item | ||
== Usage == | == Usage == | ||
- | Adding a new log block to the settings: | + | Adding a new log block with id 0x0a with variable 0x55 type uint32_t and variable 0x66 type float32 |
< | < | ||
| | ||
| | ||
- | Add log packet | + | Add log block |
- | < | + | < |
[DONE] | [DONE] | ||
Packet structure: | Packet structure: | ||
- | Computer -> CF : 0x[5,1] 0x00 0x01 0x0A 0x02 0x55 | + | Computer -> CF : 0x[5,1] 0x00 0x0a 0x03 0x55 0x07 0x66 |
- | CF -> Computer : 0x[5,1] 0x00 0x55 0x00 | + | CF -> Computer : 0x[5,1] 0x00 0x0a 0x00 |
</ | </ | ||
- | Deleting an existing log block from the settings: | + | Deleting an existing log block 0x55 from the settings: |
< | < | ||
| | ||
Line 283: | Line 303: | ||
</ | </ | ||
- | === Log data access === | + | === Log data access |
- | 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 has to be done on the computer side. | + | 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 has to be done on the computer side. Log |
+ | block header contains 3 byte timestamp, its value is number of milliseconds from Crazyflie system start (it will wrap around in about 5 hours). All values are sent in little endian format. | ||
+ | |||
+ | ^ **Byte** | ||
+ | | | ||
+ | | 1-3 | Block send time timestamp in ms, LSB first | | ||
+ | | 4-31 | Logged variable values, LSB first | | ||
< | < | ||
- | Adding a log block logging variable ID 0x55 at 100ms interval and of type uint16: | + | Adding a log block 0xbb at 100ms interval |
- | Computer -> CF : 0x[5,1] 0x00 0x01 0x0A 0x02 0x55 | + | Computer -> CF : 0x[5,1] 0x00 0xbb 0x02 0x55 // create logging block |
- | CF -> Computer : 0x[5,1] 0x00 0x55 0x00 | + | CF -> Computer : 0x[5,1] 0x00 0x55 0x00 // OK |
+ | Computer -> CF : 0x[5,1] 0x00 0xbb 0x0A // start sending block with 100ms interval | ||
+ | CF -> Computer : 0x[5,1] 0x00 0x55 0x00 // OK | ||
- | Receiving a log block logging variable | + | Receiving a log block 0xbb with timestamp 130.532s (0x1FDE4 ms), logging |
- | CF -> Computer : 0x[5, | + | CF -> Computer : 0x[5, |
</ | </ | ||
- | |||
==== Parameters ==== | ==== Parameters ==== | ||
The parameters system aims at making accessible all the gettable and settable parameters of the copter. In the copter a table of parameters is hold and can be retrieved. In this table every parameter name is associated with an ID and a group name. Three ID are used to acces the TOC and the paramareters: | The parameters system aims at making accessible all the gettable and settable parameters of the copter. In the copter a table of parameters is hold and can be retrieved. In this table every parameter name is associated with an ID and a group name. Three ID are used to acces the TOC and the paramareters: | ||
Line 337: | Line 364: | ||
**TODO** | **TODO** | ||
- | === Link layter | + | === Link layer === |
| 3: | | 3: | ||
| 3: | | 3: | ||
| 3: | | 3: | ||
| 3: | | 3: |