Skip to content

Commit 5e927ba

Browse files
committed
[ECU] Switch from TCP to serial interface
1 parent 7892a65 commit 5e927ba

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed

docs/platform/ecu/protocol.md

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
# Shassis Controller Communication Protocol
22

33
## 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.
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 uses UART for communication.
55

66
## 2. Protocol Architecture
77
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.
8+
1. **Data Link Layer** – Ensures data integrity.
9+
2. **Application Layer** – Defines the core communication commands.
1010

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.
11+
### 2.1. Data Link Layer
12+
The Data Link Layer ensures message integrity and completeness.
1413

15-
**Frame Format (UART Only)**
14+
**Frame Format**
1615
| Offset | Size (bytes) | Field | Description |
1716
|--------|-------------|---------------|-------------|
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 |
17+
| 0 | 1 | `frame_length` | Total packet length including CRC16. |
18+
| 1 | N | `payload` | Application Layer (Layer 2) data. |
19+
| N+1 | 2 | `crc16` | CRC16 checksum (Modbus polynomial: 0x8005). |
2120

22-
### 2.2 Protocol Layer (Layer 2) – Used in TCP & UART
23-
This is the core protocol used in both TCP and UART modes.
21+
### 2.2 Application Layer
22+
This layer defines the structure of the commands and responses.
2423

2524
**Protocol Format**
2625
| Offset | Size (bytes) | Field | Description |
@@ -36,7 +35,7 @@ This is the core protocol used in both TCP and UART modes.
3635
| `0x03` | [`set_all_motors_speed`](#set_all_motors_speed-0x03) | Sets the speed for all four motors in a single command |
3736
| `0x04` | [`get_encoder`](#get_encoder-0x04) | Retrieves the encoder value for a specific motor |
3837
| `0x05` | [`get_all_encoders`](#get_all_encoders-0x05) | Retrieves the encoder values for all motors |
39-
| `0x06` | [`connect_udp`](#connect_udp-0x06) | Connects to UDP port and starts sending odometry data |
38+
| `0x06` | [`get_imu`](#get_imu-0x06) | Retrieves IMU data (accelerometer, gyroscope, quaternion, magnetometer) |
4039

4140
### get_api_version (0x01)
4241
Retrieves the firmware/API version.
@@ -67,6 +66,7 @@ Sets the speed of a specific motor.
6766
| Offset | Size (bytes) | Field Description | Values |
6867
|--------|-------------|------------------|--------|
6968
| 0 | 1 | command_id | 0x02 |
69+
| 1 | 1 | status | 0 = OK, 1 = Error |
7070

7171
### set_all_motors_speed (0x03)
7272
Sets the speed for all four motors in a single command.
@@ -84,6 +84,7 @@ Sets the speed for all four motors in a single command.
8484
| Offset | Size (bytes) | Field Description | Values |
8585
|--------|-------------|------------------|--------|
8686
| 0 | 1 | command_id | 0x03 |
87+
| 1 | 1 | status | 0 = OK, 1 = Error |
8788

8889
### get_encoder (0x04)
8990
Retrieves the encoder value for a specific motor.
@@ -117,37 +118,28 @@ Retrieves the encoder values for all motors.
117118
| 9 | 4 | encoder_value_motor_3 | Encoder value (signed value, negative value means reverse direction) |
118119
| 13 | 4 | encoder_value_motor_4 | Encoder value (signed value, negative value means reverse direction) |
119120

120-
### connect_udp (0x06)
121-
Connects to a UDP port and starts sending odometry/IMU data. The ECU will send UDP packets to the client's IP address and the specified port.
121+
### get_imu (0x06)
122122

123123
**Request**
124124
| Offset | Size (bytes) | Field Description | Values |
125-
|--------|-------------|------------------|--------|
126-
| 0 | 1 | command_id | 0x06 |
127-
| 1 | 4 | port | UDP port number for odometry data transmission |
125+
|--------|--------------|-------------------|--------|
126+
| 0 | 1 | command_id | 0x06 |
128127

129128
**Response**
130-
| Offset | Size (bytes) | Field Description | Values |
131-
|--------|-------------|------------------|--------|
132-
| 0 | 1 | command_id | 0x06 |
133-
| 1 | 1 | status | 1 = OK, 0 = Error |
134-
135-
## 4. UDP Data Format
136-
When connected via UDP (after sending `connect_udp` command), the ECU sends IMU/odometry data packets to the client's IP address and specified port.
137-
138-
**UDP Packet Format**
139129
| Offset | Size (bytes) | Field Description | Values/Format |
140-
|--------|-------------|------------------|---------------|
141-
| 0 | 1 | imu_id | IMU sensor ID (uint8_t) |
142-
| 1 | 2 | packet_number | Packet sequence number (uint16_t, big-endian) |
143-
| 3 | 4 | accel_x | Accelerometer X-axis (float, big-endian) |
144-
| 7 | 4 | accel_y | Accelerometer Y-axis (float, big-endian) |
145-
| 11 | 4 | accel_z | Accelerometer Z-axis (float, big-endian) |
146-
| 15 | 4 | gyro_x | Gyroscope X-axis (float, big-endian) |
147-
| 19 | 4 | gyro_y | Gyroscope Y-axis (float, big-endian) |
148-
| 23 | 4 | gyro_z | Gyroscope Z-axis (float, big-endian) |
149-
| 27 | 4 | quat_w | Quaternion W component (float, big-endian) |
150-
| 31 | 4 | quat_x | Quaternion X component (float, big-endian) |
151-
| 35 | 4 | quat_y | Quaternion Y component (float, big-endian) |
152-
| 39 | 4 | quat_z | Quaternion Z component (float, big-endian) |
130+
|--------|-------------|--------------------|---------------|
131+
| 0 | 1 | command_id | 0x06 |
132+
| 1 | 4 | accel_x | Accelerometer X-axis (float, little-endian) |
133+
| 5 | 4 | accel_y | Accelerometer Y-axis (float, little-endian) |
134+
| 9 | 4 | accel_z | Accelerometer Z-axis (float, little-endian) |
135+
| 13 | 4 | gyro_x | Gyroscope X-axis (float, little-endian) |
136+
| 17 | 4 | gyro_y | Gyroscope Y-axis (float, little-endian) |
137+
| 21 | 4 | gyro_z | Gyroscope Z-axis (float, little-endian) |
138+
| 25 | 4 | mag_x | Magnetometer X-axis (float, little-endian) |
139+
| 29 | 4 | mag_y | Magnetometer Y-axis (float, little-endian) |
140+
| 33 | 4 | mag_z | Magnetometer Z-axis (float, little-endian) |
141+
| 37 | 4 | quat_w | Quaternion W component (float, little-endian) |
142+
| 41 | 4 | quat_x | Quaternion X component (float, little-endian) |
143+
| 45 | 4 | quat_y | Quaternion Y component (float, little-endian) |
144+
| 49 | 4 | quat_z | Quaternion Z component (float, little-endian) |
153145

0 commit comments

Comments
 (0)