Skip to content

BT Communication Structure

Nerdboy_Q edited this page Feb 3, 2021 · 4 revisions

Brief Description of Bytes

  • A byte is usually represented in hexadecimal format, or Hex for short.
  • Hex numeral system is the base 16 representation of number values.
  • It is called base 16 as it is represented in a range of 16 Values: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Integer Hex Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
  • As opposed to binary, which is base 2, as it represented with two values: 1 or 0
  • Bytes are generally represented as a pair of 4 bit arrays with the prefix "0x" : i.e. 0xFA = 1111 1010

NOTE : 8 bits is referred to as a byte, and 4 bits is referred to as a nibble.

Project - BT Communication Structure

All messages will be 8 bytes long

Requests & Response payloads

  • "Request" will be used to refer to messages sent from the Pi
    • The status byte will just be empty in requests
  • "Response" will be used to refer to messages sent from the Arduino
    • The status byte in the response will help with error messaging:

      bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
      byte0 error byte1 error byte2 error byte4 error byte5 error byte6 error byte7 error Fail (1)/Success(0)

Full Request structure

Example : [FA,8A,00,00,00,00,00,00]

Description [byte 0] [byte 1] [byte 2] [byte 3] [byte 4] [byte 5] [byte 6] [byte 7]
sanity bt Command Dummy Dummy Dummy Dummy Dummy Reserve Status
sanity servo Command Dummy Dummy Dummy Dummy Dummy Reserve Status
sanity sensor Command Dummy Dummy Dummy Dummy Dummy Reserve Status
sanity servo/sensor Command Dummy Dummy Dummy Dummy Dummy Reserve Status
sanity PID Command Dummy Dummy Dummy Dummy Dummy Reserve Status
Run PID controller Command Constants Multiplier Balance Set point Kp Ki Kd Reserve Status

Command Byte - Sanity Check BT

  • bit7 : test type flag [1 = sanity check, 0 = regular PID run]

Sanity

  • bit5 & bit 4 : test type
bit5 bit4 sanity check
0 0 BT Echo
0 1 Servo Position
1 0 Sensor Read
1 1 Tilt & measure

Sero Position

  • bit3, bit2, bit1, bit0 : Servo Target Angle
bit3 bit2 bit1 bit0 angle
1 1 0 0 180
1 0 0 0 150
0 1 0 0 120
0 0 0 0 90
0 0 0 1 60
0 0 1 0 30
0 0 1 1 0
0 1 1 0 sweep

Tilt & Measure

  • bit3 Tile direction [1 = full left tilt, 0 = full right tilt]
  • bit2, bit1, bit0
bit3 bit2 bit1 wait time
0 0 1 5s
0 1 0 10s
1 0 0 15s

Sanity Check Command Bytes (Full)

Hex Binary Test Type Action LED Details
0x8X 1000XXXX BT Echo Blue LED on Arduino should blink Blue the last 4 bits can be anything
0x9B 10011100 Adjust Servo Servo Tilts Left Both
0x96 10010110 Adjust Servo Servo Centers Both
0x93 10010011 Adjust Servo Servo Tilts Right Both
0x99 10001001 Adjust Servo Servo should loop left tilt->center->right tilt twice Both
0xAX 1100XXXX Read Sensor Sensor reading is made Yellow the last 4 bits can be anything

PID Messages

PID Command Bytes (Full)

The upper nibble is to trigger a PID command [bits 4-7]
The lower nibble is to set the start position of the balance beam [bits 0-3]

Hex Binary Start Position Action LED Details
0x4A 01001100 full left PID Controller Starts tilted left Blue Kp, Ki, & Kd values required
0x46 01000110 centered PID Controller Starts centered Blue Kp, Ki, & Kd values required
0x43 01000011 full right PID Controller Starts tilted right Blue Kp, Ki, & Kd values required

PID Multiplier Byte (Full)

The upper nibble represents which constants to multiply by [bits 4-7]
The lower nibble represents where to move the decimal place [bits 0-3]

HEX Binary Constants to Multiply Decimal place position Example Input (pi) Expected Output (Arduino)
0x0E 00001110 Null/Default Null/Default [125,125,125] [125,125,125]
0x1E 00011110 Kd Null/Default [125,125,125] [125,125,125]
0x2D 00101101 Ki 1 to the left [125,125,125] [125,12.5,125]
0x3B 00111011 Ki & Kd 2 to the left [125,125,85] [125,1.25,0.85]
0x4E 01001110 Kp Null/Default [125,125,125] [125,125,125]
0x5E 01011110 Kp & Kd Null/Default [125,125,125] [125,125,125]
0x6E 01101110 Kp & Ki Null/Default [125,125,125] [125,125,125]
0x7E 01111110 Kp, Ki, & Kd Null/Default [125,125,125] [125,125,125]
Things to Consider:
  • Multipliers should only be set on non-zero values.
  • Default constant values should be zero.
  • Each constant will have a range of 0-255 (including the multiplier).
    • Currently all tested values are floats less than 3.00.