Files
Gimbal/modules/opencv/opencv.c
T
SkyLiCoder 4d1702b577 refactor: migrate from DJI motors to DM motors, simplify to gimbal-only control
- 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
2026-05-29 23:37:36 +08:00

76 lines
2.0 KiB
C

#include "opencv.h"
VisionData_t vision_data;
static USARTInstance *cv_usart_instance;
static DaemonInstance *vision_daemon_instance;
static uint8_t calc_checksum(uint8_t *buf, uint8_t len)
{
uint8_t sum = 0;
for (uint8_t i = 0; i < len - 1; i++)
sum += buf[i];
return sum;
}
static void DecodeVision()
{
DaemonReload(vision_daemon_instance);
static uint32_t counter;
float dt = DWT_GetDeltaT(&counter);
vision_data.frequency = 1.0f / dt;
uint8_t *buf = cv_usart_instance->recv_buff;
uint16_t len = cv_usart_instance->recv_buff_size;
uint8_t sof = buf[0];
if (sof == VISION_SOF_AUTO && len == VISION_AUTO_LEN)
{
if (calc_checksum(buf, VISION_AUTO_LEN) != buf[VISION_AUTO_LEN - 1])
return;
memcpy(&vision_data.error_x, buf + 1, 4);
memcpy(&vision_data.error_y, buf + 5, 4);
vision_data.auto_updated = 1;
}
else if (sof == VISION_SOF_MANUAL && len == VISION_MANUAL_LEN)
{
if (calc_checksum(buf, VISION_MANUAL_LEN) != buf[VISION_MANUAL_LEN - 1])
return;
vision_data.zero_force = buf[1];
memcpy(&vision_data.yaw_ref, buf + 2, 4);
memcpy(&vision_data.pitch_ref, buf + 6, 4);
vision_data.manual_updated = 1;
}
else if (sof == VISION_SOF_CMD && len == VISION_CMD_LEN)
{
if (calc_checksum(buf, VISION_CMD_LEN) != buf[VISION_CMD_LEN - 1])
return;
vision_data.cmd = buf[1];
vision_data.cmd_pending = 1;
}
}
static void VisionOfflineCallback(void *id)
{
(void)id;
USARTServiceInit(cv_usart_instance);
}
void Vision_Uart_Init(UART_HandleTypeDef *_handle)
{
USART_Init_Config_s conf = {
.module_callback = DecodeVision,
.recv_buff_size = 64,
.usart_handle = _handle,
};
cv_usart_instance = USARTRegister(&conf);
Daemon_Init_Config_s daemon_conf = {
.callback = NULL,
.owner_id = NULL,
.reload_count = 10,
};
vision_daemon_instance = DaemonRegister(&daemon_conf);
}