User Tools

Site Tools


projects:crazyflie:firmware:comm_protocol

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
projects:crazyflie:firmware:comm_protocol [2012-08-13 22:28]
macke
projects:crazyflie:firmware:comm_protocol [2013-08-23 19:54]
ledvinap
Line 1: Line 1:
 ====== Overview ====== ====== Overview ======
-===== CRTP ===== +CRTP is the protocol used to communicate with Crazyflie. Is originally stands for //Crazy RealTime Protocol//. The protocol permits to communicate independently with the copter subsystem and would have the capability to handle packet priorities. 
-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: + 
-  * [[comm_protocol#serial_port | UART]] +CRTP is implemented in 3 layers: 
-  [[comm_protocol#usb_port | USB]] + 
-  [[comm_protocol#2.4_GHz_NordicSemi_Radio | 2.4 GHz NordicSemi Radio]] +<ditaa> 
-  * ...+ +-----------------------+ 
 +   Application/ports   | 
 + +-----------------------+ 
 + | CRTP packets handling | 
 + +-----------------------+   
 +       CRTP Link       | 
 + +-----------------------+ 
 +</ditaa> 
 + 
 +  * **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/ports** represents the subsystems that sends and receives messages. 
 + 
 +Implemented link drivers: 
 +^ **Link**                                                                                       ^ 
 +[[comm_protocol#serial_port | UART]]               | Uart link, mainly used in early development | 
 +[[comm_protocol#usb_port | USB]]                   | To be implemented USB link. (Crazyflie USB port) | 
 +[[comm_protocol#2.4_GHz_NordicSemi_Radio | radio]] | 2.4 GHz NordicSemi Radio link (any nRF24L01 compatible radio, eg. Crazyradio dongle) | 
 + 
 +Current port allocation: 
 + **Port**  ^   **Target**    **Used for**   ^ 
 +|          |   [[projects:crazyflie:firmware:console | Console ]]      | Read console text that is printed to the console on the Crazyflie using consoleprintf | 
 +|          |   [[projects:crazyflie:firmware:param | Parameters]]   | Get/set parameters from the CrazyflieParameters are defined using a macro in the Crazyflie source-code | 
 +|          |   [[projects:crazyflie:crtp:commander |Commander]]    | Sending control set-points for the roll/pitch/yaw/thrust regulators | 
 +|          |   [[projects:crazyflie:firmware:log#communication_protocol|Log]]    | Set up log blocks with variables that will be sent back to the Crazyflie at a specified periodLog variables are defined using a macro in the Crazyflie source-code | 
 +|   14         [[projects:crazyflie:pc_utils:debugdriver|Client-side debugging]]    | Debugging the UI and exists only in the Crazyflie Python API and not in the Crazyflie itself | 
 +|   15         [[projects:crazyflie:firmware:linklayer |Link layer ]]   | Used to control and query the communication link |
  
 ====== Communication ====== ====== Communication ======
Line 13: Line 39:
   7               0   7               0
 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
-| R |     Port      |  Channel  |+|     Port      |  Res. | Chan. 
 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
 |            DATA 0             | |            DATA 0             |
Line 21: Line 47:
 |            DATA 30            | |            DATA 30            |
 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
- 
-+--------+--------+--------+--------+--------+--....--+--------+ 
-|  0xAA  |  0xAA  | Header | Length | Data0  | Packet | CRC32  | 
-+--------+--------+--------+--------+--------+--....--+--------+ 
  
 </code> </code>
 ^ **Field** ^ **Byte** ^ **Bit** ^   **Description**      ^ ^ **Field** ^ **Byte** ^ **Bit** ^   **Description**      ^
-|   Header  |        |   0-  | The destination channel +|   Header  |        |   0-  | The destination channel 
-|    :::    |        |   3-  | The destination port  | +|    :::    |        |   2-  | Reserved for transport layer  | 
-|    :::    |        |       Resend flag. If R=1 the last packet needs to be resent  |+|    :::    |        |   4-  The destination port  |
 |    Data      1-31  |         | The data in the packet | |    Data      1-31  |         | The data in the packet |
  
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 (header and data).
  
 ==== 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:
 +
 <code> <code>
   7               0   7               0
Line 52: Line 76:
 |             0xAA              | |             0xAA              |
 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
-R |     Port      |  Channel  |+|      Port     |  Res  | Chan. |
 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
 |         Packet length         | |         Packet length         |
Line 62: Line 86:
 |            DATA 30            | |            DATA 30            |
 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
-             CRC              |+           Cksum              |
 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
  
 +--------+--------+--------+--------+--------+--....--+--------+ +--------+--------+--------+--------+--------+--....--+--------+
-|  0xAA  |  0xAA  | Header | Length | Data0  | Packet | CRC32  |+|  0xAA  |  0xAA  | Header | Length | Data0  | Packet | Cksum  |
 +--------+--------+--------+--------+--------+--....--+--------+ +--------+--------+--------+--------+--------+--....--+--------+
  
Line 72: Line 96:
 ^ **Field** ^ **Byte** ^ **Bit** ^     **Description**     ^ ^ **Field** ^ **Byte** ^ **Bit** ^     **Description**     ^
 |   Start      0-1     0-2   | Start token for synchronization (0xAAAA)  | |   Start      0-1     0-2   | Start token for synchronization (0xAAAA)  |
-|   Header  |        |   0-  | The destination channel +|   Header  |        |   0-  | The destination channel 
-|    :::    |        |   3-  | The destination port  +|    :::    |        |   2-  | Reserved for the link layer 
-|    :::    |        |       Resend flag. If R=1 the last packet needs to be resent  | +|    :::    |        |   4-  The destination port  | 
-|    Size          |         The size of the packet +|    Size          |         Number of data byte 
-|    Data      4-34          | The data in the packet | +|    Data      4-..          | The data in the packet | 
-   CRC      35-36          The CRC16 of the packet |+  Cksum    4+size          Checksum. Sum of all the bytes, excluding //Start//, modulo 256. |
  
-===== Ports ===== +=== Examples === 
-The following ports are used during the communication. +To send setpoints to the [[projects:crazyflie:crtp:commander|commander]] send:  
-^                 **Port**                  ^   **Target**   ^ +<code> 
-|   [[comm_protocol#console|0]]             |   Console      | +0xaa 0xaa 0x30 0x0e 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3e 
-|   [[comm_protocol#logging|5]]               Logging      | +</code>
-|   [[comm_protocol#parameters|9]]          |   Parameters   | +
-|   [[comm_protocol#flight_control|13]]     | Flight control | +
-|   [[comm_protocol#link_layer|15]]           Link layer   | +
- +
-==== 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:
 <code> <code>
-  7               0 + ->   0xaa 0xaa 0xf0 0x01 0x01 0xf2     # Sent to the copter  
-+---+---+---+---+---+---+---+---+ + <-   0xaa 0xaa 0xf0 0x01 0x01 0xf2     # Received from the copter
-|             CHAR 0            | +
-+---+---+---+---+---+---+---+---+ +
-  :   :   :   :   :   :   :   : +
-+---+---+---+---+---+---+---+---+ +
-|             CHAR 30           | +
-+---+---+---+---+---+---+---+---+ +
- +
-+--------+--------+--------+--------+--------+--....--+--------+ +
-|  0xAA  |  0xAA  | Header | Length | Data0  |        | Data30 | +
-+--------+--------+--------+--------+--------+--....--+--------+ +
 </code> </code>
- +===== 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 "newline" character has to be send (\n and/or \r) +
-  * A flush command as been issued+
  
 ==== Logging ==== ==== Logging ====
Line 131: Line 135:
  
 The following messages are sent from the Client to the Crazyflie: The following messages are sent from the Client to the Crazyflie:
-^  **Command byte**  ^  **Description** +^  **Request for**  ^  **Byte**  ^  **Description** 
-                 Resets the TOC index pointer in the Crazyflie  | +TOC item  |          0x00 to identify the command  | 
-                 Request the next item in the TOC               +  :::    |          The index of the TOC item to request 
-        3          | Request the CRC32 of the TOC |+ TOC CRC and count    | 0x01 Request the TOC CRC and item count |
  
 The following messages are sent from the Crazyflie to the Client: The following messages are sent from the Crazyflie to the Client:
-^  **Command byte**  ^  **Byte**  ^  **Description** +^  **Reply for**  ^  **Byte**  ^  **Description** 
-      0 or 1       |          | The two command bytes has the same format but the command byte 0 indicates that it is the last item in the TOC  +    TOC item       |          | 0x00 to identify the command | 
-|        :::                  | Variable ID  | +|        :::                  | The ID of the next variable to fetch. If ID == 0xFF no more items are available. | 
-|        :::                  | Type (ref to variable type?+|        :::                  | Variable ID  | 
-|        :::            3-n     | Null terminated string containing group name  |+|        :::                  | Type (ref to variable type?
 +|        :::            4-n     | Null terminated string containing group name  |
 |        :::            n-m     | Null terminated string containing variable name  | |        :::            n-m     | Null terminated string containing variable name  |
-        3          |          | The TOC CRC32 command byte  |+TOC CRC and count  |          | 0x01 to identify the command  |
 |        :::                  | Number of total variables in TOC  | |        :::                  | Number of total variables in TOC  |
-|        :::            2-5     | CRC32 value of the TOC (of what exacly? group/names?)  | +|        :::            2-5     | CRC32 value of the TOC (calculated from raw contents of log TOC section)  |
- +
-<code> +
-Bytes                    1    Null terminated strings +
-        +---+------------+------+----------+--------------+ +
-        | 0 |            |      |          |              | +
-        +---+   Var ID   | Type |  Group       Name     | +
-        | 1 |            |      |          |              | +
-        +---+------------+------+---+------+--------------+ +
-        | 3 | Num. Vars  |  CRC32   | +
-        +---+------------+----------+ +
-Bytes                     4 +
-</code>+
  
 == Usage == == Usage ==
Line 173: Line 166:
    Computer                 Crazyflie    Computer                 Crazyflie
    --------                 ---------    --------                 ---------
-Reset TOC pointer  --->  [Pointer resets] +Request for TOC item --->   
-Get next element   ---> +with ID omitted 
-                   <--- TOC element +                     <---  First TOC element (including ID of next element
-                   .... +Request for TOC item ---> 
-                   .... +                     <--- Requested TOC element (including ID of next element) 
-Get next element   ---> +                     .... 
-                   <--- TOC element +                     .... 
-Get next element   ---> +Request for TOC item ---> 
-                   <--- Last TOC element+                     <--- Requested TOC element (no more items, return next index 0xFF)
 [Fetch complete]                    [Fetch complete]                   
 </code> </code>
Line 189: Line 182:
 == 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**  ^  **Description** +^  **Request for**  ^  **Byte**  ^  **Description** 
-        0          |          | Add a logging block  |+ Adding a new log  |          | 0x00 for identifying the command to add a logging block  |
 |        :::                  | Desired block id  | |        :::                  | Desired block id  |
 |        :::                  | Period in 10th of ms | |        :::                  | Period in 10th of ms |
 |        :::            3-31    | [[comm_protocol#variable_format|Variables to log]]  | |        :::            3-31    | [[comm_protocol#variable_format|Variables to log]]  |
-        1          |          | Append logging variables to an existing block  |+ Append to log     |          | 0x01 for identifying the command to append logging variables to an existing block  |
 |        :::                  | Block ID | |        :::                  | Block ID |
 |        :::            2-31    | [[comm_protocol#variable_format|Variables to log]]  | |        :::            2-31    | [[comm_protocol#variable_format|Variables to log]]  |
-        2          |          | Delete an existing block  |+ Delete a log      |          | 0x02 to identify the command for delete an existing block  |
 |        :::                  | Block ID | |        :::                  | Block ID |
-        3          |          | Enable logging data from an existing block  |+ Enable a log      |          | 0x03 to identify the command for enabling logging data from an existing block  |
 |        :::                  | Block ID | |        :::                  | Block ID |
-        4          |          | Disable logging data from an existing block  |+ Disable a log     |          | 0x04 to identify the command for disablling logging data from an existing block  |
 |        :::                  | Block ID | |        :::                  | Block ID |
  
Line 348: Line 341:
 **TODO** **TODO**
  
-=== Link layter ===+=== Link layer ===
 | 3:15:                                   | Echo (profiling)  | | 3:15:                                   | Echo (profiling)  |
 | 3:15:                                   | Source (profiling)| | 3:15:                                   | Source (profiling)|
 | 3:15:                                   | Sink (profiling)  | | 3:15:                                   | Sink (profiling)  |
 | 3:15:                                   | NULL packet       | | 3:15:                                   | NULL packet       |
projects/crazyflie/firmware/comm_protocol.txt · Last modified: 2021-06-24 16:49 by kimberly