Communications
This page describes the internal Serial communications packet format for Raspberry Pi and Arduino communications. The Socket Programming page describes the protocol for creating socket code for a client to interface with the Flockbot.
Serial Packets
The startup handshake is two-part. The Uno sends an ACK message to initiate. The Pi responds with a CFG packet. The Uno then responds with an ACK.
Any transmission errors result in the sending of a NAK. Upon receipt of a NAK, the receiving system will automatically resend the last packet transmitted.
Socket connected systems may send packets directly through on a retransmit message. For these messages, described in the later section on socket packets, there is no checksum. That is computed on the Pi in the retransmit process. This simplifies the client code necessary for controlling the robots.
The general framing is as follows:
Header | Length | Payload | Checksum |
Sample Packet - Move Foward 10cm/s
Header
The header/synchronization sequence uses three sequential octets consisting of 0xBD. This byte was selected because it would not naturally appear in packets.
Length
This is a single octet and represents the number of octets in the payload.
Checksum
This is a single octet and is the XOR combination of all octets in the payload and the length.
Payload
Packet Type | Command Code One | Command Code Two | Data |
The valid payloads are as follows:
Claw Functions
Function | Len: byte[0] | byte[1] | byte[2] | byte[3] | byte[4] | byte[5] | byte[6] | byte[7] |
Claw Open | 3 | D | G | O |
Claw Close | 3 | D | G | C |
Claw Set | 4 | D | G | S | <pos>(0 to 30) |
Claw Can Close | 3 | D | G | G |
Camera Functions
Function | Len: byte[0] | byte[1] | byte[2] | byte[3] | byte[4] | byte[5] | byte[6] | byte[7] |
Camera Up | 3 | D | C | U |
Camera Down | 3 | D | C | D |
Camera Set | 4 | D | C | S | <pos> (0 to 100) |
Camera Forward | 3 | D | C | F |
LCDFunctions
Function | Len: byte[0] | byte[1] | byte[2] | byte[3] | byte[4] | byte[5] | byte[6] | byte[7] |
LCD Clear | 3 | D | L | C |
Set Cursor | 5 | D | L | U | <col> 1-2 | <row> 1-16 |
Write String | 4+ | D | L | S | <\0 terminated string> |
Movement Functions
Function | byte[0] | byte[1] | byte[2] | byte[3] | byte[4] | byte[5] | byte[6] | byte[7] |
Move | 4 | D | M | S | <speed>(-100 to 100) |
Move to Distance | 5 | D | M | D | <speed>(-100 to 100) | <dist> (0 to x meters) |
Differential Wheels | 5 | D | M | W | <left speed>(-100 to 100) | <right speed> (-100 to 100) |
Rotation | 4 | D | R | C | <speed> (-100 to 100) |
Arc | 7 | D | R | A | <speed> (0 to 100) | <distance to object> (0 to 128cm) | LSB <degree> (0 to 359) | MSB <degree> (0 to 359) |
Degree Rotation | 6 | D | R | D | <speed> (-100 to 100) | LSB <degree> (0 to 359) | MSB <degree> (0 to 359) |
Stop | 3 | D | S | T |
Reset Odometer | 3 | D | M | R |
Administrative Functions
Function | byte[0] | byte[1] | byte[2] | byte[3] | byte[4] | byte[5] | byte[6] | byte[7] | byte[8] | byte[9] | byte[10] | byte[11] | byte[12] |
Configuration | 12 | C | F | G | <gripper> | LSB <l_wheel_stop> | MSB <l_wheel_stop> | LSB <r_wheel_stop> | MSB <r_wheel_stop> | <servo model> | <id> | <ip 3> | <ip 4> |
Acknowledge | 3 | A | C | K |
Non-Acknowledge | 3 | N | A | K |
Emergency | 3 | E | M | G |
Sensor Packet
Function | byte[0] | byte[1] | byte[2] | byte[3] | byte[4] | byte[5] | byte[6] | byte[7] | byte[8] | byte[9] | byte[10] | byte[11] | byte[12] | byte[13] |
Sensor | 29 | S | E | N | LSB <battery> | MSB <battery | LSB <ir0> | MSB <ir0> | LSB <ir1> | MSB <ir1> | LSB <ir2> | MSB <ir2> | LSB <ir3> | MSB <ir3> |
byte[14] | byte[15] | byte[16] | byte[17] | byte[18] | byte[19] | byte[20] | byte[21] | byte[22] | byte[23] | byte[24] | byte[25] | byte[26] | byte[27] | byte[28] | byte[29] |
LSB <ir4> | MSB <ir4> | <l_bump> | <h_bump> | LSB <left Odometer> | MSG <left Odometer> | LSB <right Odometer> | MSB <right Odometer> | LSB <avg Odometer> | MSG <avg Odometer> | LSB <left WW> | MSG <left WW> | LSB <right WW> | MSG <right WW> | 0 | 0 |