|
| 1 | +# Shassis Controller Communication Protocol |
| 2 | + |
| 3 | +## 1. Overview |
| 4 | +This protocol is designed for communication between a ROS2 system running on platforms such as RPI and a chassis controller operating on hardware like BeagleBone Blue or STM32. It supports both TCP and UART, allowing for a seamless future transition between the two communication methods. |
| 5 | + |
| 6 | +## 2. Protocol Architecture |
| 7 | +The protocol consists of two layers: |
| 8 | +1. **Frame Layer (Layer 1)** – Ensures data integrity, required only for UART. |
| 9 | +2. **Protocol Layer (Layer 2)** – Defines the core communication commands. |
| 10 | + |
| 11 | +### 2.1. Frame Layer (Layer 1) – UART Only |
| 12 | +**(Not used in TCP mode)** |
| 13 | +The frame layer is **only applicable when using UART**, as UART does not guarantee message integrity or completeness. |
| 14 | + |
| 15 | +**Frame Format (UART Only)** |
| 16 | +| Offset | Size (bytes) | Field | Description | |
| 17 | +|--------|-------------|---------------|-------------| |
| 18 | +| 0 | 1 | `frame_length` | Total packet length (including CRC16). Ensures packet boundary detection over UART | |
| 19 | +| 1 | N | `payload` | Protocol Layer (Layer 2) data | |
| 20 | +| N+1 | 2 | `crc16` | CRC16 checksum. Provides error detection for unreliable UART communication | |
| 21 | + |
| 22 | +### 2.2 Protocol Layer (Layer 2) – Used in TCP & UART |
| 23 | +This is the core protocol used in both TCP and UART modes. |
| 24 | + |
| 25 | +**Protocol Format** |
| 26 | +| Offset | Size (bytes) | Field | Description | |
| 27 | +|--------|-------------|---------------|-------------| |
| 28 | +| 0 | 1 | `command_id` | Unique command identifier | |
| 29 | +| 1 | 1 | `payload_size` | Number of bytes in the payload | |
| 30 | +| 2 | N | `payload` | Command-specific data | |
| 31 | + |
| 32 | +## 3. Command Set |
| 33 | +| Command ID | Command Name | Description | |
| 34 | +|------------|-------------------|----------------------| |
| 35 | +| `0x01` | [`get_api_version`](#51-0x01_get_api_version) | Retrieves the API version of the system | |
| 36 | +| `0x02` | [`set_motor_speed`](#52-set_motor_speed) | Sets the speed of a motor | |
| 37 | +| `0x03` | [`set_all_motors_speed`](#53-set_all_motors_speed) | Sets the speed for all four motors in a single command | |
| 38 | +| `0x04` | [`get_encoder`](#54-get_encoder) | Retrieves the encoder value for a specific motor | |
| 39 | +| `0x05` | [`get_all_encoders`](#55-get_all_encoders) | Retrieves the encoder values for all motors | |
| 40 | + |
| 41 | +### get_api_version (0x01) |
| 42 | +Retrieves the firmware/API version. |
| 43 | + |
| 44 | +**Request** |
| 45 | +| Offset | Size (bytes) | Field Description | Values | |
| 46 | +|--------|-------------|------------------|--------| |
| 47 | +| 0 | 1 | command_id | 0x01 | |
| 48 | +| 1 | 1 | ROS2 Driver Version | 1-255 | |
| 49 | + |
| 50 | +**Response** |
| 51 | +| Offset | Size (bytes) | Field Description | Values | |
| 52 | +|--------|-------------|------------------|--------| |
| 53 | +| 0 | 1 | command_id | 0x01 | |
| 54 | +| 1 | 1 | API Version | 1-255 | |
| 55 | + |
| 56 | +### set_motor_speed (0x02) |
| 57 | +Sets the speed of a specific motor. |
| 58 | + |
| 59 | +**Request** |
| 60 | +| Offset | Size (bytes) | Field Description | Values | |
| 61 | +|--------|-------------|------------------|--------| |
| 62 | +| 0 | 1 | command_id | 0x02 | |
| 63 | +| 1 | 1 | motor_id | Motor ID (0-3) | |
| 64 | +| 2 | 4 | speed | Speed in RPM multiplied by 100 | |
| 65 | + |
| 66 | +**Response** |
| 67 | +| Offset | Size (bytes) | Field Description | Values | |
| 68 | +|--------|-------------|------------------|--------| |
| 69 | +| 0 | 1 | command_id | 0x02 | |
| 70 | +| 1 | 1 | Status Code | 0 for OK, non-zero for error (error codes defined later) | |
| 71 | + |
| 72 | +### set_all_motors_speed (0x03) |
| 73 | +Sets the speed for all four motors in a single command. |
| 74 | + |
| 75 | +**Request** |
| 76 | +| Offset | Size (bytes) | Field Description | Values | |
| 77 | +|--------|--------------|-------------------|--------| |
| 78 | +| 0 | 1 | command_id | 0x03 | |
| 79 | +| 1 | 4 | speed_motor_0 | Speed in RPM multiplied by 100 | |
| 80 | +| 5 | 4 | speed_motor_1 | Speed in RPM multiplied by 100 | |
| 81 | +| 9 | 4 | speed_motor_2 | Speed in RPM multiplied by 100 | |
| 82 | +| 13 | 4 | speed_motor_3 | Speed in RPM multiplied by 100 | |
| 83 | + |
| 84 | +**Response** |
| 85 | +| Offset | Size (bytes) | Field Description | Values | |
| 86 | +|--------|-------------|------------------|--------| |
| 87 | +| 0 | 1 | command_id | 0x03 | |
| 88 | +| 1 | 1 | Status Code | 0 for OK, non-zero for error (error codes defined later) | |
| 89 | + |
| 90 | +### get_encoder (0x04) |
| 91 | +Retrieves the encoder value for a specific motor. |
| 92 | + |
| 93 | +**Request** |
| 94 | +| Offset | Size (bytes) | Field Description | Values | |
| 95 | +|--------|-------------|------------------|--------| |
| 96 | +| 0 | 1 | command_id | 0x04 | |
| 97 | +| 1 | 1 | motor_id | Motor ID (0-3) | |
| 98 | + |
| 99 | +**Response** |
| 100 | +| Offset | Size (bytes) | Field Description | Values | |
| 101 | +|--------|--------------|-------------------|--------| |
| 102 | +| 0 | 1 | command_id | 0x04 | |
| 103 | +| 1 | 4 | encoder_value | Encoder value for the specified motor | |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +### get_all_encoders (0x05) |
| 108 | +Retrieves the encoder values for all motors. |
| 109 | + |
| 110 | +**Request** |
| 111 | +| Offset | Size (bytes) | Field Description | Values | |
| 112 | +|--------|--------------|-------------------|--------| |
| 113 | +| 0 | 1 | command_id | 0x05 | |
| 114 | + |
| 115 | +**Response** |
| 116 | +| Offset | Size (bytes) | Field Description | Values | |
| 117 | +|--------|--------------|-------------------|--------| |
| 118 | +| 0 | 1 | command_id | 0x05 | |
| 119 | +| 1 | 4 | encoder_motor_0 | Encoder value for motor 0 | |
| 120 | +| 5 | 4 | encoder_motor_1 | Encoder value for motor 1 | |
| 121 | +| 9 | 4 | encoder_motor_2 | Encoder value for motor 2 | |
| 122 | +| 13 | 4 | encoder_motor_3 | Encoder value for motor 3 | |
| 123 | + |
0 commit comments