4d1702b577
- Rewrite DM motor driver based on DM_6220 reference protocol (MIT/PosVel/Velocity modes) - Use velocity control mode: MCU runs angle PID with IMU feedback, motor handles speed loop - Rewrite vision protocol with 3 frame types (0xA5 auto data, 0xA6 manual data, 0xA7 command) - Decouple serial parsing (opencv module) from mode switching (robot_cmd module) - Implement dual-loop architecture: vision PID outer loop → angle ref → motor PID inner loop - Add KF/PID reset on mode switch transitions - Merge motor_reverse_flag and feedback_reverse_flag into single output_reverse flag - Remove DMMotorEnable/DMMotorStop (motor always runs, controlled by angle ref) - Remove unused modules: DJI/LK/HT/step/servo motors, chassis, shoot, referee - Add ExitRun0Mode() for STM32H723 power supply configuration - Clean up CMakeLists: 115 → 76 C source files
76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
#ifndef OPENCV_H
|
|
#define OPENCV_H
|
|
|
|
#include "bsp_usart.h"
|
|
#include "bsp_dwt.h"
|
|
#include "bsp_log.h"
|
|
#include "usart.h"
|
|
#include "daemon.h"
|
|
#include <string.h>
|
|
|
|
/*
|
|
* 上位机串口协议 — 三种帧类型, 通过帧头区分
|
|
*
|
|
* ---- 自动/视觉追踪数据帧 0xA5 (10 字节) ----
|
|
* [SOF:0xA5][error_x:4][error_y:4][checksum:1]
|
|
* error_x/y: float, 归一化误差, 视觉PID外环反馈值
|
|
*
|
|
* ---- 手动控制数据帧 0xA6 (11 字节) ----
|
|
* [SOF:0xA6][zero_force:1][yaw_ref:4][pitch_ref:4][checksum:1]
|
|
* zero_force: 0=正常角度控制, 1=零力/保持当前位置
|
|
* yaw_ref/pitch_ref: float, 角度参考值 (degrees)
|
|
*
|
|
* ---- 命令帧 0xA7 (3 字节) ----
|
|
* [SOF:0xA7][cmd:1][checksum:1]
|
|
* cmd: 0x01=切换到自动模式, 0x02=切换到手动模式, 0x03=激光开, 0x04=激光关
|
|
*
|
|
* checksum: 帧头到数据末尾前一字节累加和取低8位
|
|
*/
|
|
|
|
#define VISION_SOF_AUTO 0xA5
|
|
#define VISION_SOF_MANUAL 0xA6
|
|
#define VISION_SOF_CMD 0xA7
|
|
|
|
#define VISION_AUTO_LEN 10
|
|
#define VISION_MANUAL_LEN 11
|
|
#define VISION_CMD_LEN 3
|
|
|
|
/* 命令码 */
|
|
#define VISION_CMD_SWITCH_AUTO 0x01
|
|
#define VISION_CMD_SWITCH_MANUAL 0x02
|
|
#define VISION_CMD_LASER_ON 0x03
|
|
#define VISION_CMD_LASER_OFF 0x04
|
|
|
|
/* 工作模式 */
|
|
typedef enum
|
|
{
|
|
VISION_MODE_AUTO = 0, // 自动/视觉追踪
|
|
VISION_MODE_MANUAL = 1, // 手动
|
|
} Vision_Mode_e;
|
|
|
|
typedef struct
|
|
{
|
|
/* 自动模式数据 */
|
|
float error_x;
|
|
float error_y;
|
|
uint8_t auto_updated; // 收到新的自动数据帧标志
|
|
|
|
/* 手动模式数据 */
|
|
uint8_t zero_force;
|
|
float yaw_ref;
|
|
float pitch_ref;
|
|
uint8_t manual_updated; // 收到新的手动数据帧标志
|
|
|
|
/* 命令 */
|
|
uint8_t cmd; // 最新命令码
|
|
uint8_t cmd_pending; // 有待处理命令标志
|
|
|
|
float frequency; // 接收频率 (Hz)
|
|
} VisionData_t;
|
|
|
|
extern VisionData_t vision_data;
|
|
|
|
void Vision_Uart_Init(UART_HandleTypeDef *_handle);
|
|
|
|
#endif // OPENCV_H
|