Skip to content

RoboBuggy Serial Messages (RBSM)

VivaanBahl edited this page Jan 29, 2016 · 5 revisions

Several components in the low level system need to communicate in a structured manner. This simple serial packet structure can be used to send messages both direction (surface to arduino, arduino to surface). Each message type has 4 bytes of data in a single message. Although there is no error correction (yet), there is out-of-sync detection. Data is sent periodically in both directions, but there is no connection between the 2 streams. We assume that stray characters are not send between packets, so we watch for the last footer to know where to start buffering this packet. If the footer appears in the data, we might think this is the end of a packet and start recording, but we will dump the data when there is not a footer on the end of the current packet.

Message Types

Define Name ID (base 10) Description
RBSM_MID_ENC_TICKS_LAST 0 Encoder ticks since last message.
RBSM_MID_ENC_TICKS_RESET 1 Encoder ticks since reset.
RBSM_MID_ENC_TIMESTAMP 2 Encoder timestamp since reset in milliseconds.
...
RBSM_MID_BRAKE_COMMAND 18 Brake value sent from high-level to the Mega
RBSM_MID_MEGA_COMMAND 19 Steering angle and brake state sent to the Mega. Angle is a signed 16 bit int in thousandths of a degree with center at 0 (first two bytes). Brake is a binary 1 or 0 (third byte). Fourth byte unused.
RBSM_MID_MEGA_STEER_ANGLE 20 Steering angle set to/reported from the Mega. Signed int in thousandths of a degree with center at 0.
RBSM_MID_MEGA_BRAKE_STATE 21 Brake state set to/reported from the Mega. 0 = engaged, !0 = disengaged.
RBSM_MID_MEGA_AUTON_STATE 22 Autonomous switch state. 0 = RC, !0 = Surface control.
RBSM_MID_MEGA_BATTERY_LEVEL 23 Battery level reported in mV as an unsigned 32 bit number.
RBSM_MID_MEGA_STEER_FEEDBACK 24 Steering angle feedback reported from the Mega. Signed int in thousands of a degree with center at 0.
...
LIGHTING_ID 50 ID for message to lighting system
...
RBSM_MID_RESERVED 252 Reserved as the message footer (0xFC)
RBSM_MID_ERROR 254 Error code reporting from device.
RBSM_MID_DEVICE_ID 255 Device ID to identify this connection.

Device Types

Define Name ID (base 10) Description
RBSM_DID_MEGA 0 Steering/brake/RC manager on the Arduino Mega.
RBSM_DID_DRIVE_ENCODER 1 (Drive) encoder for reporting forward speed.

Packet Structure

Byte Content Description
0 Message ID First byte send on the wire.
1 Data[3] Most significant data byte.
2 Data[2]
3 Data[1]
4 Data[0] Least significant data byte.
5 Footer Known footer byte (0x0A).

Reading State Machine

Start in the SYNC state on a new connection.

  1. SYNC - Wait to see a footer byte. Throw away any data found.
  2. READ - Buffer the next 5 bytes on the wire. These might be valid data.
  3. VERIFY - Check that the next byte is a footer byte. If it is, parse data to ID and data; go back to READ. If not this was not a valid packet; dump buffer, return to SYNC state, and record error.