refactor: remove deprecated zero_force field from manual control frame
VISION_MANUAL_LEN 11→10, frame [SOF:0xA6][yaw_velocity:4][pitch_velocity:4][checksum:1]. Protocol comment, docs, README struct diagram all updated.
This commit is contained in:
@@ -108,7 +108,7 @@ main()
|
|||||||
| 帧头 | 长度 | 用途 |
|
| 帧头 | 长度 | 用途 |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| 0xA5 | 10 | 自动/视觉追踪数据帧 (error_x, error_y) |
|
| 0xA5 | 10 | 自动/视觉追踪数据帧 (error_x, error_y) |
|
||||||
| 0xA6 | 11 | 手动控制数据帧 (zero_force, yaw_velocity, pitch_velocity) |
|
| 0xA6 | 10 | 手动控制数据帧 (yaw_velocity, pitch_velocity) |
|
||||||
| 0xA7 | 3 | 命令帧 (模式切换, 激光) |
|
| 0xA7 | 3 | 命令帧 (模式切换, 激光) |
|
||||||
| 0xA8 | 50 | 调试调参帧 (12 个 float PID 参数) |
|
| 0xA8 | 50 | 调试调参帧 (12 个 float PID 参数) |
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ main()
|
|||||||
```
|
```
|
||||||
上位机 USART10 → DecodeVision() → vision_data (全局结构体)
|
上位机 USART10 → DecodeVision() → vision_data (全局结构体)
|
||||||
├── 0xA5 → auto_updated=1, error_x/y
|
├── 0xA5 → auto_updated=1, error_x/y
|
||||||
├── 0xA6 → manual_updated=1, zero_force, yaw/pitch velocity
|
├── 0xA6 → manual_updated=1, yaw/pitch velocity
|
||||||
├── 0xA7 → cmd_pending=1, cmd
|
├── 0xA7 → cmd_pending=1, cmd
|
||||||
└── 0xA8 → debug_updated=1, 12 个 PID 参数
|
└── 0xA8 → debug_updated=1, 12 个 PID 参数
|
||||||
|
|
||||||
@@ -323,7 +323,6 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
float error_x, error_y; // 自动模式: 归一化误差
|
float error_x, error_y; // 自动模式: 归一化误差
|
||||||
uint8_t auto_updated;
|
uint8_t auto_updated;
|
||||||
uint8_t zero_force; // 手动模式: 零力标志
|
|
||||||
float yaw_degree_velocity, pitch_degree_velocity; // 手动模式: 角速度
|
float yaw_degree_velocity, pitch_degree_velocity; // 手动模式: 角速度
|
||||||
uint8_t manual_updated;
|
uint8_t manual_updated;
|
||||||
// 调试模式数据
|
// 调试模式数据
|
||||||
|
|||||||
@@ -53,29 +53,27 @@ def send_auto_tracking(ser, error_x: float, error_y: float):
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 2. 手动控制数据帧 0xA6 (11 字节)
|
## 2. 手动控制数据帧 0xA6 (10 字节)
|
||||||
|
|
||||||
**用途**: 手动模式下发送角速度目标值。
|
**用途**: 手动模式下发送角速度目标值。
|
||||||
|
|
||||||
```
|
```
|
||||||
[SOF:0xA6][zero_force:1][yaw_velocity:4][pitch_velocity:4][checksum:1]
|
[SOF:0xA6][yaw_velocity:4][pitch_velocity:4][checksum:1]
|
||||||
```
|
```
|
||||||
|
|
||||||
| 偏移 | 长度 | 类型 | 含义 |
|
| 偏移 | 长度 | 类型 | 含义 |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| 0 | 1 | uint8 | 帧头 0xA6 |
|
| 0 | 1 | uint8 | 帧头 0xA6 |
|
||||||
| 1 | 1 | uint8 | 零力标志 (0=正常, 1=零力) |
|
| 1 | 4 | float | Yaw 角速度 (degrees/s) |
|
||||||
| 2 | 4 | float | Yaw 角速度 (degrees/s) |
|
| 5 | 4 | float | Pitch 角速度 (degrees/s) |
|
||||||
| 6 | 4 | float | Pitch 角速度 (degrees/s) |
|
| 9 | 1 | uint8 | checksum |
|
||||||
| 10 | 1 | uint8 | checksum |
|
|
||||||
|
|
||||||
**Python 写入示例**:
|
**Python 写入示例**:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def send_manual_control(ser, yaw_deg_per_s: float, pitch_deg_per_s: float, zero_force: int = 0):
|
def send_manual_control(ser, yaw_deg_per_s: float, pitch_deg_per_s: float):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
data.append(0xA6)
|
data.append(0xA6)
|
||||||
data.append(0 if zero_force else 0)
|
|
||||||
data.extend(struct.pack('<ff', yaw_deg_per_s, pitch_deg_per_s))
|
data.extend(struct.pack('<ff', yaw_deg_per_s, pitch_deg_per_s))
|
||||||
checksum = sum(data) & 0xFF
|
checksum = sum(data) & 0xFF
|
||||||
data.append(checksum)
|
data.append(checksum)
|
||||||
|
|||||||
@@ -37,9 +37,8 @@ static void DecodeVision()
|
|||||||
{
|
{
|
||||||
if (calc_checksum(buf, VISION_MANUAL_LEN) != buf[VISION_MANUAL_LEN - 1])
|
if (calc_checksum(buf, VISION_MANUAL_LEN) != buf[VISION_MANUAL_LEN - 1])
|
||||||
return;
|
return;
|
||||||
vision_data.zero_force = buf[1];
|
memcpy(&vision_data.yaw_degree_velocity, buf + 1, 4);
|
||||||
memcpy(&vision_data.yaw_degree_velocity, buf + 2, 4);
|
memcpy(&vision_data.pitch_degree_velocity, buf + 5, 4);
|
||||||
memcpy(&vision_data.pitch_degree_velocity, buf + 6, 4);
|
|
||||||
vision_data.manual_updated = 1;
|
vision_data.manual_updated = 1;
|
||||||
}
|
}
|
||||||
else if (sof == VISION_SOF_DEBUG && len == VISION_DEBUG_LEN)
|
else if (sof == VISION_SOF_DEBUG && len == VISION_DEBUG_LEN)
|
||||||
|
|||||||
@@ -15,9 +15,8 @@
|
|||||||
* [SOF:0xA5][error_x:4][error_y:4][checksum:1]
|
* [SOF:0xA5][error_x:4][error_y:4][checksum:1]
|
||||||
* error_x/y: float, 归一化误差, 视觉PID外环反馈值
|
* error_x/y: float, 归一化误差, 视觉PID外环反馈值
|
||||||
*
|
*
|
||||||
* ---- 手动控制数据帧 0xA6 (11 字节) ----
|
* ---- 手动控制数据帧 0xA6 (10 字节) ----
|
||||||
* [SOF:0xA6][zero_force:1][yaw_velocity:4][pitch_velocity:4][checksum:1]
|
* [SOF:0xA6][yaw_velocity:4][pitch_velocity:4][checksum:1]
|
||||||
* zero_force: 0=正常速度控制, 1=零力/保持当前位置
|
|
||||||
* yaw_velocity/pitch_velocity: float, 角速度 (degrees/s)
|
* yaw_velocity/pitch_velocity: float, 角速度 (degrees/s)
|
||||||
*
|
*
|
||||||
* ---- 命令帧 0xA7 (3 字节) ----
|
* ---- 命令帧 0xA7 (3 字节) ----
|
||||||
@@ -40,7 +39,7 @@
|
|||||||
#define VISION_SOF_DEBUG 0xA8
|
#define VISION_SOF_DEBUG 0xA8
|
||||||
|
|
||||||
#define VISION_AUTO_LEN 10
|
#define VISION_AUTO_LEN 10
|
||||||
#define VISION_MANUAL_LEN 11
|
#define VISION_MANUAL_LEN 10
|
||||||
#define VISION_CMD_LEN 3
|
#define VISION_CMD_LEN 3
|
||||||
#define VISION_DEBUG_LEN 50
|
#define VISION_DEBUG_LEN 50
|
||||||
|
|
||||||
@@ -67,7 +66,6 @@ typedef struct
|
|||||||
uint8_t auto_updated; // 收到新的自动数据帧标志
|
uint8_t auto_updated; // 收到新的自动数据帧标志
|
||||||
|
|
||||||
/* 手动模式数据 */
|
/* 手动模式数据 */
|
||||||
uint8_t zero_force;
|
|
||||||
float yaw_degree_velocity;
|
float yaw_degree_velocity;
|
||||||
float pitch_degree_velocity;
|
float pitch_degree_velocity;
|
||||||
uint8_t manual_updated; // 收到新的手动数据帧标志
|
uint8_t manual_updated; // 收到新的手动数据帧标志
|
||||||
|
|||||||
Reference in New Issue
Block a user