增加调试功能,以及yaw补偿

This commit is contained in:
lyf committed 2026-11-18 16:05:46 +08:00
1 parent 267a659242
commit 957c535bda
257 files changed
+239436 -692

No files matched your search

+21 -18
View File
@@ -1,8 +1,9 @@
/* =============================================================================
* chassis.c - 底盘模块:麦轮逆解 + 四轮转速 PID + 跟随云台(双 INS 世界系)
* 电机槽位(与 legacy 实际发送一致,已修正 legacy 后轮反馈交叉的 bug):
* 0x201 右前 0x202 左前 0x203 左后 0x204 右后
* 逆解(legacy Mecanum_PowerMoveControl 实际生效版本):
* 电机槽位(按实车接线):
* 0x201 右前 0x202 右后 0x203 左前 0x204 左后
* 逆解(平移方向按实车实测标定,
* 使 +vx 指向 1&3 号轮一侧、+vy 指向 3&4 号轮一侧):
* w_wheel = (vx ± vy ± w*(rx+ry)/100) / R * 18143.66
* 跟随(2026-09 二次重写):改回 Yaw GM6020(0x205) 编码器多圈相对角——
* 编码器测的是"云台相对底盘"的机械角,零漂移(此前双 INS 方案两板 yaw
@@ -22,13 +23,13 @@
#include "robot_param.h"
#include "c_comm.h"
dji_motor_t motor_wheel_rf; // 0x201 右前
dji_motor_t motor_wheel_lf; // 0x202 左前
dji_motor_t motor_wheel_lr; // 0x203 左后
dji_motor_t motor_wheel_rr; // 0x204 右后
dji_motor_t motor_wheel_rf; // 0x201 右前(实际接线)
dji_motor_t motor_wheel_lf; // 0x202 右后(实际接线,变量名沿用 legacy)
dji_motor_t motor_wheel_lr; // 0x203 左前(实际接线,变量名沿用 legacy)
dji_motor_t motor_wheel_rr; // 0x204 左后(实际接线,变量名沿用 legacy)
dji_motor_t motor_yaw_follow; // Yaw GM6020 反馈,CAN2 0x205(跟随用,相对角零漂移)
static PID_PositionTypeDef wheel_speed_pid[4]; // 顺序:RF/LF/LR/RR(槽位序)
static PID_PositionTypeDef wheel_speed_pid[4]; // 槽位序:ID1 右前 / ID2 右后 / ID3 左前 / ID4 左后
static PID_PositionTypeDef follow_pid;
/* 跟随环诊断导出(debug_task 打印) */
@@ -73,18 +74,20 @@ uint8_t chassis_motor_offline(void)
void chassis_control(float vx, float vy, float w, float power_scale)
{
/* 麦轮逆解(legacy Mecanum_PowerMoveControl 的实际生效版本)
* 换算:w_wheel = (vx±vy±w*(rx+ry)/100)/R * 18143.66 */
/* 麦轮逆解(符号按实车实测标定,勿按教科书公式直接改):
* +vx = 朝 1&3 号轮一侧(车头),+vy = 朝 3&4 号轮一侧(车左)
* 四个量按 CAN 电流帧槽位 ID1~ID4 排列:
* ID1=右前 ID2=右后 ID3=左前 ID4=左后(与 dji_motor_init 一致) */
float rear = w * (MECANUM_RX + MECANUM_RY) / 100.0f;
float rf = (vx - vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
float lf = (-vx - vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
float lr = (vx + vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
float rr = (-vx + vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
float s1 = (vx - vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
float s2 = (vx + vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
float s3 = (-vx - vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
float s4 = (-vx + vy - rear) / MECANUM_WHEEL_RADIUS * MECANUM_SPEED_FACTOR;
wheel_speed_pid[0].Need_Value = rf;
wheel_speed_pid[1].Need_Value = lf;
wheel_speed_pid[2].Need_Value = lr;
wheel_speed_pid[3].Need_Value = rr;
wheel_speed_pid[0].Need_Value = s1;
wheel_speed_pid[1].Need_Value = s2;
wheel_speed_pid[2].Need_Value = s3;
wheel_speed_pid[3].Need_Value = s4;
PID_PositionCalc(&wheel_speed_pid[0], motor_wheel_rf.fdb.rotor_speed);
PID_PositionCalc(&wheel_speed_pid[1], motor_wheel_lf.fdb.rotor_speed);
+5 -5
View File
@@ -5,13 +5,13 @@
#include "dji_motor.h"
/* 底盘模块:麦轮逆解 + 四轮转速 PID + 跟随云台(双 INS 世界系,2026-09 重写)
* 电机接线(与 legacy 实际发送一致):
* 0x201 右前 0x202 左前 0x203 左后 0x204 右后 */
* 电机实际接线:
* 0x201 右前 0x202 右后 0x203 左前 0x204 左后 */
extern dji_motor_t motor_wheel_rf; // 0x201 右前
extern dji_motor_t motor_wheel_lf; // 0x202 左前
extern dji_motor_t motor_wheel_lr; // 0x203 左后
extern dji_motor_t motor_wheel_rr; // 0x204 右后
extern dji_motor_t motor_wheel_lf; // 0x202 右后(变量名沿用 legacy)
extern dji_motor_t motor_wheel_lr; // 0x203 左前(变量名沿用 legacy)
extern dji_motor_t motor_wheel_rr; // 0x204 左后(变量名沿用 legacy)
extern dji_motor_t motor_yaw_follow; // Yaw GM6020,CAN2 0x205(跟随反馈)
extern void chassis_motor_init(void);