System API table - SergeGit/rc-tank-platform GitHub Wiki

Hull Controller API Reference

I2C Interface Specifications

  • Slave Address: 0x08
  • Communication Protocol: I2C

Command Structure

Each command consists of:

  1. Command byte (identifying the action)
  2. Data byte (parameter for the action)

Command Codes

Command Hex Value Description Data Parameter Response
CMD_TURRET_ROTATE 0x10 Controls turret rotation 0-200 (-100 to +100 speed, centered at 100) None
CMD_TURRET_ELEVATE 0x11 Controls turret elevation 0-200 (-100 to +100 speed, centered at 100) None
CMD_TRACKS_MOVE 0x20 Controls forward/backward movement 0-200 (-100 to +100 speed, centered at 100) None
CMD_TRACKS_TURN 0x21 Controls left/right turning 0-200 (-100 to +100 turn rate, centered at 100) None
CMD_LASER_TOGGLE 0x30 Controls laser targeting system 0=OFF, 1=ON None
CMD_IR_TOGGLE 0x31 Controls IR emitter 0=OFF, 1=ON None
CMD_CANNON_FIRE 0x32 Fires cannon 0-255 (max firing duration in ms) None
CMD_FRONT_LIGHTS 0x40 Controls front lights 0=OFF, 1=ON, 2=BLINKING None
CMD_REAR_LIGHTS 0x41 Controls rear lights 0=OFF, 1=ON, 2=BLINKING None
CMD_TURRET_LIGHT 0x42 Controls turret light 0=OFF, 1=ON None
CMD_GET_BATTERY 0xE0 Requests battery voltage None 2 bytes (uint16_t millivolts)
CMD_GET_POSITION 0xE1 Requests position data None 4 bytes (2x uint16_t coordinates)
CMD_GET_CANNON_STATUS 0xE2 Requests cannon ready status None 1 byte (0=not ready, 1=ready)
CMD_GET_GPS 0xE3 Requests GPS coordinates None 8 bytes (4x uint16_t GPS data)
CMD_GET_ALL_SENSORS 0xEF Requests all sensor data None 16 bytes (combined sensor data)
CMD_GET_STATUS 0xF0 Requests general status None 1 byte (status bits)

Status Byte Structure (CMD_GET_STATUS response)

Bit Description Value
0 Cannon ready 0=not ready, 1=ready
1 Laser status 0=OFF, 1=ON
2 IR emitter status 0=OFF, 1=ON
3 Front lights status 0=OFF, 1=ON or BLINKING
4 Rear lights status 0=OFF, 1=ON or BLINKING
5-7 Reserved Always 0

All Sensors Data Structure (CMD_GET_ALL_SENSORS response)

Bytes Description Type
0-1 Battery voltage uint16_t (millivolts)
2-5 Position data 2x uint16_t (x, y coordinates)
6 Cannon status uint8_t (0=not ready, 1=ready)
7 Front lights state uint8_t (0=OFF, 1=ON, 2=BLINKING)
8 Rear lights state uint8_t (0=OFF, 1=ON, 2=BLINKING)
9-15 Reserved Always 0

Examples

Moving Forward at Half Speed

Command: 0x20
Data: 150 (100 + 50 = half speed forward)

Turning Right at 30% Rate

Command: 0x21
Data: 130 (100 + 30 = 30% right turn)

Firing Cannon with 200ms Safety Timeout

Command: 0x32
Data: 200 (200ms max firing duration)
Response: None, but subsequent CMD_GET_CANNON_STATUS will return 0 until cooldown period ends

Getting Battery Voltage

Command: 0xE0
Data: None
Response: Two bytes representing millivolts (e.g., 0x70, 0x12 = 0x1270 = 4720mV = 4.72V)