This page has deprecated and will be archived. Please go to [[https://www.bitcraze.io/]]. ====== Crazy RealTime Protocol ====== The protocol used to communicate with the Crazyflie is called the Crazy RealTime Protocol, or CRTP in short. It's a simple protocol mainly designed to suit the radio chip used on the Crazyflie but the protocol can also be used on other physical links. This page and it's sub-pages describe the protocol itself, not the implementation of some of the more complex functions such as logging and parameters. ===== Header ===== Each packet has a 1 byte header and can carry up to 29 bytes data payload. The header field has the following layout: 7 6 5 4 3 2 1 0 +----+----+----+----+----+----+----+----+ | Port | Link | Chan. | +----+----+----+----+----+----+----+----+ Where: * **Port**: Used to identify the functionality or task that is associated with this message * **Link**: Reserved for future use * **Channel**: Used to identify the sub-task/functionality ===== Layers ===== CRTP is implemented in 3 layers: +-----------------------+ | Application/ports | +-----------------------+ | CRTP packets handling | +-----------------------+ | CRTP Link | +-----------------------+ * **CRTP Link** is responsible for transferring the packets between the Crazyflie and the host. It will typically handles packet size and error detection. * **CRTP Packet handling** delivers the packet to the right subsystem in the Crazyflie and in the host control software. * **Application/ports** represents the subsystems that sends and receives messages. ===== Port allocation ===== Current port allocation: ^ **Port** ^ **Target** ^ **Used for** ^ | 0 | [[projects:crazyflie:crtp:console | Console ]] | Read console text that is printed to the console on the Crazyflie using consoleprintf | | 2 | [[projects:crazyflie:crtp:param | Parameters]] | Get/set parameters from the Crazyflie. Parameters are defined using a [[projects:crazyflie:firmware:param|macro in the Crazyflie source-code]] | | 3 | [[projects:crazyflie:crtp:commander |Commander]] | Sending control set-points for the roll/pitch/yaw/thrust regulators | | 5 | [[projects:crazyflie:crtp:log#|Log]] | Set up log blocks with variables that will be sent back to the Crazyflie at a specified period. Log variables are defined using a [[projects:crazyflie:firmware:log|macro in the Crazyflie source-code]] | | 7 | [[projects:crazyflie:crtp:setpointgeneric | Setpoint Generic]] | For sending generic, extensible setpoints | | 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:crtp:linklayer |Link layer ]] | Used to control and query the communication link | ====== Physical layers ====== Below are details on how CRTP is implemented for different physical links. Currently only the radio link is working but there's some legacy support for the UART still in the code. ===== 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 ===== This is currently not implemented but it will potentially replace the serial port link. The use of this is to get CRTP at higher speeds than the radio can transmit. ===== Serial port ===== The serial port is configured in 115200 8N1. CRTP packets are sent and received asynchronously using the following packet format: 7 6 5 4 3 2 1 0 +---+---+---+---+---+---+---+---+ | 0xAA | +---+---+---+---+---+---+---+---+ | 0xAA | +---+---+---+---+---+---+---+---+ | Port | Res | Chan. | +---+---+---+---+---+---+---+---+ | Packet length | +---+---+---+---+---+---+---+---+ | DATA 0 | +---+---+---+---+---+---+---+---+ : : : : : : : : : +---+---+---+---+---+---+---+---+ | Cksum | +---+---+---+---+---+---+---+---+ +--------+--------+--------+--------+--------+--....--+--------+ | 0xAA | 0xAA | Header | Length | Data0 | Packet | Cksum | +--------+--------+--------+--------+--------+--....--+--------+ ^ **Field** ^ **Byte** ^ **Bit** ^ **Description** ^ | Start | 0-1 | 0-2 | Start token for synchronization (0xAAAA) | | Header | 2 | 0-1 | The destination channel | | ::: | 2 | 2-3 | Reserved for the link layer | | ::: | 2 | 4-7 | The destination port | | Size | 3 | | Number of data byte | | Data | 4-.. | | The data in the packet | | Cksum | 4+size | | Checksum. Sum of all the bytes, excluding //Start//, modulo 256. | ==== Example ==== To send setpoints to the [[projects:crazyflie:crtp:commander|commander]] send: 0xaa 0xaa 0x30 0x0e 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3e To ping Crazyflie: -> 0xaa 0xaa 0xf0 0x01 0x01 0xf2 # Sent to the copter <- 0xaa 0xaa 0xf0 0x01 0x01 0xf2 # Received from the copter