User Tools

Site Tools


projects:crazyflie:firmware:comm_protocol

This is an old revision of the document!


Overview

CRTP

The CRTP (Crazy RealTime Protocol) is the name of the protocol used to communication with the Crazyflie. The protocol is used for multiple physical layers:

Communication

Packet structure

A CRTP packet consists of a 8bit header followed by 0-31 bytes of data.

  7   6   5   4   3   2   1   0
+---+---+---+---+---+---+---+---+
| R |     Port      |  Channel  |
+---+---+---+---+---+---+---+---+
|            DATA 0             |
+---+---+---+---+---+---+---+---+
:   :   :   :   :   :   :   :   :
+---+---+---+---+---+---+---+---+
|            DATA 30            |
+---+---+---+---+---+---+---+---+

Physical layers

Below is the structures for the packages both for the wired serial interface and for the wireless interface. The limitation for the length of the data is set so that it will fit inside one packet for the wireless transmission.

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.

USB port

TODO

Serial port

  7   6   5   4   3   2   1   0
+---+---+---+---+---+---+---+---+
|             0xAA              |
+---+---+---+---+---+---+---+---+
|             0xAA              |
+---+---+---+---+---+---+---+---+
| R |     Port      |  Channel  |
+---+---+---+---+---+---+---+---+
|         Packet length         |
+---+---+---+---+---+---+---+---+
|            DATA 0             |
+---+---+---+---+---+---+---+---+
:   :   :   :   :   :   :   :   :
+---+---+---+---+---+---+---+---+
|            DATA 30            |
+---+---+---+---+---+---+---+---+
|              CRC              |
+---+---+---+---+---+---+---+---+

Ports

*Port* *Target*
000 Console
*5* Logging
*9* Parameters
*13* Flight control
0:13:0 Send/Receive yaw, pith, roll and throttle
*15* Link layer reserved
3:15:0 Echo (profiling)
3:15:1 Source (profiling)
3:15:2 Sink (profiling)
3:15:3 NULL packet

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.

  7   6   5   4   3   2   1   0
+---+---+---+---+---+---+---+---+
|             CHAR 0            |
+---+---+---+---+---+---+---+---+
:   :   :   :   :   :   :   :   :
+---+---+---+---+---+---+---+---+
|             CHAR 30           |
+---+---+---+---+---+---+---+---+

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 “newline” character has to be send (\n and/or \r)
  • A flush command as been issued

Logging

The purpose of the logging is to be able to log variables that are available in the copter during runtime. The available variables are listed using a TOC that can be read from the copter. A logging block can then be registered consisting of there variables and the data will be sent periodically via CRTP to a receiver.

Port Channel Function
5 0 Table of content access
5 1 Log settings access
5 2 Log data access

Table of content access

This port is used to access the loggable variables table of content. The first byte of the message is a message ID, three messages ID are defined:

Messages
+---+---+---+---+---+---+---+---+
| R |     Port      |  Channel  |
+---+---+---+---+---+---+---+---+
|         Packet length         |
+---+---+---+---+---+---+---+---+
|            DATA 0             |
+---+---+---+---+---+---+---+---+
:   :   :   :   :   :   :   :   :
+---+---+---+---+---+---+---+---+
|            DATA 30            |
+---+---+---+---+---+---+---+---+
Usage

Example of checking the CRC of a TOC to determine if the TOC needs to be refreshed.

   Computer                 Crazyflie
   --------                 ---------
Get TOC CRC32      --->
                   <---     TOC CRC32
[Compare CRC]                   

Example of downloading TOC contents from Crazyflie.

   Computer                 Crazyflie
   --------                 ---------
Reset TOC pointer  --->  [Pointer resets]
Get next element   --->
                   <--- TOC element
                   ....
                   ....
Get next element   --->
                   <--- TOC element
Get next element   --->
                   <--- Last TOC element
[Fetch complete]                   
Message ID Meaning in upstream packets Meaning in downstream packets
0 Reset TOC pointer Last TOC element
1 Get next TOC element TOC element
3 Get TOC CRC32 TOC CRC32

The upstream ID are commands and are sent alone. The downstream have the following formats:

Bytes     1       1          1    Null terminated strings
        +---+------------+------+----------+--------------+
        | 0 |            |      |          |              |
        +---+   Var ID   | Type |  Group   |     Name     |
        | 1 |            |      |          |              |
        +---+------------+------+---+------+--------------+
        | 3 | Num. Vars  |  CRC32   |
        +---+------------+----------+
Bytes     1       1           4

The logging variables are sequentially requested by the receiver until the end. When the last loggable variable is reached it has the ID 0 'Last TOC element'. The reset command permits to reset the TOC pointers so that the next sent TOC element will be the first one. The Get CRC commands also returns the number of loggable variables.

The CRC32 is a hash of the copter's loggable variable TOC. The aim of having this is to be able to cache data on the receiver end and to quickly check the validity of it when connecting.

Block access

TODO

Logging data

TODO

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:

Port Function
(0,9,0) TOC access
(0,9,1) Parameter read
(0,9,2) Parameter write

TOC access

This ports permits to access the parameters table of content. The first byte of the message is a message ID, three messages ID are defined:

Message ID Meaning in upstream packets Meaning in downstream packets
0 Reset TOC pointer Last TOC element
1 Get next TOC element TOC element
3 Get TOC CRC32 TOC CRC32

The upstream ID are commands and are sent alone. The downstream have the following formats:

Bytes     1       1          1    Null terminated strings
        +---+------------+------+----------+--------------+
        | 0 |            |      |          |              |
        +---+  Param ID  | Type |  Group   |     Name     |
        | 1 |            |      |          |              |
        +---+------------+------+---+------+--------------+
        | 3 | Num. Param |  CRC32   |
        +---+------------+----------+
Bytes     1       1           4

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 reset command permits to reset the TOC pointers so that the next sent TOC element will be the first one. The Get CRC commands also returns the number of parameters.

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.

Parameter read

TODO

Parameter write

TODO

Fight control

TODO

projects/crazyflie/firmware/comm_protocol.1344362636.txt.gz · Last modified: 2015-07-15 16:30 (external edit)