Compare commits
3
Commits
59d1169895
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
267a659242 | ||
|
|
370d4519b5 | ||
|
|
67eea77789 |
+14
@@ -28,6 +28,20 @@
|
|||||||
*.uvguix
|
*.uvguix
|
||||||
DebugConfig/
|
DebugConfig/
|
||||||
|
|
||||||
|
# ---- J-Link 调试器自动生成(与具体探针/机器绑定, 非源码) ----
|
||||||
|
# JLinkSettings.ini: 点"下载/调试"时 Keil 写下的连接参数(器件/接口/速率)
|
||||||
|
# JLinkLog.txt: J-Link 驱动日志
|
||||||
|
# 两者都会随换机器、换探针、换烧录方式而变, 不应入库; 缺失时 Keil 会自动重建
|
||||||
|
JLinkSettings.ini
|
||||||
|
JLinkLog.txt
|
||||||
|
JLinkLog.txt.*
|
||||||
|
*.jlink
|
||||||
|
|
||||||
|
# ---- Keil UV4 编译/烧录日志(uv4 -b/-f -o 生成) ----
|
||||||
|
build_log.txt
|
||||||
|
*_build.txt
|
||||||
|
*_flash.txt
|
||||||
|
|
||||||
# ---- 编辑器 / 系统 ----
|
# ---- 编辑器 / 系统 ----
|
||||||
*.bak
|
*.bak
|
||||||
*.ddk
|
*.ddk
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ FreeRTOS 节拍 1 kHz。任务来自 `Core/Src/freertos.c`:
|
|||||||
|
|
||||||
| 板 | CAN1 | CAN2 |
|
| 板 | CAN1 | CAN2 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| 云台板 | Pitch GM6020 `0x206`、摩擦轮 M3508 `0x201/0x202` | Yaw GM6020 `0x205`、底盘回传 `0x019` |
|
| 云台板 | Pitch GM6020 `0x206`(0x1FE)、摩擦轮 M3508 `0x201/0x202`(0x200) | Yaw GM6020 `0x205`(0x1FE)、拨弹 M2006 `0x201`(0x200)、底盘回传 `0x019` |
|
||||||
| 底盘板 | 四轮 M3508 `0x201~0x204` | 云台数据 `0x149/0x189/0x1A9` |
|
| 底盘板 | 四轮 M3508 `0x201~0x204` | 云台数据 `0x149/0x189/0x1A9` |
|
||||||
|
|
||||||
### 6.2 串口分配
|
### 6.2 串口分配
|
||||||
|
|||||||
@@ -24,4 +24,13 @@ typedef struct
|
|||||||
|
|
||||||
extern keyboard_data_t keyboard_data;
|
extern keyboard_data_t keyboard_data;
|
||||||
|
|
||||||
|
/* ---- 键鼠来源合并视图(2026-10-16) ----
|
||||||
|
* 客户端键鼠既可能从裁判系统 0x0304 进来,也可能从 USART3 那 18 字节帧进来
|
||||||
|
* (官方 18 字节控制帧里就带鼠标与按键,由 dr16 解析成 dr16.mouse_rl / dr16.key_w 等)。
|
||||||
|
* robot_cmd_task 每周期把两路合并到下面这个视图:
|
||||||
|
* 云台/发射控制 与 c_comm_task 的底盘摇杆合成 都读它,
|
||||||
|
* 避免两处各判一次出现"云台跟鼠标、底盘却还在收遥控器原始摇杆"。 */
|
||||||
|
extern keyboard_data_t keyboard_merged; /* 合并后的键鼠数据(0x0304 优先) */
|
||||||
|
extern uint8_t keyboard_merged_online; /* 1=键鼠在控(0x0304 在线 或 帧内键鼠有动作) */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -33,28 +33,38 @@ void c_comm_task(void const * argument)
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
#if defined(ROBOT_TYPE_GIMBAL)
|
#if defined(ROBOT_TYPE_GIMBAL)
|
||||||
uint8_t kb_online = (keyboard_data.last_tick != 0 &&
|
/* 键鼠来源已由 robot_cmd_task 合并(0x0304 优先,否则 USART3 帧内键鼠)。
|
||||||
HAL_GetTick() - keyboard_data.last_tick < DEVICE_OFFLINE_TIME_MS * 10);
|
* 直接用共享视图,保证"云台怎么控、底盘就怎么收"——否则 WASD 合成的
|
||||||
|
* 底盘摇杆会因为这里只认 0x0304 而被整段跳过(客户端键鼠走帧内时平移失效)。 */
|
||||||
|
uint8_t kb_online = keyboard_merged_online;
|
||||||
uint8_t kb[12];
|
uint8_t kb[12];
|
||||||
kb[0] = (uint8_t)(keyboard_data.mouse_rl & 0xFF);
|
kb[0] = (uint8_t)(keyboard_merged.mouse_rl & 0xFF);
|
||||||
kb[1] = (uint8_t)((uint16_t)keyboard_data.mouse_rl >> 8);
|
kb[1] = (uint8_t)((uint16_t)keyboard_merged.mouse_rl >> 8);
|
||||||
kb[2] = (uint8_t)(keyboard_data.mouse_du & 0xFF);
|
kb[2] = (uint8_t)(keyboard_merged.mouse_du & 0xFF);
|
||||||
kb[3] = (uint8_t)((uint16_t)keyboard_data.mouse_du >> 8);
|
kb[3] = (uint8_t)((uint16_t)keyboard_merged.mouse_du >> 8);
|
||||||
kb[4] = (uint8_t)(keyboard_data.mouse_wheel & 0xFF);
|
kb[4] = (uint8_t)(keyboard_merged.mouse_wheel & 0xFF);
|
||||||
kb[5] = (uint8_t)((uint16_t)keyboard_data.mouse_wheel >> 8);
|
kb[5] = (uint8_t)((uint16_t)keyboard_merged.mouse_wheel >> 8);
|
||||||
kb[6] = keyboard_data.mouse_key_l;
|
kb[6] = keyboard_merged.mouse_key_l;
|
||||||
kb[7] = keyboard_data.mouse_key_r;
|
kb[7] = keyboard_merged.mouse_key_r;
|
||||||
kb[8] = (uint8_t)(keyboard_data.key_w | (keyboard_data.key_s << 1) |
|
kb[8] = (uint8_t)(keyboard_merged.key_w | (keyboard_merged.key_s << 1) |
|
||||||
(keyboard_data.key_a << 2) | (keyboard_data.key_d << 3) |
|
(keyboard_merged.key_a << 2) | (keyboard_merged.key_d << 3) |
|
||||||
(keyboard_data.key_shift << 4) | (keyboard_data.key_ctrl << 5) |
|
(keyboard_merged.key_shift << 4) | (keyboard_merged.key_ctrl << 5) |
|
||||||
(keyboard_data.key_q << 6) | (keyboard_data.key_e << 7));
|
(keyboard_merged.key_q << 6) | (keyboard_merged.key_e << 7));
|
||||||
kb[9] = (uint8_t)(keyboard_data.key_alpha1 | (keyboard_data.key_alpha2 << 1));
|
kb[9] = (uint8_t)(keyboard_merged.key_alpha1 | (keyboard_merged.key_alpha2 << 1));
|
||||||
kb[10] = 0;
|
kb[10] = 0;
|
||||||
kb[11] = 0;
|
kb[11] = 0;
|
||||||
|
|
||||||
c_comm_master_send(kb_online, kb, gimbal_motor_offline(),
|
c_comm_master_send(kb_online, kb, gimbal_motor_offline(),
|
||||||
cmd_robot.spin_flag); // 故障位+小陀螺使能位
|
cmd_robot.spin_flag); // 故障位+小陀螺使能位
|
||||||
|
|
||||||
|
/* 0x1B9 自定义UI 专用量:底盘本地没有 pitch 与摩擦轮转速,
|
||||||
|
* 由云台随板间通讯带给它(见 底盘/modules/comms/referee_ui.c)。
|
||||||
|
* pitch 取云台 pitch 环反馈 -att_deg_roll;摩擦轮转速取电机反馈 rpm。 */
|
||||||
|
c_comm_master_send_ui(-att_deg_roll,
|
||||||
|
(float)motor_friction_l.fdb.rotor_speed,
|
||||||
|
(float)motor_friction_r.fdb.rotor_speed,
|
||||||
|
cmd_robot.spin_flag);
|
||||||
|
|
||||||
/* 0x1A9 姿态帧:跟随符号自动综合的数据源
|
/* 0x1A9 姿态帧:跟随符号自动综合的数据源
|
||||||
* flags:bit0=att_ready bit1=tick增向CCW bit2=bit1有效 */
|
* flags:bit0=att_ready bit1=tick增向CCW bit2=bit1有效 */
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
* debug_task.c - USB 虚拟串口(CDC)姿态输出(欧拉角 + 姿态链路诊断)
|
* debug_task.c - USB 虚拟串口(CDC)姿态输出(欧拉角 + 姿态链路诊断 + 控制量)
|
||||||
* 每 DEBUG_OUT_PERIOD_MS 输出一行。单位: 角度 ° / 加速度 m/s² / 角速度 rad/s
|
* 每 DEBUG_OUT_PERIOD_MS 输出一行。单位: 角度 ° / 加速度 m/s² / 角速度 rad/s
|
||||||
*
|
*
|
||||||
* ---- 欧拉角(QuaternionEKF 解算结果,见 modules/ins) ----
|
* ---- 欧拉角(QuaternionEKF 解算结果,见 modules/ins) ----
|
||||||
@@ -25,7 +25,30 @@
|
|||||||
* se bmi088_spi_errors:SPI/DMA 出错次数;st=bmi088_spi_state()
|
* se bmi088_spi_errors:SPI/DMA 出错次数;st=bmi088_spi_state()
|
||||||
* (1=READY,非 1 说明 SPI 被卡住,数据路会因此停摆)
|
* (1=READY,非 1 说明 SPI 被卡住,数据路会因此停摆)
|
||||||
*
|
*
|
||||||
* 开关: DEBUG_ATT_HEALTH=0 只输出三个欧拉角;DEBUG_ATT_DIAG=0 去掉诊断位。
|
* ---- 控制量(DEBUG_CMD_OUT=1 时追加;用于排查 控制源→cmd_robot→执行机构) ----
|
||||||
|
* online 1=**遥控器(DR16)在线** —— 本板这一位只反映 DR16,键鼠不置位!
|
||||||
|
* 没有遥控器时整段控制分支都不执行(见 robot_cmd_task.c 的 online 门控),
|
||||||
|
* 所以"键鼠测试"也必须有遥控器在线,否则这里恒为 0。
|
||||||
|
* src 0=遥控器 1=键鼠(判据:0x0304 在 1s 内到过 keyboard_data.last_tick)
|
||||||
|
* spin 小陀螺使能(云台侧检测,随 0x189 下发给底盘)
|
||||||
|
* yaw_d/pitch_d 本周期云台角度增量(°/2ms 任务周期,×500 即 °/s)
|
||||||
|
* fric/fire/eject 发射机构开关 reset 云台角度复位请求
|
||||||
|
* s2/ctrl 遥控器 S2 档位与 Ctrl 按下沿 —— 底盘就是靠这两个量推出
|
||||||
|
* chassis_mode,所以本板不输出模式本身(本板该字段恒为 OFF)
|
||||||
|
* wheel 遥控拨轮原始值(1000~1050 为中立)
|
||||||
|
* --- 以下为 DR16 帧内容诊断(判断"键鼠数据到底有没有到机器人") ---
|
||||||
|
* s1 左侧拨杆(1上 2下 3中)。注意官方 RoboRTS 的 dbus.c 与本工程一致:
|
||||||
|
* sw2=bit44-45→s2, sw1=bit46-47→s1;若与实物相反,用本列与 s2 对照即可判定
|
||||||
|
* mouse_rl/mouse_du/mouse_wheel 帧里 data[6..11] 解析出的鼠标三轴
|
||||||
|
* mouse_l/mouse_r 帧里 data[12]/data[13](鼠标左右键)
|
||||||
|
* key_lo/key_hi 帧里 data[14]/data[15] **原始字节**(不做位拆分)
|
||||||
|
* ★ 按下 W 时 key_lo 应变 0x01;若恒为 0,说明帧里根本没有键鼠数据
|
||||||
|
* frames dr16_frame_count;持续增长说明 USART3 一直在收帧
|
||||||
|
* 无健康位(DEBUG_ATT_HEALTH=0)时输出为纯数字 CSV,列序即上面顺序,
|
||||||
|
* 可被 Lissio FireWater 直接解析成通道绘图。
|
||||||
|
*
|
||||||
|
* 开关: DEBUG_ATT_HEALTH=0 只输出三个欧拉角;DEBUG_ATT_DIAG=0 去掉诊断位;
|
||||||
|
* DEBUG_CMD_OUT=1 追加控制量字段。
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "debug_task.h"
|
#include "debug_task.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
@@ -36,24 +59,69 @@
|
|||||||
#include "ins.h"
|
#include "ins.h"
|
||||||
#include "bmi088.h"
|
#include "bmi088.h"
|
||||||
#include "gimbal.h"
|
#include "gimbal.h"
|
||||||
|
#include "dr16.h"
|
||||||
|
#include "robot_typedef.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* ===== 2026-10-15 台架调参临时遥测(已停用,保留备查) =====
|
||||||
|
* 启用时把 #if 0 改 #if 1:本任务改为输出 5 列 CSV
|
||||||
|
* setpoint_deg, actual_deg, out_current, ecd_deg, gyro_x_dps
|
||||||
|
* (逗号分隔+换行,可被 Lissio FireWater 自动识别为 5 通道),采样率提到 200Hz,
|
||||||
|
* 用于定量观测阶跃响应与判断"轴是否真的在转动"。 */
|
||||||
|
#if 0
|
||||||
|
#include "robot_param.h"
|
||||||
|
#define DEBUG_PITCH_TUNE 1
|
||||||
|
#if DEBUG_PITCH_TUNE
|
||||||
|
#define DEBUG_OUT_PERIOD_MS 5 /* 200Hz:2ms 控制环的阶跃响应需 ≥100Hz 采样才量得准 */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* 1-输出健康位(cvg/rdy/imu/an/gn); 0-只输出三个欧拉角 */
|
/* 1-输出健康位(cvg/rdy/imu/an/gn); 0-只输出三个欧拉角 */
|
||||||
#define DEBUG_ATT_HEALTH 1
|
#define DEBUG_ATT_HEALTH 0
|
||||||
/* 1-再附加原始陀螺/零偏/采样计数(排障用); 0-只留上面的通用健康位 */
|
/* 1-再附加原始陀螺/零偏/采样计数(排障用); 0-只留上面的通用健康位 */
|
||||||
#define DEBUG_ATT_DIAG 1
|
#define DEBUG_ATT_DIAG 0
|
||||||
|
/* 1-仅输出 Pitch 调参行(便于用 VOFA+/串口示波器绘图); 0-同时输出姿态行与 Pitch 调参行 */
|
||||||
|
#define DEBUG_PITCH_ONLY 0
|
||||||
|
/* 1-追加控制量字段(见文件头); 0-保持原姿态输出不变 */
|
||||||
|
#define DEBUG_CMD_OUT 1
|
||||||
|
|
||||||
/* 输出周期(ms)。姿态观测建议 100ms(10Hz) */
|
/* 输出周期(ms)。姿态观测建议 100ms(10Hz) */
|
||||||
#define DEBUG_OUT_PERIOD_MS 100
|
#define DEBUG_OUT_PERIOD_MS 100
|
||||||
|
|
||||||
void debug_task(void const * argument)
|
void debug_task(void const * argument)
|
||||||
{
|
{
|
||||||
char line[192];
|
char line[384];
|
||||||
char tail[112];
|
char tail[112];
|
||||||
|
char pitch_line[128];
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
|
/* ===== 2026-10-15 台架 Pitch 调参遥测(已停用,保留备查) =====
|
||||||
|
* 5 列 CSV → Lissio FireWater 直接成 5 通道:
|
||||||
|
* setpoint(位置环设定值含台架偏置), actual(-att_deg_roll),
|
||||||
|
* out(最终电流), ecd_deg(编码器机械角), gyro_x_dps(陀螺 x 轴角速度) */
|
||||||
|
const float tune_ecd_deg = ((float)motor_pitch_gimbal.fdb.raw_angle -
|
||||||
|
(float)PITCH_GM6020_ENCODER_ZERO) * (360.0f / 8192.0f);
|
||||||
|
const float tune_gyro_dps = bmi088_gyro[0] * 57.29578f;
|
||||||
|
int len = snprintf(line, sizeof(line), "%.3f,%.3f,%.1f,%.3f,%.2f\n",
|
||||||
|
gimbal_pitch_setpoint_deg(),
|
||||||
|
-att_deg_roll,
|
||||||
|
pitch_current,
|
||||||
|
tune_ecd_deg,
|
||||||
|
tune_gyro_dps);
|
||||||
|
#endif
|
||||||
|
#if DEBUG_PITCH_ONLY
|
||||||
|
/* 仅输出 Pitch 调参数据(编码值、roll、PID最后输出值、遥控pitch杆量) */
|
||||||
|
int len = snprintf(line, sizeof(line),
|
||||||
|
"p_ecd=%u roll=%.2f p_out=%.1f rc_pitch=%u\r\n",
|
||||||
|
(unsigned)motor_pitch_gimbal.fdb.raw_angle,
|
||||||
|
att_deg_roll,
|
||||||
|
pitch_current,
|
||||||
|
(unsigned)dr16.rc_l_UD);
|
||||||
|
#else
|
||||||
const float an = sqrtf(bmi088_accel[0] * bmi088_accel[0] +
|
const float an = sqrtf(bmi088_accel[0] * bmi088_accel[0] +
|
||||||
bmi088_accel[1] * bmi088_accel[1] +
|
bmi088_accel[1] * bmi088_accel[1] +
|
||||||
bmi088_accel[2] * bmi088_accel[2]);
|
bmi088_accel[2] * bmi088_accel[2]);
|
||||||
@@ -72,16 +140,69 @@ void debug_task(void const * argument)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_ATT_HEALTH
|
#if DEBUG_ATT_HEALTH
|
||||||
|
#if DEBUG_CMD_OUT
|
||||||
|
/* 健康位分支是文本格式,控制量就按 key=value 追加,便于人读 */
|
||||||
|
char ctl[160];
|
||||||
|
snprintf(ctl, sizeof(ctl),
|
||||||
|
" online=%u src=%u spin=%u yaw_d=%.4f pitch_d=%.4f fric=%u fire=%u"
|
||||||
|
" eject=%u reset=%u s2=%u ctrl=%u wheel=%d",
|
||||||
|
(unsigned)cmd_robot.online, (unsigned)cmd_robot.source,
|
||||||
|
(unsigned)cmd_robot.spin_flag,
|
||||||
|
cmd_robot.gimbal_yaw_delta, cmd_robot.gimbal_pitch_delta,
|
||||||
|
(unsigned)cmd_robot.friction_on, (unsigned)cmd_robot.fire,
|
||||||
|
(unsigned)cmd_robot.eject, (unsigned)cmd_robot.gimbal_reset,
|
||||||
|
(unsigned)dr16.s2, (unsigned)dr16.key_push_ctrl,
|
||||||
|
(int)cmd_robot.thumb_wheel);
|
||||||
|
#else
|
||||||
|
const char * ctl = "";
|
||||||
|
#endif
|
||||||
int len = snprintf(line, sizeof(line),
|
int len = snprintf(line, sizeof(line),
|
||||||
"ecd=%u yaw=%.2f pitch=%.2f roll=%.2f cvg=%u rdy=%u imu=%u an=%.2f gn=%.3f%s\r\n",
|
"ecd=%u yaw=%.2f pitch=%.2f roll=%.2f cvg=%u rdy=%u imu=%u an=%.2f gn=%.3f%s%s\r\n",
|
||||||
(unsigned)motor_yaw_gimbal.fdb.raw_angle,
|
(unsigned)motor_yaw_gimbal.fdb.raw_angle,
|
||||||
att_deg_yaw, att_deg_pitch, att_deg_roll,
|
att_deg_yaw, att_deg_pitch, att_deg_roll,
|
||||||
(unsigned)INS.ConvergeFlag, (unsigned)att_ready,
|
(unsigned)INS.ConvergeFlag, (unsigned)att_ready,
|
||||||
(unsigned)bmi088_online, an, gn, tail);
|
(unsigned)bmi088_online, an, gn, tail, ctl);
|
||||||
#else
|
#else
|
||||||
int len = snprintf(line, sizeof(line), "ecd=%u yaw=%.2f pitch=%.2f roll=%.2f\r\n",
|
#if DEBUG_CMD_OUT
|
||||||
|
/* 纯数字 CSV。前 3 列保持原样(pitch_ecd, pitch_current, yaw_ecd),其余:
|
||||||
|
* online,src,spin, yaw_d,pitch_d, fric,fire,eject,reset, s2,ctrl,wheel,
|
||||||
|
* s1, mouse_rl,mouse_du,mouse_wheel,mouse_l,mouse_r, key_lo,key_hi,
|
||||||
|
* dr16_frame_count
|
||||||
|
* 末尾这 9 列是 DR16 帧内容诊断:key_lo/key_hi 就是帧里的 data[14]/data[15]。
|
||||||
|
* 按住 W 时若它们仍为 0,说明帧里本就没有键鼠数据(不是解析问题)。 */
|
||||||
|
int len = snprintf(line, sizeof(line),
|
||||||
|
"%u,%.1f,%u,%u,%u,%u,%.4f,%.4f,%u,%u,%u,%u,%u,%u,%d,%u,%d,%d,%d,%u,%u,%u,%u,%lu\r\n",
|
||||||
|
(unsigned)motor_pitch_gimbal.fdb.raw_angle,
|
||||||
|
pitch_current,
|
||||||
(unsigned)motor_yaw_gimbal.fdb.raw_angle,
|
(unsigned)motor_yaw_gimbal.fdb.raw_angle,
|
||||||
att_deg_yaw, att_deg_pitch, att_deg_roll);
|
(unsigned)cmd_robot.online,
|
||||||
|
(unsigned)cmd_robot.source,
|
||||||
|
(unsigned)cmd_robot.spin_flag,
|
||||||
|
cmd_robot.gimbal_yaw_delta,
|
||||||
|
cmd_robot.gimbal_pitch_delta,
|
||||||
|
(unsigned)cmd_robot.friction_on,
|
||||||
|
(unsigned)cmd_robot.fire,
|
||||||
|
(unsigned)cmd_robot.eject,
|
||||||
|
(unsigned)cmd_robot.gimbal_reset,
|
||||||
|
(unsigned)dr16.s2,
|
||||||
|
(unsigned)dr16.key_push_ctrl,
|
||||||
|
(int)cmd_robot.thumb_wheel,
|
||||||
|
(unsigned)dr16.s1,
|
||||||
|
(int)dr16.mouse_rl,
|
||||||
|
(int)dr16.mouse_du,
|
||||||
|
(int)dr16.mouse_wheel,
|
||||||
|
(unsigned)dr16.mouse_key_l,
|
||||||
|
(unsigned)dr16.mouse_key_r,
|
||||||
|
(unsigned)dr16.key_code_lo,
|
||||||
|
(unsigned)dr16.key_code_hi,
|
||||||
|
(unsigned long)dr16_frame_count);
|
||||||
|
#else
|
||||||
|
int len = snprintf(line, sizeof(line), "%u,%.1f,%u\r\n",
|
||||||
|
(unsigned)motor_pitch_gimbal.fdb.raw_angle,
|
||||||
|
pitch_current,(unsigned)motor_yaw_gimbal.fdb.raw_angle);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
* YAW_RUN 正常串级控制(符号用参数回退值,直至手势自检完成)
|
* YAW_RUN 正常串级控制(符号用参数回退值,直至手势自检完成)
|
||||||
* YAW_DETECT 装配符号自检——**仅由操作手手势显式触发,绝不自动执行**:
|
* YAW_DETECT 装配符号自检——**仅由操作手手势显式触发,绝不自动执行**:
|
||||||
* 遥控在线时"左摇杆推到最左 + 右摇杆推到最右"保持 0.5s。
|
* 遥控在线时"左摇杆推到最左 + 右摇杆推到最右"保持 0.5s。
|
||||||
* 检测期间云台会轻转几度(约 20% 电压脉冲 60ms),操作手应
|
* 检测期间云台会轻转几度(约 20% 电流脉冲 60ms),操作手应
|
||||||
* 确认云台周围无人后再做手势。失败重试 3 次后回退参数符号。
|
* 确认云台周围无人后再做手势。失败重试 3 次后回退参数符号。
|
||||||
* 任意门控失效(遥控离线/电机掉线/姿态不可用/底盘故障)立即清零输出
|
* 任意门控失效(遥控离线/电机掉线/姿态不可用/底盘故障)立即清零输出
|
||||||
* 拨弹电流由 shoot_task 写入共享变量,本任务与 Pitch 共帧发送(0x1FF CAN1)
|
* Yaw/Pitch GM6020 采用 0x1FE 电流帧控制;拨弹 M2006 由 shoot_task 独立发 0x200
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "app_tasks.h"
|
#include "app_tasks.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
@@ -64,6 +64,34 @@ void gimbal_task(void const * argument)
|
|||||||
if (gesture)
|
if (gesture)
|
||||||
gesture_cnt = 0;
|
gesture_cnt = 0;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* ===== 2026-10-15 台架 Pitch 阶跃发生器(已停用,保留备查) =====
|
||||||
|
* **有界**测试,不是持续抖动:只跑 GIMBAL_BENCH_PITCH_HALF_COUNT 个半周期,
|
||||||
|
* 跑完自动归零并锁存,之后云台恢复静止(重新上电/改开关才会再跑一次)。
|
||||||
|
* 配合 gimbal.c 的台架偏置使用;2ms 任务,半周期 tick 数 = HALF_MS / 2 */
|
||||||
|
{
|
||||||
|
static uint32_t bench_phase = 0;
|
||||||
|
static uint8_t bench_done = 0;
|
||||||
|
const uint32_t half_ticks = (uint32_t)GIMBAL_BENCH_PITCH_HALF_MS / 2u;
|
||||||
|
if (!bench_done && half_ticks > 0u)
|
||||||
|
{
|
||||||
|
const uint32_t total_ticks = half_ticks * (uint32_t)GIMBAL_BENCH_PITCH_HALF_COUNT;
|
||||||
|
if (bench_phase >= total_ticks)
|
||||||
|
{
|
||||||
|
bench_done = 1;
|
||||||
|
gimbal_bench_pitch_offset = 0.0f; /* 跑完立即停,不再抖动 */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gimbal_bench_pitch_offset = ((bench_phase / half_ticks) % 2u)
|
||||||
|
? GIMBAL_BENCH_PITCH_STEP_DEG
|
||||||
|
: 0.0f;
|
||||||
|
bench_phase++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case YAW_WAIT:
|
case YAW_WAIT:
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ static int8_t linkcheck_first_offline(void)
|
|||||||
{
|
{
|
||||||
uint32_t now = HAL_GetTick();
|
uint32_t now = HAL_GetTick();
|
||||||
#if defined(ROBOT_TYPE_GIMBAL)
|
#if defined(ROBOT_TYPE_GIMBAL)
|
||||||
/* 设备序号:0 摩擦轮L(0x201) 1 摩擦轮R(0x202) 2 Pitch(0x206)
|
/* 设备序号:0 摩擦轮L(CAN1 0x201) 1 摩擦轮R(CAN1 0x202) 2 Pitch(CAN1 0x206)
|
||||||
* 3 Yaw(0x205) 4 拨弹(0x207,安装时) 5 底盘回传(0x019) */
|
* 3 Yaw(CAN2 0x205) 4 拨弹(CAN2 0x201,安装时) 5 底盘回传(0x019) */
|
||||||
if (LINK_OFFLINE(motor_friction_l.fdb.last_online_tick))
|
if (LINK_OFFLINE(motor_friction_l.fdb.last_online_tick))
|
||||||
return 0;
|
return 0;
|
||||||
if (LINK_OFFLINE(motor_friction_r.fdb.last_online_tick))
|
if (LINK_OFFLINE(motor_friction_r.fdb.last_online_tick))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
* robot_cmd_task.c - 控制源汇总(2ms),发布 cmd_robot_t(robot_typedef.h)
|
* robot_cmd_task.c - 控制源汇总(2ms),发布 cmd_robot_t(robot_typedef.h)
|
||||||
* 云台板: DR16 遥控器 + 图传键鼠(0x0304,referee 键盘钩子填充 keyboard_data)
|
* 云台板: DR16 遥控器 + 键鼠(0x0304 优先;USART3 的 18 字节帧里同样带键鼠,两路已合并,见 KB_FROM_DBUS_FRAME)
|
||||||
* 键鼠/遥控互斥(与 legacy 一致);摇杆->云台增量与限位门控;
|
* 键鼠/遥控互斥(与 legacy 一致);摇杆->云台增量与限位门控;
|
||||||
* Q 摩擦轮/左键发射/E 退弹/拨轮;首帧触发 gimbal_reset
|
* Q 摩擦轮/左键发射/E 退弹/拨轮;首帧触发 gimbal_reset
|
||||||
* 底盘板: 从 ctoc_remote(0x149/0x189 解析结果)生成:
|
* 底盘板: 从 ctoc_remote(0x149/0x189 解析结果)生成:
|
||||||
@@ -31,6 +31,9 @@ volatile cmd_robot_t cmd_robot;
|
|||||||
#if defined(ROBOT_TYPE_GIMBAL)
|
#if defined(ROBOT_TYPE_GIMBAL)
|
||||||
|
|
||||||
keyboard_data_t keyboard_data;
|
keyboard_data_t keyboard_data;
|
||||||
|
/* 键鼠来源合并视图(声明见 robot_cmd_task.h):云台控制与 c_comm_task 底盘摇杆合成共用 */
|
||||||
|
keyboard_data_t keyboard_merged;
|
||||||
|
uint8_t keyboard_merged_online = 0;
|
||||||
static uint8_t keyboard_online = 0;
|
static uint8_t keyboard_online = 0;
|
||||||
|
|
||||||
void dr16_frame_callback(const uint8_t * frame, uint16_t len)
|
void dr16_frame_callback(const uint8_t * frame, uint16_t len)
|
||||||
@@ -74,6 +77,15 @@ static void referee_keyboard_hook(const uint8_t data[12])
|
|||||||
keyboard_data.last_tick = HAL_GetTick();
|
keyboard_data.last_tick = HAL_GetTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---- 键鼠输入来源(2026-10-16 修) ----
|
||||||
|
* 背景:客户端键鼠是从 USART3 那 18 字节帧进来的(data[6..15]),dr16_parse 早就
|
||||||
|
* 解析进 dr16.mouse_rl / dr16.key_w 等字段,但控制逻辑只读 0x0304 填的
|
||||||
|
* keyboard_data,于是"键鼠控制完全没用"。此开关让两路合并。
|
||||||
|
* 1 = 除 0x0304 外同时接受帧内键鼠:见到键鼠动作即进入键鼠模式并保持,
|
||||||
|
* 直到操作手去动云台左摇杆才交还遥控器(右摇杆在底盘,键鼠模式下仍要能用)。
|
||||||
|
* 0 = 旧行为:只有 0x0304 在线才走键鼠。 */
|
||||||
|
#define KB_FROM_DBUS_FRAME 1
|
||||||
|
|
||||||
void robot_cmd_task(void const * argument)
|
void robot_cmd_task(void const * argument)
|
||||||
{
|
{
|
||||||
referee_set_keyboard_hook(referee_keyboard_hook);
|
referee_set_keyboard_hook(referee_keyboard_hook);
|
||||||
@@ -81,13 +93,80 @@ void robot_cmd_task(void const * argument)
|
|||||||
while (!app_ready)
|
while (!app_ready)
|
||||||
osDelay(2);
|
osDelay(2);
|
||||||
|
|
||||||
|
/* 键鼠模式状态:帧内键鼠动作置 1,左摇杆动作清 0 */
|
||||||
|
static uint8_t kb_mode = 0;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
keyboard_online = (keyboard_data.last_tick != 0 &&
|
keyboard_online = (keyboard_data.last_tick != 0 &&
|
||||||
HAL_GetTick() - keyboard_data.last_tick < DEVICE_OFFLINE_TIME_MS * 10);
|
HAL_GetTick() - keyboard_data.last_tick < DEVICE_OFFLINE_TIME_MS * 10);
|
||||||
|
|
||||||
|
#if KB_FROM_DBUS_FRAME
|
||||||
|
{
|
||||||
|
uint8_t kb_act = 0, rc_act = 0;
|
||||||
|
|
||||||
|
/* 键鼠动作:鼠标移动 / 滚轮 / 左右键 / 任意按键(data[14]或data[15]非 0) */
|
||||||
|
if (dr16.mouse_rl > 1 || dr16.mouse_rl < -1) kb_act = 1;
|
||||||
|
if (dr16.mouse_du > 1 || dr16.mouse_du < -1) kb_act = 1;
|
||||||
|
if (dr16.mouse_wheel != 0) kb_act = 1;
|
||||||
|
if (dr16.mouse_key_l || dr16.mouse_key_r) kb_act = 1;
|
||||||
|
if (dr16.key_code_lo || dr16.key_code_hi) kb_act = 1;
|
||||||
|
|
||||||
|
/* 遥控器动作:只认云台左摇杆 */
|
||||||
|
if (dr16.rc_l_UD > 1050 || dr16.rc_l_UD < 1000) rc_act = 1;
|
||||||
|
if (dr16.rc_l_RL > 1050 || dr16.rc_l_RL < 1000) rc_act = 1;
|
||||||
|
|
||||||
|
if (kb_act) kb_mode = 1;
|
||||||
|
if (rc_act) kb_mode = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 是否键鼠在控:0x0304 在线时始终算键鼠(保持原有优先级) */
|
||||||
|
uint8_t kb_active = (keyboard_online || kb_mode) ? 1 : 0;
|
||||||
|
|
||||||
|
/* ---- 合并成共享视图 keyboard_merged ----
|
||||||
|
* 0x0304 在线 → 整份用 keyboard_data;否则用 USART3 帧里那一套。
|
||||||
|
* 云台控制、发射机构、以及 c_comm_task 里 WASD→底盘摇杆的合成都读这个
|
||||||
|
* 视图,避免两处各判一次导致"云台跟鼠标了、底盘却还在收遥控器原始摇杆"。 */
|
||||||
|
if (keyboard_online)
|
||||||
|
{
|
||||||
|
keyboard_merged = keyboard_data;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyboard_merged.mouse_rl = dr16.mouse_rl;
|
||||||
|
keyboard_merged.mouse_du = dr16.mouse_du;
|
||||||
|
keyboard_merged.mouse_wheel = dr16.mouse_wheel;
|
||||||
|
keyboard_merged.mouse_key_l = dr16.mouse_key_l;
|
||||||
|
keyboard_merged.mouse_key_r = dr16.mouse_key_r;
|
||||||
|
keyboard_merged.key_w = dr16.key_w;
|
||||||
|
keyboard_merged.key_s = dr16.key_s;
|
||||||
|
keyboard_merged.key_a = dr16.key_a;
|
||||||
|
keyboard_merged.key_d = dr16.key_d;
|
||||||
|
keyboard_merged.key_shift = dr16.key_shift;
|
||||||
|
keyboard_merged.key_ctrl = dr16.key_ctrl;
|
||||||
|
keyboard_merged.key_q = dr16.key_q;
|
||||||
|
keyboard_merged.key_e = dr16.key_e;
|
||||||
|
/* alpha 键:dr16 侧那两位恒为 0(见 dr16.c 的 >>9/>>10),照搬保持语义 */
|
||||||
|
keyboard_merged.key_alpha1 = dr16.key_alpha1;
|
||||||
|
keyboard_merged.key_alpha2 = dr16.key_alpha2;
|
||||||
|
keyboard_merged.key_push_q = dr16.key_push_q;
|
||||||
|
keyboard_merged.key_push_e = dr16.key_push_e;
|
||||||
|
keyboard_merged.key_push_shift = dr16.key_push_shift;
|
||||||
|
keyboard_merged.key_push_ctrl = dr16.key_push_ctrl;
|
||||||
|
keyboard_merged.last_tick = dr16_last_tick;
|
||||||
|
}
|
||||||
|
keyboard_merged_online = kb_active;
|
||||||
|
|
||||||
|
/* 控制逻辑用的简写(取自共享视图) */
|
||||||
|
int16_t kb_mouse_rl = keyboard_merged.mouse_rl;
|
||||||
|
int16_t kb_mouse_du = keyboard_merged.mouse_du;
|
||||||
|
uint8_t kb_mouse_l = keyboard_merged.mouse_key_l;
|
||||||
|
uint8_t kb_push_q = keyboard_merged.key_push_q;
|
||||||
|
uint8_t kb_push_e = keyboard_merged.key_push_e;
|
||||||
|
|
||||||
cmd_robot.online = (dr16_status == 1 && !dr16_offline());
|
cmd_robot.online = (dr16_status == 1 && !dr16_offline());
|
||||||
cmd_robot.source = keyboard_online ? 1 : 0;
|
cmd_robot.source = kb_active ? 1 : 0;
|
||||||
|
|
||||||
if (cmd_robot.online)
|
if (cmd_robot.online)
|
||||||
{
|
{
|
||||||
@@ -95,10 +174,10 @@ void robot_cmd_task(void const * argument)
|
|||||||
float yaw_delta = 0, pitch_delta = 0;
|
float yaw_delta = 0, pitch_delta = 0;
|
||||||
uint16_t pos = motor_pitch_gimbal.fdb.raw_angle;
|
uint16_t pos = motor_pitch_gimbal.fdb.raw_angle;
|
||||||
|
|
||||||
if (!keyboard_online)
|
if (!kb_active)
|
||||||
{
|
{
|
||||||
/* 遥控器:左摇杆,输出与摇杆偏量成比例(legacy 为过死区即全速,
|
/* 遥控器:左摇杆向上(>1050)为抬头(pitch_delta减小,pos向2260减小),门控须 pos > UPPER_LIMIT(2260);
|
||||||
* 体感过灵敏),限位门控与方向保持 legacy */
|
* 左摇杆向下(<1000)为低头(pitch_delta增大,pos向3950增大),门控须 pos < LOWER_LIMIT(3950) */
|
||||||
if (dr16.rc_l_UD > 1050 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
if (dr16.rc_l_UD > 1050 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
||||||
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
||||||
((float)dr16.rc_l_UD - 1024.0f) / 660.0f;
|
((float)dr16.rc_l_UD - 1024.0f) / 660.0f;
|
||||||
@@ -113,24 +192,27 @@ void robot_cmd_task(void const * argument)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 键鼠:同改为比例输出 */
|
/* 键鼠:鼠标前推(>8)为抬头(pitch_delta减小),门控须 pos > UPPER_LIMIT;鼠标后拉(<-8)为低头(pitch_delta增大),门控须 pos < LOWER_LIMIT */
|
||||||
if (keyboard_data.mouse_du < -8 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
if (kb_mouse_du > 8 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
||||||
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
||||||
(-(float)keyboard_data.mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
((float)kb_mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
||||||
else if (keyboard_data.mouse_du > 8 && pos < PITCH_GM6020_POSITION_LOWER_LIMIT)
|
else if (kb_mouse_du < -8 && pos < PITCH_GM6020_POSITION_LOWER_LIMIT)
|
||||||
pitch_delta += GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
pitch_delta += GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
||||||
((float)keyboard_data.mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
(-(float)kb_mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
||||||
|
|
||||||
if (keyboard_data.mouse_rl != 0)
|
if (kb_mouse_rl != 0)
|
||||||
yaw_delta -= GIMBAL_LEVER_SPEED_MAP_RATE * GIMBAL_YAW_PITCH_SPEED_RATE *
|
yaw_delta -= GIMBAL_LEVER_SPEED_MAP_RATE * GIMBAL_YAW_PITCH_SPEED_RATE *
|
||||||
GIMBAL_YAW_PITCH_SPEED_RATE * 0.0439453125f *
|
GIMBAL_YAW_PITCH_SPEED_RATE * 0.0439453125f *
|
||||||
((float)keyboard_data.mouse_rl * PC_MOUSE_RL_SENSITIVITY / 660.0f * 2.0f);
|
((float)kb_mouse_rl * PC_MOUSE_RL_SENSITIVITY / 660.0f * 2.0f);
|
||||||
}
|
}
|
||||||
cmd_robot.gimbal_yaw_delta = yaw_delta;
|
cmd_robot.gimbal_yaw_delta = yaw_delta;
|
||||||
cmd_robot.gimbal_pitch_delta = pitch_delta;
|
cmd_robot.gimbal_pitch_delta = pitch_delta;
|
||||||
|
|
||||||
/* ---- 发射机构 ---- */
|
/* ---- 发射机构 ----
|
||||||
if (!keyboard_online)
|
* 键鼠模式用 Q / 鼠标左键 / E(两路来源已合并进 kb_*,0x0304 优先);
|
||||||
|
* 遥控模式用 S1 与拨轮。kb_push_* 是"按下翻转"的常驻状态,
|
||||||
|
* 且键鼠模式只在动左摇杆时才退出,所以摩擦轮/E 的状态不会自己掉。 */
|
||||||
|
if (!kb_active)
|
||||||
{
|
{
|
||||||
cmd_robot.friction_on = (dr16.s1 == 1);
|
cmd_robot.friction_on = (dr16.s1 == 1);
|
||||||
cmd_robot.fire = (dr16.thumb_wheel < 1000);
|
cmd_robot.fire = (dr16.thumb_wheel < 1000);
|
||||||
@@ -138,9 +220,9 @@ void robot_cmd_task(void const * argument)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd_robot.friction_on = keyboard_data.key_push_q;
|
cmd_robot.friction_on = kb_push_q;
|
||||||
cmd_robot.fire = keyboard_data.mouse_key_l;
|
cmd_robot.fire = kb_mouse_l;
|
||||||
cmd_robot.eject = keyboard_data.key_push_e;
|
cmd_robot.eject = kb_push_e;
|
||||||
}
|
}
|
||||||
cmd_robot.thumb_wheel = dr16.thumb_wheel;
|
cmd_robot.thumb_wheel = dr16.thumb_wheel;
|
||||||
}
|
}
|
||||||
@@ -153,12 +235,13 @@ void robot_cmd_task(void const * argument)
|
|||||||
cmd_robot.eject = 0;
|
cmd_robot.eject = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 小陀螺使能:Ctrl 沿翻转(仅在遥控源检测,键鼠 TODO);
|
/* 小陀螺使能:Ctrl 沿翻转。键鼠模式下取键鼠那一路的 Ctrl(0x0304 的
|
||||||
|
* keyboard_data 或帧内 dr16.key_push_ctrl),遥控模式用遥控器 Ctrl。
|
||||||
* 云台侧是数据源头,底盘只收状态位——重连瞬间保持态跳变不会在
|
* 云台侧是数据源头,底盘只收状态位——重连瞬间保持态跳变不会在
|
||||||
* 底盘误触发沿(修复"重连误开小陀螺疯转") */
|
* 底盘误触发沿(修复"重连误开小陀螺疯转") */
|
||||||
{
|
{
|
||||||
static uint8_t spin_flag = 0, last_ctrl = 0;
|
static uint8_t spin_flag = 0, last_ctrl = 0;
|
||||||
uint8_t ctrl_now = (!keyboard_online) ? dr16.key_push_ctrl : 0;
|
uint8_t ctrl_now = keyboard_online ? keyboard_data.key_push_ctrl : dr16.key_push_ctrl;
|
||||||
if (last_ctrl == 0 && ctrl_now == 1)
|
if (last_ctrl == 0 && ctrl_now == 1)
|
||||||
spin_flag = !spin_flag;
|
spin_flag = !spin_flag;
|
||||||
last_ctrl = ctrl_now;
|
last_ctrl = ctrl_now;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
* shoot_task.c - 发射机构任务(2ms)
|
* shoot_task.c - 发射机构任务(2ms)
|
||||||
* shoot_control() 计算摩擦轮/拨弹电流 -> shoot_send_cmd() 发 0x200;
|
* shoot_control() 计算摩擦轮/拨弹电流 -> shoot_send_cmd() 发 0x200(CAN1 摩擦轮 / CAN2 拨弹);
|
||||||
* 拨弹电流由云台任务与 Pitch 共帧发送;发射机构上电状态来自底盘 0x019
|
* 发射机构上电状态来自底盘 0x019
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "app_tasks.h"
|
#include "app_tasks.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
#define ROBOT_PARAM_H
|
#define ROBOT_PARAM_H
|
||||||
|
|
||||||
/* ============================ 云台 ============================ */
|
/* ============================ 云台 ============================ */
|
||||||
#define PITCH_GM6020_POSITION_LOWER_LIMIT 3990 // Pitch 轴编码器值下限(云台抬起方向)
|
#define PITCH_GM6020_POSITION_UPPER_LIMIT 2260 // Pitch 轴抬起极限(最高位,编码器较小值;实测2203撞死限位,留余量设2260)
|
||||||
#define PITCH_GM6020_POSITION_UPPER_LIMIT 2220 // Pitch 轴编码器值上限(云台压低方向)
|
#define PITCH_GM6020_POSITION_LOWER_LIMIT 3950 // Pitch 轴压低极限(最低位,编码器较大值;实测4234撞死限位,留余量设3950)
|
||||||
#define PITCH_GM6020_ENCODER_ZERO 3245 // Pitch 轴编码器零位
|
#define PITCH_GM6020_ENCODER_ZERO 3200 // Pitch 轴编码器水平零位
|
||||||
#define YAW_GM6020_ENCODER_ZERO 4440 // Yaw 轴编码器零位(机械正前方,0~8191)
|
#define YAW_GM6020_ENCODER_ZERO 7730 // Yaw 轴编码器零位(机械正前方,0~8191)
|
||||||
#define CHASSIS_SPIN_FEEDFORWARD_K 0.008f // 小陀螺解算时延前馈补偿系数(s)
|
#define CHASSIS_SPIN_FEEDFORWARD_K 0.008f // 小陀螺解算时延前馈补偿系数(s)
|
||||||
|
|
||||||
#define GIMBAL_FRICTION_WHEEL_SPEED 5500.0f // 摩擦轮转速(RPM)
|
#define GIMBAL_FRICTION_WHEEL_SPEED 5500.0f // 摩擦轮转速(RPM)
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
* 这是反复"疯转"的根源,已废弃;
|
* 这是反复"疯转"的根源,已废弃;
|
||||||
* - 现在两环共用陀螺,整条链只有一个装配符号,由上电自检自动测定
|
* - 现在两环共用陀螺,整条链只有一个装配符号,由上电自检自动测定
|
||||||
* (GIMBAL_YAW_DETECT 见下),无需人工猜;
|
* (GIMBAL_YAW_DETECT 见下),无需人工猜;
|
||||||
* - 单位:角度环 误差° -> 目标角速度°/s;速度环 误差°/s -> 电压。
|
* - 单位:角度环 误差° -> 目标角速度°/s;速度环 误差°/s -> 电流。
|
||||||
* 调参顺序:先速度环(点动不振荡),再位置环(刚性)——见移植 README §8.1 */
|
* 调参顺序:先速度环(点动不振荡),再位置环(刚性)——见移植 README §8.1 */
|
||||||
#define GIMBAL_YAW_ANGLE_KP 20.0f // ° -> °/s:10° 误差给 150°/s
|
#define GIMBAL_YAW_ANGLE_KP 20.0f // ° -> °/s:10° 误差给 150°/s
|
||||||
#define GIMBAL_YAW_ANGLE_KI 0.0f
|
#define GIMBAL_YAW_ANGLE_KI 0.0f
|
||||||
@@ -39,28 +39,50 @@
|
|||||||
#define GIMBAL_YAW_ANGLE_EK_DEADBAND 0.05f // 误差死区(°),QEKF 噪声小可用窄死区
|
#define GIMBAL_YAW_ANGLE_EK_DEADBAND 0.05f // 误差死区(°),QEKF 噪声小可用窄死区
|
||||||
#define GIMBAL_YAW_ANGLE_OUT_LIMIT 360.0f // 目标角速度上限(°/s)
|
#define GIMBAL_YAW_ANGLE_OUT_LIMIT 360.0f // 目标角速度上限(°/s)
|
||||||
|
|
||||||
#define GIMBAL_YAW_SPEED_KP 85.0f // °/s -> 电压:100°/s 误差给 6000(约 24% 满电压)
|
#define GIMBAL_YAW_SPEED_KP 85.0f // °/s -> 电流:100°/s 误差给 6000(约 36% 满电流)
|
||||||
#define GIMBAL_YAW_SPEED_KI 0.0f // 稳定后可回填 0.5~2 消速度稳态差
|
#define GIMBAL_YAW_SPEED_KI 0.0f // 稳定后可回填 0.5~2 消速度稳态差
|
||||||
#define GIMBAL_YAW_SPEED_KD 0.0f // 陀螺速率反馈噪声小,先不用 D
|
#define GIMBAL_YAW_SPEED_KD 0.0f // 陀螺速率反馈噪声小,先不用 D
|
||||||
#define GIMBAL_YAW_SPEED_OUT_LIMIT 25000.0f// GM6020 电压限幅
|
#define GIMBAL_YAW_SPEED_OUT_LIMIT 16384.0f// GM6020 电流限幅(±16384 对应 ±3A)
|
||||||
#define GIMBAL_YAW_SPIN_FEEDFORWARD_K 24.0f // 小陀螺底盘自旋解耦前馈系数(RPM->电压,通常15~35)
|
#define GIMBAL_YAW_SPIN_FEEDFORWARD_K 24.0f // 小陀螺底盘自旋解耦前馈系数(RPM->电流)
|
||||||
|
|
||||||
/* Yaw 装配符号自动检测:上电自检时给 Yaw 电机一个正向小电压脉冲,
|
/* Yaw 装配符号自动检测:上电自检时给 Yaw 电机一个正向小电流脉冲,
|
||||||
* 看陀螺 z 轴往哪边转——脉冲引起同向转动则符号 +1,反向则 -1。
|
* 看陀螺 z 轴往哪边转——脉冲引起同向转动则符号 +1,反向则 -1。
|
||||||
* 检测时云台会轻转几度,勿扶云台;失败(被按住/电机离线)时用 FALLBACK */
|
* 检测时云台会轻转几度,勿扶云台;失败(被按住/电机离线)时用 FALLBACK */
|
||||||
#define GIMBAL_YAW_SIGN_AUTO 1 // 1=上电自动检测 0=直接用 FALLBACK
|
#define GIMBAL_YAW_SIGN_AUTO 1 // 1=上电自动检测 0=直接用 FALLBACK
|
||||||
#define GIMBAL_YAW_SIGN_FALLBACK (1.0f)
|
#define GIMBAL_YAW_SIGN_FALLBACK (1.0f)
|
||||||
#define GIMBAL_YAW_DETECT_VOLTAGE 5000 // 检测脉冲电压(约 20% 满电压)
|
#define GIMBAL_YAW_DETECT_CURRENT 3500 // 检测脉冲电流(约 21% 满电流 16384)
|
||||||
#define GIMBAL_YAW_DETECT_RATE_MIN 20.0f // 判定转动的陀螺速率阈值(°/s)
|
#define GIMBAL_YAW_DETECT_RATE_MIN 20.0f // 判定转动的陀螺速率阈值(°/s)
|
||||||
|
|
||||||
/* ---- Pitch(位置环陀螺 Roll,速度环转子转速——Pitch 无符号史问题,维持原案) ---- */
|
/* ---- Pitch(位置环陀螺 Roll,速度环转子转速——Pitch 无符号史问题,维持原案) ---- */
|
||||||
#define GIMBAL_PITCH_ANGLE_EK_DEADBAND 0.3f // 位置环误差死区(°)
|
#define GIMBAL_PITCH_ANGLE_EK_DEADBAND 0.05f // 误差死区(°),收窄死区消除边缘阶跃
|
||||||
#define GIMBAL_PITCH_ANGLE_KP 15.0f
|
#define GIMBAL_PITCH_ANGLE_KP 15.0f
|
||||||
#define GIMBAL_PITCH_ANGLE_KI 0.0f
|
#define GIMBAL_PITCH_ANGLE_KI 0.0f
|
||||||
#define GIMBAL_PITCH_ANGLE_KD 100.0f
|
#define GIMBAL_PITCH_ANGLE_KD 0.0f // 原100.0f是万级电流振颤主因!清零以消除剧烈振荡
|
||||||
#define GIMBAL_PITCH_SPEED_KP 150.0f
|
#define GIMBAL_PITCH_SPEED_KP 40.0f // 速度/电流环Kp
|
||||||
#define GIMBAL_PITCH_SPEED_KI 0.001f
|
#define GIMBAL_PITCH_SPEED_KI 0.0f
|
||||||
#define GIMBAL_PITCH_SPEED_KD 5.0f
|
#define GIMBAL_PITCH_SPEED_KD 0.0f
|
||||||
|
|
||||||
|
/* Pitch 重力拟合前馈参数: I_g = K_COS * cos(a) + K_SIN * sin(a) + K_CONST
|
||||||
|
* 其中 a = (raw_angle - ZERO_ECD) * 360 / 8192 (°) */
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_ZERO_ECD 3200.0f // 重力补偿拟合基准编码值
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_K_COS 2856.1f// cos 项系数
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_K_SIN 4340.3f// sin 项系数
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_K_CONST 2826.5f // 常数偏置项
|
||||||
|
|
||||||
|
/* ---- 2026-10-15 台架前馈实测记录(未采用,保留备查) ----
|
||||||
|
* 用上位机 203Hz 遥测在编码器 -16.91°/+4.88°/+9.30° 三处长时间静止(编码器
|
||||||
|
* 零漂移+目标恒定)实测真实保持电流 3597/4498/4613 counts;当时上面这组参数
|
||||||
|
* 分别高估 699/1543/1733 counts,折合 1.17~2.89° 稳态静差
|
||||||
|
* (位置环 Kp15×Kp40 = 600 counts/°:静差 = 前馈高估量 / 600)。
|
||||||
|
* 按"保留原相位与形状(K_COS:K_SIN 不变)、幅值×0.503 并微调常数项"重标定为:
|
||||||
|
* GIMBAL_PITCH_GRAVITY_K_COS 1435.4f
|
||||||
|
* GIMBAL_PITCH_GRAVITY_K_SIN 2181.3f
|
||||||
|
* GIMBAL_PITCH_GRAVITY_K_CONST 2861.6f
|
||||||
|
* 该组在当次数据上残差 RMS 16 counts(0.03°),看似很准;**但换到另一机械状态后
|
||||||
|
* 同一编码器角度实测保持电流又差约 1650 counts**,说明被标定对象本身在变
|
||||||
|
* (见上方"机械滞回 2130 counts"记录),故不采用,前馈保持原值不动。
|
||||||
|
* 另一并记录:PID 动态特性实测良好(上升时间 0.095~0.14s、超调 0.3~5.2%、
|
||||||
|
* 16s 稳态段纹波 p-p 0.046°、无振荡),故 GIMBAL_PITCH_*_KP/KI/KD 也未改动。 */
|
||||||
|
|
||||||
#define GIMBAL_FRICTION_WHEEL_KP 16.0f
|
#define GIMBAL_FRICTION_WHEEL_KP 16.0f
|
||||||
#define GIMBAL_FRICTION_WHEEL_KI 0.0f
|
#define GIMBAL_FRICTION_WHEEL_KI 0.0f
|
||||||
@@ -117,10 +139,11 @@
|
|||||||
#define CTOC_SLAVE_ID1 0x149 // 云台->底盘:摇杆数据
|
#define CTOC_SLAVE_ID1 0x149 // 云台->底盘:摇杆数据
|
||||||
#define CTOC_SLAVE_ID2 0x189 // 云台->底盘:控制状态+故障/陀螺使能位
|
#define CTOC_SLAVE_ID2 0x189 // 云台->底盘:控制状态+故障/陀螺使能位
|
||||||
#define CTOC_SLAVE_ID3 0x1A9 // 云台->底盘:云台世界系 yaw(float)+att_ready
|
#define CTOC_SLAVE_ID3 0x1A9 // 云台->底盘:云台世界系 yaw(float)+att_ready
|
||||||
|
#define CTOC_SLAVE_ID4 0x1B9 // 云台->底盘:自定义UI 专用(pitch + 摩擦轮 L/R 转速)
|
||||||
|
|
||||||
/* ============================ CAN ID ============================ */
|
/* ============================ CAN ID ============================ */
|
||||||
/* 云台板:CAN1 = Pitch GM6020(0x206)+摩擦轮 M3508(0x201/0x202)
|
/* 云台板:CAN1 = Pitch GM6020(0x206,0x1FE)+摩擦轮 M3508(0x201/0x202,0x200)
|
||||||
* CAN2 = Yaw GM6020(0x205)+底盘回传(0x019)
|
* CAN2 = Yaw GM6020(0x205,0x1FE)+拨弹 M2006(0x201,0x200)+底盘回传(0x019)
|
||||||
* 底盘板:CAN1 = 四轮 M3508(0x201~0x204)
|
* 底盘板:CAN1 = 四轮 M3508(0x201~0x204)
|
||||||
* CAN2 = 云台数据(0x149/0x189/0x1A9) */
|
* CAN2 = 云台数据(0x149/0x189/0x1A9) */
|
||||||
|
|
||||||
@@ -128,9 +151,44 @@
|
|||||||
#define DEBUG_SHOOT_WITHOUT_REFEREE 1 // 1=无裁判系统时也允许开摩擦轮(台架调试用),比赛请改 0
|
#define DEBUG_SHOOT_WITHOUT_REFEREE 1 // 1=无裁判系统时也允许开摩擦轮(台架调试用),比赛请改 0
|
||||||
#define GIMBAL_RAMMER_INSTALLED 0 // 1=拨弹 M2006 已安装;0=暂缺,不参与掉线判定
|
#define GIMBAL_RAMMER_INSTALLED 0 // 1=拨弹 M2006 已安装;0=暂缺,不参与掉线判定
|
||||||
|
|
||||||
|
/* ================= 2026-10-15 Pitch 台架 PID 调参改动(已停用,保留备查) =================
|
||||||
|
* 以下开关是一次台架 Pitch 调参试验所加,已用 #if 0 停用:不参与编译、不影响现有行为。
|
||||||
|
* 需要复现时把外层 #if 0 改成 #if 1,并同步启用 gimbal.c / gimbal_task.c / gimbal.h
|
||||||
|
* / debug_task.c 里同名的停用块。
|
||||||
|
* 启用前务必先确认机械无卡滞:当时实测**同一编码器角度下保持电流可差 2130 counts
|
||||||
|
* (≈3.55° 当量)**,属机械滞回(线缆拖拽/接触/摩擦),不是控制问题;机械不一致时
|
||||||
|
* 任何固定前馈都标不准,调参也无意义。 */
|
||||||
|
#if 0
|
||||||
|
/* ---- Pitch 台架 PID 调参(仅台架;调完/比赛必须置 0) ----
|
||||||
|
* 1=在 Pitch 位置环设定值上叠加一个方波阶跃,用于定量观测阶跃响应。
|
||||||
|
* 安全约束(务必遵守):
|
||||||
|
* - **有界**:只跑 GIMBAL_BENCH_PITCH_HALF_COUNT 个半周期就自动归零停住,
|
||||||
|
* 不做长时间连续抖动;
|
||||||
|
* - **限位内**:轴距上下软限位不足 GIMBAL_BENCH_PITCH_SAFE_MARGIN_DEG 时
|
||||||
|
* 不施加阶跃,绝不把轴推向限位;
|
||||||
|
* - 该偏置是纯附加量,不累加进 pitch_target_deg,关掉即完全恢复原行为。 */
|
||||||
|
#define GIMBAL_BENCH_PITCH_TUNE 0
|
||||||
|
#define GIMBAL_BENCH_PITCH_STEP_DEG 3.0f // 阶跃幅值(°)
|
||||||
|
#define GIMBAL_BENCH_PITCH_HALF_MS 800 // 半周期(ms),(跑完自动停,非持续抖动)
|
||||||
|
#define GIMBAL_BENCH_PITCH_HALF_COUNT 4 // 总半周期数:4×0.8s=3.2s 后自动静止
|
||||||
|
#define GIMBAL_BENCH_PITCH_SAFE_MARGIN_DEG 5.0f // 距上下限位至少留这么多才允许阶跃
|
||||||
|
|
||||||
|
/* Pitch 软限位外的电流限制(方向 + 堵转双层保护):
|
||||||
|
* - 压向限位的方向一律清零(绝不顶限位);
|
||||||
|
* - 离开限位的方向允许 GIMBAL_PITCH_LIMIT_CURRENT_RECOVER,让轴能自行归位
|
||||||
|
* (烧录/上电会短暂失力矩,轴会掉到限位,必须能自己爬起来);
|
||||||
|
* - 但限位外若连续 GIMBAL_PITCH_LIMIT_STALL_MS 编码器一动不动,判为堵转/
|
||||||
|
* 撞死,允许电流降到 GIMBAL_PITCH_LIMIT_CURRENT,避免长时间过载发热。
|
||||||
|
* 轴回到软限位内后闭环自动恢复正常输出。 */
|
||||||
|
#define GIMBAL_PITCH_LIMIT_CURRENT_RECOVER 12000.0f // 限位外抬升方向允许电流(≈2.2A,额定3A的73%)
|
||||||
|
#define GIMBAL_PITCH_LIMIT_CURRENT 1500.0f // 限位外判定堵转后的涓流上限(≈0.27A)
|
||||||
|
#define GIMBAL_PITCH_LIMIT_STALL_MS 300 // 限位外不动多久判定堵转(高位电流只持续这么久)
|
||||||
|
#endif
|
||||||
|
/* ================= 以上为停用块,以下为原有代码 ================= */
|
||||||
|
|
||||||
/* 1=把 CAN 掉线警告音替换成循环播放的旋律《你》(RM动画片尾曲),报警时播放;
|
/* 1=把 CAN 掉线警告音替换成循环播放的旋律《你》(RM动画片尾曲),报警时播放;
|
||||||
* 旋律音符表见 modules/dev/buzzer.c 的 buzzer_melody[] */
|
* 旋律音符表见 modules/dev/buzzer.c 的 buzzer_melody[] */
|
||||||
#define DEBUG_BUZZER_MELODY 1
|
#define DEBUG_BUZZER_MELODY 0
|
||||||
#define BUZZER_MELODY_SPEED_DIV 1 // 旋律降速分频(默认1:每步100ms精准匹配原版带吐音断音节拍)
|
#define BUZZER_MELODY_SPEED_DIV 1 // 旋律降速分频(默认1:每步100ms精准匹配原版带吐音断音节拍)
|
||||||
|
|
||||||
/* ============================ 掉线检测 ============================ */
|
/* ============================ 掉线检测 ============================ */
|
||||||
|
|||||||
@@ -103,7 +103,7 @@
|
|||||||
<bEvRecOn>1</bEvRecOn>
|
<bEvRecOn>1</bEvRecOn>
|
||||||
<bSchkAxf>0</bSchkAxf>
|
<bSchkAxf>0</bSchkAxf>
|
||||||
<bTchkAxf>0</bTchkAxf>
|
<bTchkAxf>0</bTchkAxf>
|
||||||
<nTsel>2</nTsel>
|
<nTsel>3</nTsel>
|
||||||
<sDll></sDll>
|
<sDll></sDll>
|
||||||
<sDllPa></sDllPa>
|
<sDllPa></sDllPa>
|
||||||
<sDlgDll></sDlgDll>
|
<sDlgDll></sDlgDll>
|
||||||
@@ -114,9 +114,14 @@
|
|||||||
<tDlgDll></tDlgDll>
|
<tDlgDll></tDlgDll>
|
||||||
<tDlgPa></tDlgPa>
|
<tDlgPa></tDlgPa>
|
||||||
<tIfile></tIfile>
|
<tIfile></tIfile>
|
||||||
<pMon>BIN\CMSIS_AGDI.dll</pMon>
|
<pMon>Segger\JL2CM3.dll</pMon>
|
||||||
</DebugOpt>
|
</DebugOpt>
|
||||||
<TargetDriverDllRegistry>
|
<TargetDriverDllRegistry>
|
||||||
|
<SetRegEntry>
|
||||||
|
<Number>0</Number>
|
||||||
|
<Key>JL2CM3</Key>
|
||||||
|
<Name>-U20090928 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||||
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>ARMRTXEVENTFLAGS</Key>
|
<Key>ARMRTXEVENTFLAGS</Key>
|
||||||
|
|||||||
+5
-5
@@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
## 这块板负责什么
|
## 这块板负责什么
|
||||||
|
|
||||||
- **云台控制**:Yaw(GM6020 `0x205`,CAN2)/ Pitch(GM6020 `0x206`,CAN1)双环
|
- **云台控制**:Yaw(GM6020 `0x205`,CAN2 `0x1FE`电流控制)/ Pitch(GM6020 `0x206`,CAN1 `0x1FE`电流控制)双环
|
||||||
- **发射机构**:摩擦轮 M3508 `0x201`/`0x202` + 拨弹 M2006 `0x207`(装与不装由 `GIMBAL_RAMMER_INSTALLED` 决定)
|
- **发射机构**:摩擦轮 M3508 `0x201`/`0x202`(CAN1 `0x200`) + 拨弹 M2006 `0x201`(CAN2 `0x200`)(装与不装由 `GIMBAL_RAMMER_INSTALLED` 决定)
|
||||||
- **图传链路 / 裁判系统**:USART6(3pin 口)
|
- **图传链路 / 裁判系统**:USART6(3pin 口)
|
||||||
- **DR16 遥控器**:USART3
|
- **DR16 遥控器**:USART3
|
||||||
- **板间通讯主控**:云台把世界系 yaw(`0x1A9`)与摇杆/控制状态(`0x149`/`0x189`)发给底盘
|
- **板间通讯主控**:云台把世界系 yaw(`0x1A9`)与摇杆/控制状态(`0x149`/`0x189`)发给底盘
|
||||||
@@ -38,7 +38,7 @@ USE_HAL_DRIVER, STM32F407xx, ARM_MATH_CM4, ROBOT_TYPE_GIMBAL
|
|||||||
|
|
||||||
1. `led_init` 点亮蓝灯 → 各外设初始化
|
1. `led_init` 点亮蓝灯 → 各外设初始化
|
||||||
2. IMU 初始化 + **z 轴零偏静止标定(约 0.5~1.5 s,这段时间别碰车)**
|
2. IMU 初始化 + **z 轴零偏静止标定(约 0.5~1.5 s,这段时间别碰车)**
|
||||||
3. **Yaw 装配符号自检**:给 Yaw 电机一个正向小电压脉冲,看陀螺 z 轴往哪边转,自动定符号;**云台会轻转几度,不要扶住云台**。失败(被按住 / 电机离线)时回退到 `GIMBAL_YAW_SIGN_FALLBACK`
|
3. **Yaw 装配符号自检**:给 Yaw 电机一个正向小电流脉冲,看陀螺 z 轴往哪边转,自动定符号;**云台会轻转几度,不要扶住云台**。失败(被按住 / 电机离线)时回退到 `GIMBAL_YAW_SIGN_FALLBACK`
|
||||||
4. 自检结果经 `0x1A9` 的 flags 下发给底盘,与底盘自测的车身转向相乘完成跟随符号综合
|
4. 自检结果经 `0x1A9` 的 flags 下发给底盘,与底盘自测的车身转向相乘完成跟随符号综合
|
||||||
|
|
||||||
## 蜂鸣器序号(本板)
|
## 蜂鸣器序号(本板)
|
||||||
@@ -46,8 +46,8 @@ USE_HAL_DRIVER, STM32F407xx, ARM_MATH_CM4, ROBOT_TYPE_GIMBAL
|
|||||||
CAN 掉线报警按设备序号响 `n` 下:
|
CAN 掉线报警按设备序号响 `n` 下:
|
||||||
|
|
||||||
```
|
```
|
||||||
0 = 摩擦轮L(0x201) 1 = 摩擦轮R(0x202) 2 = Pitch(0x206)
|
0 = 摩擦轮L(CAN1 0x201) 1 = 摩擦轮R(CAN1 0x202) 2 = Pitch(CAN1 0x206)
|
||||||
3 = Yaw(0x205) 4 = 拨弹(0x207) 5 = 底盘回传(0x019)
|
3 = Yaw(CAN2 0x205) 4 = 拨弹(CAN2 0x201) 5 = 底盘回传(0x019)
|
||||||
```
|
```
|
||||||
|
|
||||||
**响三下 = Pitch 电机掉线。** 台架调试嫌吵时把 `robot_param.h` 的 `DEBUG_BUZZER_MELODY` 置 1(只换声音不换灯语)。
|
**响三下 = Pitch 电机掉线。** 台架调试嫌吵时把 `robot_param.h` 的 `DEBUG_BUZZER_MELODY` 置 1(只换声音不换灯语)。
|
||||||
|
|||||||
@@ -136,6 +136,26 @@ void c_comm_master_send(uint8_t keyboard_online, const uint8_t kb[12], uint8_t m
|
|||||||
c_comm_send_frame(&hcan2, CTOC_SLAVE_ID2, data);
|
c_comm_send_frame(&hcan2, CTOC_SLAVE_ID2, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 0x1B9 云台->底盘:自定义UI 专用量(底盘本地没有,见 referee_ui)
|
||||||
|
* [0..1] pitch(0.01°) [2..3] 左摩擦轮(rpm/100) [4..5] 右摩擦轮(rpm/100)
|
||||||
|
* [6] bit0=小陀螺使能 */
|
||||||
|
void c_comm_master_send_ui(float pitch_deg, float fric_l_rpm, float fric_r_rpm, uint8_t spin_on)
|
||||||
|
{
|
||||||
|
uint8_t data[8] = {0};
|
||||||
|
int16_t p = (int16_t)(pitch_deg * 100.0f);
|
||||||
|
int16_t fl = (int16_t)(fric_l_rpm / 100.0f);
|
||||||
|
int16_t fr = (int16_t)(fric_r_rpm / 100.0f);
|
||||||
|
|
||||||
|
data[0] = (uint8_t)(p & 0xFF);
|
||||||
|
data[1] = (uint8_t)((uint16_t)p >> 8);
|
||||||
|
data[2] = (uint8_t)(fl & 0xFF);
|
||||||
|
data[3] = (uint8_t)((uint16_t)fl >> 8);
|
||||||
|
data[4] = (uint8_t)(fr & 0xFF);
|
||||||
|
data[5] = (uint8_t)((uint16_t)fr >> 8);
|
||||||
|
data[6] = spin_on ? 0x01 : 0;
|
||||||
|
c_comm_send_frame(&hcan2, CTOC_SLAVE_ID4, data);
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||||
|
|
||||||
/* ============================ 底盘板(从机) ============================ */
|
/* ============================ 底盘板(从机) ============================ */
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ extern volatile int8_t ctoc_encoder_ccw;
|
|||||||
/* 底盘板:0x1A9 帧是否新鲜(掉线检测) */
|
/* 底盘板:0x1A9 帧是否新鲜(掉线检测) */
|
||||||
extern uint8_t ctoc_att_fresh(void);
|
extern uint8_t ctoc_att_fresh(void);
|
||||||
|
|
||||||
|
/* ---- 0x1B9 云台->底盘:自定义UI 专用数据 ---------------------------------
|
||||||
|
* 底盘本地没有、但裁判系统自定义UI 需要的量(见 底盘/modules/comms/referee_ui):
|
||||||
|
* pitch 角度与左右摩擦轮转速。接收侧解析见底盘 c_comm.c(c_comm_rx_0x1b9)。 */
|
||||||
|
extern void c_comm_master_send_ui(float pitch_deg, float fric_l_rpm, float fric_r_rpm, uint8_t spin_on);
|
||||||
|
|
||||||
/* 注册 CAN 接收回调(can_start() 之后调用) */
|
/* 注册 CAN 接收回调(can_start() 之后调用) */
|
||||||
extern void c_comm_init(void);
|
extern void c_comm_init(void);
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ void dr16_parse(const uint8_t * data)
|
|||||||
dr16.key_alpha1 = (data[14] >> 9) & 0x01;
|
dr16.key_alpha1 = (data[14] >> 9) & 0x01;
|
||||||
dr16.key_alpha2 = (data[14] >> 10) & 0x01;
|
dr16.key_alpha2 = (data[14] >> 10) & 0x01;
|
||||||
|
|
||||||
|
/* 原始按键字节。注意 data[14] 是 uint8_t:上面两条 >>9/>>10 恒为 0
|
||||||
|
* (整型提升后 byte 值 <256,右移 9 位必然为 0),即 alpha 键从未被真正解析。
|
||||||
|
* 官方 16 位 key_code 的高字节在 data[15],这里先原样存下来供诊断/后续解析。 */
|
||||||
|
dr16.key_code_lo = data[14];
|
||||||
|
dr16.key_code_hi = data[15];
|
||||||
|
|
||||||
dr16.thumb_wheel = (int16_t)(((uint16_t)data[17] << 8) | data[16]); // B[120:135]
|
dr16.thumb_wheel = (int16_t)(((uint16_t)data[17] << 8) | data[16]); // B[120:135]
|
||||||
|
|
||||||
/* 按键边沿检测(legacy 语义:Q/E/Shift/Ctrl 按下翻转,鼠标右键按下瞬间置 1) */
|
/* 按键边沿检测(legacy 语义:Q/E/Shift/Ctrl 按下翻转,鼠标右键按下瞬间置 1) */
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ typedef struct
|
|||||||
uint8_t key_alpha1; // 图传扩展键
|
uint8_t key_alpha1; // 图传扩展键
|
||||||
uint8_t key_alpha2;
|
uint8_t key_alpha2;
|
||||||
|
|
||||||
|
/* 原始按键字节(诊断用,不做位拆分) —— 用来判断"帧里到底有没有键鼠数据":
|
||||||
|
* 官方 dbus.h 的 key_code 是 16 位:bit0..7 = W/S/A/D/Shift/Ctrl/Q/E(=data[14]),
|
||||||
|
* bit8..15 = R/F/G/Z/X/C/V/B(=data[15])。本工程此前只读了 data[14]。
|
||||||
|
* 拨键盘时这两个字节若非 0 说明数据确实到了;全 0 说明帧里就是空的。 */
|
||||||
|
uint8_t key_code_lo; // data[14]
|
||||||
|
uint8_t key_code_hi; // data[15]
|
||||||
|
|
||||||
int16_t thumb_wheel; // 遥控器拨轮
|
int16_t thumb_wheel; // 遥控器拨轮
|
||||||
|
|
||||||
/* 按键边沿检测(legacy 语义) */
|
/* 按键边沿检测(legacy 语义) */
|
||||||
|
|||||||
+145
-37
@@ -2,11 +2,11 @@
|
|||||||
* gimbal.c - 云台双轴控制(串级 PID)
|
* gimbal.c - 云台双轴控制(串级 PID)
|
||||||
* Yaw(2026-09 重写):双陀螺环,见 gimbal.h 与 robot_param.h 说明
|
* Yaw(2026-09 重写):双陀螺环,见 gimbal.h 与 robot_param.h 说明
|
||||||
* 位置环:err(°) = 目标角 - SIGN*att_deg_yaw -> 目标角速度(°/s,限幅)
|
* 位置环:err(°) = 目标角 - SIGN*att_deg_yaw -> 目标角速度(°/s,限幅)
|
||||||
* 速度环:err(°/s) = 目标角速度 - SIGN*gyro_z -> 电压(限幅)
|
* 速度环:err(°/s) = 目标角速度 - SIGN*gyro_z -> 电流(限幅)
|
||||||
* 稳定性条件:SIGN*G>0,G 为"电压->陀螺 z 角速度"的装配增益,
|
* 稳定性条件:SIGN*G>0,G 为"电流->陀螺 z 角速度"的装配增益,
|
||||||
* 由 gimbal_detect_yaw_sign() 上电实测,彻底消除双传感器符号打架
|
* 由 gimbal_detect_yaw_sign() 上电实测,彻底消除双传感器符号打架
|
||||||
* Pitch:位置环用 QEKF Roll(安装方向),速度环转子转速(legacy 案,无符号史问题)
|
* Pitch:位置环用 QEKF Roll(安装方向),速度环转子转速(legacy 案,无符号史问题)
|
||||||
* 发送:CAN2 0x1FF 槽1=Yaw 电压;CAN1 0x1FF 槽2=Pitch 电压,槽3=拨弹电流
|
* 发送:CAN2 0x1FE 槽1=Yaw 电流;CAN1 0x1FE 槽2=Pitch 电流
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "gimbal.h"
|
#include "gimbal.h"
|
||||||
#include "shoot.h"
|
#include "shoot.h"
|
||||||
@@ -18,11 +18,16 @@
|
|||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "robot_typedef.h"
|
#include "robot_typedef.h"
|
||||||
#include "dr16.h"
|
#include "dr16.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#ifndef RAD_TO_ANGLE
|
#ifndef RAD_TO_ANGLE
|
||||||
#define RAD_TO_ANGLE 57.295779513082320876798154814105f
|
#define RAD_TO_ANGLE 57.295779513082320876798154814105f
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ANGLE_TO_RAD
|
||||||
|
#define ANGLE_TO_RAD 0.01745329251994329576923690768489f
|
||||||
|
#endif
|
||||||
|
|
||||||
dji_motor_t motor_yaw_gimbal;
|
dji_motor_t motor_yaw_gimbal;
|
||||||
dji_motor_t motor_pitch_gimbal;
|
dji_motor_t motor_pitch_gimbal;
|
||||||
dji_motor_t motor_friction_l;
|
dji_motor_t motor_friction_l;
|
||||||
@@ -34,25 +39,32 @@ static PID_PositionTypeDef pitch_angle_pid, pitch_speed_pid;
|
|||||||
|
|
||||||
static float yaw_target_deg; // 世界系目标角(°)
|
static float yaw_target_deg; // 世界系目标角(°)
|
||||||
static float pitch_target_deg; // 目标角(°)
|
static float pitch_target_deg; // 目标角(°)
|
||||||
static float yaw_voltage;
|
static float yaw_current;
|
||||||
static float pitch_voltage;
|
float pitch_pid = 0.0f;
|
||||||
|
float pitch_g = 0.0f;
|
||||||
|
float pitch_current = 0.0f;
|
||||||
|
|
||||||
|
/* ===== 2026-10-15 台架调参临时量(已停用,保留备查) ===== */
|
||||||
|
#if 0
|
||||||
|
/* 台架调参用 Pitch 目标角附加偏置(°)。由 gimbal_task 的方波发生器写入,
|
||||||
|
* 只叠加到位置环设定值上,不累加进 pitch_target_deg,默认 0 无副作用 */
|
||||||
|
float gimbal_bench_pitch_offset = 0.0f;
|
||||||
|
|
||||||
|
/* 实际施加的偏置(经限位安全门控后),仅用于遥测显示真实设定值 */
|
||||||
|
static float pitch_applied_offset = 0.0f;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* 装配符号:0=未检测,±1=已测定;未检测前 gimbal_control 不应被调用 */
|
/* 装配符号:0=未检测,±1=已测定;未检测前 gimbal_control 不应被调用 */
|
||||||
static float yaw_sign_f = 0.0f;
|
static float yaw_sign_f = 0.0f;
|
||||||
static uint8_t yaw_sign_valid = 0;
|
static uint8_t yaw_sign_valid = 0;
|
||||||
|
|
||||||
/* 拨弹电流由 shoot 模块写入,云台与拨弹共帧(0x1FF CAN1)发送 */
|
|
||||||
static int16_t rammer_current_shared = 0;
|
|
||||||
|
|
||||||
void shoot_share_rammer_current(int16_t current);
|
|
||||||
|
|
||||||
void gimbal_motor_init(void)
|
void gimbal_motor_init(void)
|
||||||
{
|
{
|
||||||
dji_motor_init(&motor_yaw_gimbal, &hcan2, 0x205, DJI_MOTOR_6020);
|
dji_motor_init(&motor_yaw_gimbal, &hcan2, 0x205, DJI_MOTOR_6020);
|
||||||
dji_motor_init(&motor_pitch_gimbal, &hcan1, 0x206, DJI_MOTOR_6020);
|
dji_motor_init(&motor_pitch_gimbal, &hcan1, 0x206, DJI_MOTOR_6020);
|
||||||
dji_motor_init(&motor_friction_l, &hcan1, 0x201, DJI_MOTOR_3508);
|
dji_motor_init(&motor_friction_l, &hcan1, 0x201, DJI_MOTOR_3508);
|
||||||
dji_motor_init(&motor_friction_r, &hcan1, 0x202, DJI_MOTOR_3508);
|
dji_motor_init(&motor_friction_r, &hcan1, 0x202, DJI_MOTOR_3508);
|
||||||
dji_motor_init(&motor_rammer, &hcan1, 0x207, DJI_MOTOR_2006);
|
dji_motor_init(&motor_rammer, &hcan2, 0x201, DJI_MOTOR_2006);
|
||||||
|
|
||||||
/* Yaw 位置环:° -> °/s */
|
/* Yaw 位置环:° -> °/s */
|
||||||
PID_PositionStructureInit(&yaw_angle_pid, 0);
|
PID_PositionStructureInit(&yaw_angle_pid, 0);
|
||||||
@@ -60,7 +72,7 @@ void gimbal_motor_init(void)
|
|||||||
PID_PositionSetEkRange(&yaw_angle_pid, -GIMBAL_YAW_ANGLE_EK_DEADBAND, GIMBAL_YAW_ANGLE_EK_DEADBAND);
|
PID_PositionSetEkRange(&yaw_angle_pid, -GIMBAL_YAW_ANGLE_EK_DEADBAND, GIMBAL_YAW_ANGLE_EK_DEADBAND);
|
||||||
PID_PositionSetOUTRange(&yaw_angle_pid, -GIMBAL_YAW_ANGLE_OUT_LIMIT, GIMBAL_YAW_ANGLE_OUT_LIMIT);
|
PID_PositionSetOUTRange(&yaw_angle_pid, -GIMBAL_YAW_ANGLE_OUT_LIMIT, GIMBAL_YAW_ANGLE_OUT_LIMIT);
|
||||||
|
|
||||||
/* Yaw 速度环:°/s -> 电压 */
|
/* Yaw 速度环:°/s -> 电流 */
|
||||||
PID_PositionStructureInit(&yaw_speed_pid, 0);
|
PID_PositionStructureInit(&yaw_speed_pid, 0);
|
||||||
PID_PositionSetParameter(&yaw_speed_pid, GIMBAL_YAW_SPEED_KP, GIMBAL_YAW_SPEED_KI, GIMBAL_YAW_SPEED_KD);
|
PID_PositionSetParameter(&yaw_speed_pid, GIMBAL_YAW_SPEED_KP, GIMBAL_YAW_SPEED_KI, GIMBAL_YAW_SPEED_KD);
|
||||||
PID_PositionSetOUTRange(&yaw_speed_pid, -GIMBAL_YAW_SPEED_OUT_LIMIT, GIMBAL_YAW_SPEED_OUT_LIMIT);
|
PID_PositionSetOUTRange(&yaw_speed_pid, -GIMBAL_YAW_SPEED_OUT_LIMIT, GIMBAL_YAW_SPEED_OUT_LIMIT);
|
||||||
@@ -73,8 +85,8 @@ void gimbal_motor_init(void)
|
|||||||
|
|
||||||
PID_PositionStructureInit(&pitch_speed_pid, 300);
|
PID_PositionStructureInit(&pitch_speed_pid, 300);
|
||||||
PID_PositionSetParameter(&pitch_speed_pid, GIMBAL_PITCH_SPEED_KP, GIMBAL_PITCH_SPEED_KI, GIMBAL_PITCH_SPEED_KD);
|
PID_PositionSetParameter(&pitch_speed_pid, GIMBAL_PITCH_SPEED_KP, GIMBAL_PITCH_SPEED_KI, GIMBAL_PITCH_SPEED_KD);
|
||||||
PID_PositionSetEkRange(&pitch_speed_pid, -5, 5);
|
PID_PositionSetEkRange(&pitch_speed_pid, 0, 0);
|
||||||
PID_PositionSetOUTRange(&pitch_speed_pid, -30000, 30000);
|
PID_PositionSetOUTRange(&pitch_speed_pid, -16384, 16384);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t gimbal_detect_yaw_sign(void)
|
uint8_t gimbal_detect_yaw_sign(void)
|
||||||
@@ -83,24 +95,24 @@ uint8_t gimbal_detect_yaw_sign(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* 静默期:输出清零等待机械/陀螺稳定 */
|
/* 静默期:输出清零等待机械/陀螺稳定 */
|
||||||
dji_motor_send_current_high(&hcan2, 0, 0, 0, 0);
|
dji_motor_send_gm6020_current_low(&hcan2, 0, 0, 0, 0);
|
||||||
HAL_Delay(50);
|
HAL_Delay(50);
|
||||||
|
|
||||||
/* 正向电压脉冲 60ms,期间平均陀螺 z 角速度 */
|
/* 正向电流脉冲 60ms,期间平均陀螺 z 角速度 */
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
dji_motor_send_current_high(&hcan2, GIMBAL_YAW_DETECT_VOLTAGE, 0, 0, 0);
|
dji_motor_send_gm6020_current_low(&hcan2, GIMBAL_YAW_DETECT_CURRENT, 0, 0, 0);
|
||||||
for (uint16_t i = 0; i < 60; i++)
|
for (uint16_t i = 0; i < 60; i++)
|
||||||
{
|
{
|
||||||
sum += bmi088_gyro[2]; // rad/s(z 轴向上为正)
|
sum += bmi088_gyro[2]; // rad/s(z 轴向上为正)
|
||||||
HAL_Delay(1);
|
HAL_Delay(1);
|
||||||
}
|
}
|
||||||
dji_motor_send_current_high(&hcan2, 0, 0, 0, 0);
|
dji_motor_send_gm6020_current_low(&hcan2, 0, 0, 0, 0);
|
||||||
HAL_Delay(80); // 回稳,随后 gimbal_task 的首次控制会同步目标角
|
HAL_Delay(80); // 回稳,随后 gimbal_task 的首次控制会同步目标角
|
||||||
|
|
||||||
const float rate_dps = sum / 60.0f * RAD_TO_ANGLE;
|
const float rate_dps = sum / 60.0f * RAD_TO_ANGLE;
|
||||||
if (rate_dps > GIMBAL_YAW_DETECT_RATE_MIN)
|
if (rate_dps > GIMBAL_YAW_DETECT_RATE_MIN)
|
||||||
{
|
{
|
||||||
yaw_sign_f = 1.0f; // 正电压->陀螺正转,装配增益 G>0
|
yaw_sign_f = 1.0f; // 正电流->陀螺正转,装配增益 G>0
|
||||||
yaw_sign_valid = 1;
|
yaw_sign_valid = 1;
|
||||||
}
|
}
|
||||||
else if (rate_dps < -GIMBAL_YAW_DETECT_RATE_MIN)
|
else if (rate_dps < -GIMBAL_YAW_DETECT_RATE_MIN)
|
||||||
@@ -121,7 +133,7 @@ float gimbal_yaw_sign(void)
|
|||||||
|
|
||||||
int8_t gimbal_encoder_ccw(void)
|
int8_t gimbal_encoder_ccw(void)
|
||||||
{
|
{
|
||||||
/* 自检:电压正脉冲 -> 陀螺 z 正转(云台 CCW),而电压正方向即编码器
|
/* 自检:电流正脉冲 -> 陀螺 z 正转(云台 CCW),而电流正方向即编码器
|
||||||
* tick 增大方向,故 tick 增方向 = sign(gimbal 旋转) */
|
* tick 增大方向,故 tick 增方向 = sign(gimbal 旋转) */
|
||||||
if (!yaw_sign_valid)
|
if (!yaw_sign_valid)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -151,7 +163,11 @@ void gimbal_control(float yaw_delta, float pitch_delta, uint8_t reset_flag)
|
|||||||
/* 将编码器 tick 差折算为机械角度偏差(°),补偿给世界系目标角 */
|
/* 将编码器 tick 差折算为机械角度偏差(°),补偿给世界系目标角 */
|
||||||
const float ecd_err_deg = (float)ecd_diff * (360.0f / 8192.0f);
|
const float ecd_err_deg = (float)ecd_diff * (360.0f / 8192.0f);
|
||||||
yaw_target_deg = yaw_meas - ecd_err_deg;
|
yaw_target_deg = yaw_meas - ecd_err_deg;
|
||||||
pitch_target_deg = 0;
|
|
||||||
|
/* Pitch: 计算当前编码器距离机械零位的差值,折算为角度偏差补偿给目标角(上电自动归位到零位) */
|
||||||
|
int16_t pitch_ecd_diff = (int16_t)motor_pitch_gimbal.fdb.raw_angle - (int16_t)PITCH_GM6020_ENCODER_ZERO;
|
||||||
|
const float pitch_ecd_err_deg = (float)pitch_ecd_diff * (360.0f / 8192.0f);
|
||||||
|
pitch_target_deg = -att_deg_roll - pitch_ecd_err_deg;
|
||||||
|
|
||||||
if (reset_flag)
|
if (reset_flag)
|
||||||
{
|
{
|
||||||
@@ -169,7 +185,7 @@ void gimbal_control(float yaw_delta, float pitch_delta, uint8_t reset_flag)
|
|||||||
yaw_angle_pid.Need_Value = yaw_target_deg;
|
yaw_angle_pid.Need_Value = yaw_target_deg;
|
||||||
PID_PositionCalc(&yaw_angle_pid, yaw_meas);
|
PID_PositionCalc(&yaw_angle_pid, yaw_meas);
|
||||||
|
|
||||||
/* Yaw 速度环:°/s -> 电压(反馈为带符号陀螺角速度,双环符号自洽) */
|
/* Yaw 速度环:°/s -> 电流(反馈为带符号陀螺角速度,双环符号自洽) */
|
||||||
yaw_speed_pid.Need_Value = yaw_angle_pid.OUT;
|
yaw_speed_pid.Need_Value = yaw_angle_pid.OUT;
|
||||||
PID_PositionCalc(&yaw_speed_pid, yaw_rate_meas);
|
PID_PositionCalc(&yaw_speed_pid, yaw_rate_meas);
|
||||||
|
|
||||||
@@ -179,29 +195,120 @@ void gimbal_control(float yaw_delta, float pitch_delta, uint8_t reset_flag)
|
|||||||
{
|
{
|
||||||
spin_feedforward = GIMBAL_YAW_SPIN_FEEDFORWARD_K * (float)motor_yaw_gimbal.fdb.rotor_speed;
|
spin_feedforward = GIMBAL_YAW_SPIN_FEEDFORWARD_K * (float)motor_yaw_gimbal.fdb.rotor_speed;
|
||||||
}
|
}
|
||||||
yaw_voltage = yaw_speed_pid.OUT + spin_feedforward;
|
yaw_current = yaw_speed_pid.OUT + spin_feedforward;
|
||||||
if (yaw_voltage > GIMBAL_YAW_SPEED_OUT_LIMIT)
|
if (yaw_current > GIMBAL_YAW_SPEED_OUT_LIMIT)
|
||||||
yaw_voltage = GIMBAL_YAW_SPEED_OUT_LIMIT;
|
yaw_current = GIMBAL_YAW_SPEED_OUT_LIMIT;
|
||||||
else if (yaw_voltage < -GIMBAL_YAW_SPEED_OUT_LIMIT)
|
else if (yaw_current < -GIMBAL_YAW_SPEED_OUT_LIMIT)
|
||||||
yaw_voltage = -GIMBAL_YAW_SPEED_OUT_LIMIT;
|
yaw_current = -GIMBAL_YAW_SPEED_OUT_LIMIT;
|
||||||
|
|
||||||
/* Pitch 串级闭环,位置环反馈为 AHRS Roll(legacy 语义) */
|
/* Pitch 串级闭环,位置环反馈为 AHRS Roll */
|
||||||
|
#if 0
|
||||||
|
/* ===== 2026-10-15 台架调参临时改动(已停用,保留备查) =====
|
||||||
|
* 启用时:先算编码器角与上下软限位,做台架偏置的限位安全门控(轴距限位
|
||||||
|
* 不足 GIMBAL_BENCH_PITCH_SAFE_MARGIN_DEG 时不施加阶跃),并把下面一行
|
||||||
|
* 改为 pitch_angle_pid.Need_Value = pitch_target_deg + pitch_applied_offset; */
|
||||||
|
const float pitch_ecd_deg = ((float)motor_pitch_gimbal.fdb.raw_angle -
|
||||||
|
(float)PITCH_GM6020_ENCODER_ZERO) * (360.0f / 8192.0f);
|
||||||
|
const float pitch_lim_up_deg = ((float)PITCH_GM6020_POSITION_UPPER_LIMIT -
|
||||||
|
(float)PITCH_GM6020_ENCODER_ZERO) * (360.0f / 8192.0f);
|
||||||
|
const float pitch_lim_dn_deg = ((float)PITCH_GM6020_POSITION_LOWER_LIMIT -
|
||||||
|
(float)PITCH_GM6020_ENCODER_ZERO) * (360.0f / 8192.0f);
|
||||||
|
pitch_applied_offset = gimbal_bench_pitch_offset;
|
||||||
|
if (pitch_ecd_deg < pitch_lim_up_deg + GIMBAL_BENCH_PITCH_SAFE_MARGIN_DEG ||
|
||||||
|
pitch_ecd_deg > pitch_lim_dn_deg - GIMBAL_BENCH_PITCH_SAFE_MARGIN_DEG)
|
||||||
|
pitch_applied_offset = 0.0f;
|
||||||
|
#endif
|
||||||
pitch_angle_pid.Need_Value = pitch_target_deg;
|
pitch_angle_pid.Need_Value = pitch_target_deg;
|
||||||
PID_PositionCalc(&pitch_angle_pid, att_deg_roll);
|
PID_PositionCalc(&pitch_angle_pid, -att_deg_roll);
|
||||||
pitch_speed_pid.Need_Value = pitch_angle_pid.OUT;
|
pitch_speed_pid.Need_Value = pitch_angle_pid.OUT;
|
||||||
PID_PositionCalc(&pitch_speed_pid, motor_pitch_gimbal.fdb.rotor_speed);
|
PID_PositionCalc(&pitch_speed_pid, motor_pitch_gimbal.fdb.rotor_speed);
|
||||||
pitch_voltage = pitch_speed_pid.OUT;
|
pitch_pid = pitch_speed_pid.OUT;
|
||||||
|
|
||||||
/* 发送:CAN2 0x1FF 槽1 = Yaw 电压;CAN1 0x1FF 槽2 = Pitch 电压,槽3 = 拨弹电流 */
|
/* Pitch 重力拟合前馈补偿:
|
||||||
dji_motor_send_current_high(&hcan2, (int16_t)yaw_voltage, 0, 0, 0);
|
* a 为当前物理编码值减去 3200*360/8192 的数值(折算为弧度送入三角函数)
|
||||||
dji_motor_send_current_high(&hcan1, 0, (int16_t)pitch_voltage, rammer_current_shared, 0);
|
* I = 3105.88 * cos(a) + 3565.50 * sin(a) + 64.31
|
||||||
|
* 最终电流输出 pitch_out = pitch_pid + pitch_g (速度环不代入 pitch_g) */
|
||||||
|
const float a_deg = ((float)motor_pitch_gimbal.fdb.raw_angle - GIMBAL_PITCH_GRAVITY_ZERO_ECD) * (360.0f / 8192.0f);
|
||||||
|
const float a_rad = a_deg * ANGLE_TO_RAD;
|
||||||
|
pitch_g = GIMBAL_PITCH_GRAVITY_K_COS * cosf(a_rad) +
|
||||||
|
GIMBAL_PITCH_GRAVITY_K_SIN * sinf(a_rad) +
|
||||||
|
GIMBAL_PITCH_GRAVITY_K_CONST;
|
||||||
|
|
||||||
|
pitch_current = pitch_pid + pitch_g;
|
||||||
|
if (pitch_current > 16384.0f)
|
||||||
|
pitch_current = 16384.0f;
|
||||||
|
else if (pitch_current < -16384.0f)
|
||||||
|
pitch_current = -16384.0f;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* ===== 2026-10-15 台架调参临时改动:Pitch 软限位/堵转保护(已停用,保留备查) =====
|
||||||
|
* 背景:原设计的上下限位只作用于遥控输入路径(robot_cmd_task),控制环自身的
|
||||||
|
* 目标角/前馈没有任何限位约束。台架烧录会失力矩十几秒~几分钟,轴会掉到限位,
|
||||||
|
* 若不加保护,原逻辑会持续输出大电流顶着限位(GM6020 直驱堵转 = 持续过载发热)。
|
||||||
|
* 做法:越限位时只允许"离开限位"方向的电流(正电流 = 抬头/编码器减小,故下限位
|
||||||
|
* 只留正向、上限位只留负向),反方向清零;限位外连续 GIMBAL_PITCH_LIMIT_STALL_MS
|
||||||
|
* 编码器不动则判堵转,电流降到涓流上限。轴回到软限位内后闭环自动恢复正常。 */
|
||||||
|
if (pitch_ecd_deg >= pitch_lim_dn_deg || pitch_ecd_deg <= pitch_lim_up_deg)
|
||||||
|
{
|
||||||
|
/* 堵转计时:相对基准编码值移动超过 10 个刻度(0.44°)才算"在动"。
|
||||||
|
* 阈值取 10 而不是 2:陀螺/结构微振会让编码器抖 2~3 个刻度,阈值太小会把
|
||||||
|
* 静止误判成在动,保护永远不生效(实测踩过);慢速抬升 5°/s 在 300ms 内
|
||||||
|
* 也能走 34 个刻度,不会被误判。 */
|
||||||
|
static uint16_t lim_stall = 0;
|
||||||
|
static uint16_t lim_ref_ecd = 0;
|
||||||
|
const int16_t d_ecd = (int16_t)((int16_t)motor_pitch_gimbal.fdb.raw_angle -
|
||||||
|
(int16_t)lim_ref_ecd);
|
||||||
|
if (d_ecd > 10 || d_ecd < -10)
|
||||||
|
{
|
||||||
|
lim_ref_ecd = motor_pitch_gimbal.fdb.raw_angle;
|
||||||
|
lim_stall = 0;
|
||||||
|
}
|
||||||
|
else if (lim_stall < 60000u)
|
||||||
|
lim_stall++;
|
||||||
|
|
||||||
|
const float cap = (lim_stall * 2u >= (uint16_t)GIMBAL_PITCH_LIMIT_STALL_MS)
|
||||||
|
? GIMBAL_PITCH_LIMIT_CURRENT
|
||||||
|
: GIMBAL_PITCH_LIMIT_CURRENT_RECOVER;
|
||||||
|
|
||||||
|
if (pitch_ecd_deg >= pitch_lim_dn_deg) /* 轴过低:只许抬升 */
|
||||||
|
{
|
||||||
|
if (pitch_current < 0.0f)
|
||||||
|
pitch_current = 0.0f;
|
||||||
|
else if (pitch_current > cap)
|
||||||
|
pitch_current = cap;
|
||||||
|
}
|
||||||
|
else /* 轴过高:只许下压 */
|
||||||
|
{
|
||||||
|
if (pitch_current > 0.0f)
|
||||||
|
pitch_current = 0.0f;
|
||||||
|
else if (pitch_current < -cap)
|
||||||
|
pitch_current = -cap;
|
||||||
|
}
|
||||||
|
PID_PositionClean(&pitch_speed_pid);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* ===== 停用块结束 ===== */
|
||||||
|
|
||||||
|
/* 发送:CAN2 0x1FE 槽1 = Yaw 电流;CAN1 0x1FE 槽2 = Pitch 电流 */
|
||||||
|
dji_motor_send_gm6020_current_low(&hcan2, (int16_t)yaw_current, 0, 0, 0);
|
||||||
|
dji_motor_send_gm6020_current_low(&hcan1, 0, (int16_t)pitch_current, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shoot_share_rammer_current(int16_t current)
|
#if 0
|
||||||
|
/* ===== 2026-10-15 台架调参临时接口(已停用,保留备查) ===== */
|
||||||
|
/* Pitch 位置环实际设定值(°) = 真实目标角 + 经限位门控后的台架偏置 */
|
||||||
|
float gimbal_pitch_setpoint_deg(void)
|
||||||
{
|
{
|
||||||
rammer_current_shared = current;
|
return pitch_target_deg + pitch_applied_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pitch 位置环输出 = 速度环目标(°/s),用于判断内环是否被限幅 */
|
||||||
|
float gimbal_pitch_speed_ref(void)
|
||||||
|
{
|
||||||
|
return pitch_angle_pid.OUT;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t gimbal_motor_offline(void)
|
uint8_t gimbal_motor_offline(void)
|
||||||
{
|
{
|
||||||
uint32_t now = HAL_GetTick();
|
uint32_t now = HAL_GetTick();
|
||||||
@@ -219,7 +326,8 @@ uint8_t gimbal_motor_offline(void)
|
|||||||
|
|
||||||
void gimbal_output_zero(void)
|
void gimbal_output_zero(void)
|
||||||
{
|
{
|
||||||
dji_motor_send_current_high(&hcan2, 0, 0, 0, 0);
|
dji_motor_send_gm6020_current_low(&hcan2, 0, 0, 0, 0);
|
||||||
dji_motor_send_current_high(&hcan1, 0, 0, 0, 0);
|
dji_motor_send_gm6020_current_low(&hcan1, 0, 0, 0, 0);
|
||||||
dji_motor_send_current_low(&hcan1, 0, 0, 0, 0);
|
dji_motor_send_current_low(&hcan1, 0, 0, 0, 0);
|
||||||
|
dji_motor_send_current_low(&hcan2, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
/* 云台双轴控制(串级 PID)
|
/* 云台双轴控制(串级 PID)
|
||||||
* Yaw (2026-09 重写):双环都以陀螺仪为反馈——
|
* Yaw (2026-09 重写):双环都以陀螺仪为反馈——
|
||||||
* 位置环:QEKF 多圈 yaw(°) -> 目标角速度(°/s)
|
* 位置环:QEKF 多圈 yaw(°) -> 目标角速度(°/s)
|
||||||
* 速度环:陀螺 z 轴角速度(°/s) -> GM6020 电压
|
* 速度环:陀螺 z 轴角速度(°/s) -> GM6020 电流
|
||||||
* 装配符号由上电自检自动测定(gimbal_detect_yaw_sign),
|
* 装配符号由上电自检自动测定(gimbal_detect_yaw_sign),
|
||||||
* 两环共用同一符号,不可能再出现"两传感器符号打架"
|
* 两环共用同一符号,不可能再出现"两传感器符号打架"
|
||||||
* Pitch:位置环用 QEKF 的 Roll(安装方向所致,勿改),速度环转子转速
|
* Pitch:位置环用 QEKF 的 Roll(安装方向所致,勿改),速度环转子转速
|
||||||
* 电机: Yaw=GM6020 CAN2 0x205(电压,0x1FF CAN2 槽1)
|
* 电机: Yaw=GM6020 CAN2 0x205(电流,0x1FE CAN2 槽1)
|
||||||
* Pitch=GM6020 CAN1 0x206(电压,与拨弹共帧 0x1FF CAN1 槽2/3,legacy 方案)
|
* Pitch=GM6020 CAN1 0x206(电流,0x1FE CAN1 槽2)
|
||||||
* 摩擦轮 M3508 0x201/0x202 与拨弹 M2006 0x207 的实例也在此初始化 */
|
* 摩擦轮 M3508 0x201/0x202(CAN1) 与拨弹 M2006 0x201(CAN2) 的实例也在此初始化 */
|
||||||
|
|
||||||
#include "dji_motor.h"
|
#include "dji_motor.h"
|
||||||
|
|
||||||
@@ -19,12 +19,15 @@ extern dji_motor_t motor_yaw_gimbal; // Yaw GM6020,CAN2 0x205
|
|||||||
extern dji_motor_t motor_pitch_gimbal; // Pitch GM6020,CAN1 0x206
|
extern dji_motor_t motor_pitch_gimbal; // Pitch GM6020,CAN1 0x206
|
||||||
extern dji_motor_t motor_friction_l; // 左摩擦轮 M3508,CAN1 0x201
|
extern dji_motor_t motor_friction_l; // 左摩擦轮 M3508,CAN1 0x201
|
||||||
extern dji_motor_t motor_friction_r; // 右摩擦轮 M3508,CAN1 0x202
|
extern dji_motor_t motor_friction_r; // 右摩擦轮 M3508,CAN1 0x202
|
||||||
extern dji_motor_t motor_rammer; // 拨弹 M2006,CAN1 0x207
|
extern dji_motor_t motor_rammer; // 拨弹 M2006,CAN2 0x201
|
||||||
|
extern float pitch_pid; // Pitch PID 输出分量(仅速度环反馈计算)
|
||||||
|
extern float pitch_g; // Pitch 重力拟合前馈分量
|
||||||
|
extern float pitch_current; // Pitch GM6020 最终电流控制输出(pitch_pid + pitch_g, ±16384)
|
||||||
|
|
||||||
/* 初始化电机实例与 PID(can_start 之后调用) */
|
/* 初始化电机实例与 PID(can_start 之后调用) */
|
||||||
extern void gimbal_motor_init(void);
|
extern void gimbal_motor_init(void);
|
||||||
|
|
||||||
/* Yaw 装配符号自检:给 Yaw 电机正向小电压脉冲,按陀螺 z 轴响应方向
|
/* Yaw 装配符号自检:给 Yaw 电机正向小电流脉冲,按陀螺 z 轴响应方向
|
||||||
* 测定符号。阻塞约 200ms(HAL_Delay),检测期间云台会轻转几度。
|
* 测定符号。阻塞约 200ms(HAL_Delay),检测期间云台会轻转几度。
|
||||||
* 返回 1-成功(gimbal_yaw_sign() 可用) 0-失败(被按住/电机离线/无响应) */
|
* 返回 1-成功(gimbal_yaw_sign() 可用) 0-失败(被按住/电机离线/无响应) */
|
||||||
extern uint8_t gimbal_detect_yaw_sign(void);
|
extern uint8_t gimbal_detect_yaw_sign(void);
|
||||||
@@ -36,13 +39,22 @@ extern float gimbal_yaw_sign(void);
|
|||||||
* 0=尚未自检。随 0x1A9 flags bit1 下发,供底盘跟随符号自动综合 */
|
* 0=尚未自检。随 0x1A9 flags bit1 下发,供底盘跟随符号自动综合 */
|
||||||
extern int8_t gimbal_encoder_ccw(void);
|
extern int8_t gimbal_encoder_ccw(void);
|
||||||
|
|
||||||
/* 云台轴控制:根据 cmd 增量更新目标角并计算电压输出(2ms 调用)
|
/* 云台轴控制:根据 cmd 增量更新目标角并计算电流输出(2ms 调用)
|
||||||
* 内部发送 CAN2 0x1FF(Yaw)与 CAN1 0x1FF(Pitch+拨弹) */
|
* 内部发送 CAN2 0x1FE(Yaw)与 CAN1 0x1FE(Pitch) */
|
||||||
extern void gimbal_control(float yaw_delta, float pitch_delta, uint8_t reset_flag);
|
extern void gimbal_control(float yaw_delta, float pitch_delta, uint8_t reset_flag);
|
||||||
|
|
||||||
/* 云台任一电机掉线返回 1 */
|
/* 云台任一电机掉线返回 1 */
|
||||||
extern uint8_t gimbal_motor_offline(void);
|
extern uint8_t gimbal_motor_offline(void);
|
||||||
|
|
||||||
|
/* ===== 2026-10-15 台架调参临时接口(已停用,保留备查) =====
|
||||||
|
* 启用时把 #if 0 改 #if 1,并同步启用 gimbal.c / gimbal_task.c / robot_param.h
|
||||||
|
* / debug_task.c 里的同名停用块 */
|
||||||
|
#if 0
|
||||||
|
extern float gimbal_bench_pitch_offset; // 位置环设定值附加偏置(°),台架方波发生器写入
|
||||||
|
extern float gimbal_pitch_setpoint_deg(void); // 位置环实际设定值(°),供调参遥测读取
|
||||||
|
extern float gimbal_pitch_speed_ref(void); // 位置环输出=速度环目标(°/s),判断内环是否限幅
|
||||||
|
#endif
|
||||||
|
|
||||||
/* 云台输出清零(停车) */
|
/* 云台输出清零(停车) */
|
||||||
extern void gimbal_output_zero(void);
|
extern void gimbal_output_zero(void);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
* shoot.c - 发射机构:摩擦轮 2xM3508(0x200 CAN1 槽1/2)+ 拨弹 M2006
|
* shoot.c - 发射机构:摩擦轮 2xM3508(0x200 CAN1 槽1/2)+ 拨弹 M2006(0x200 CAN2 槽1)
|
||||||
* 逻辑(与 legacy 一致):
|
* 逻辑(与 legacy 一致):
|
||||||
* 摩擦轮开关受发射机构上电状态门控(可由 DEBUG_SHOOT_WITHOUT_REFEREE 绕过),
|
* 摩擦轮开关受发射机构上电状态门控(可由 DEBUG_SHOOT_WITHOUT_REFEREE 绕过),
|
||||||
* 开启时联动激光(PC8=TIM3_CH3 PWM,占空比 0/满 对应关/开)
|
* 开启时联动激光(PC8=TIM3_CH3 PWM,占空比 0/满 对应关/开)
|
||||||
* 拨弹仅在摩擦轮开启后允许;fire=GIMBAL_RAMMER_SPEED(-5400),eject 反向
|
* 拨弹仅在摩擦轮开启后允许;fire=GIMBAL_RAMMER_SPEED(-5400),eject 反向
|
||||||
* 拨弹电流经 shoot_share_rammer_current() 交给云台共帧发送(0x1FF CAN1)
|
* 拨弹电流经 shoot_send_cmd() 经 CAN2 0x200 帧直接发送(ID 1)
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "shoot.h"
|
#include "shoot.h"
|
||||||
#include "gimbal.h"
|
#include "gimbal.h"
|
||||||
@@ -43,7 +43,7 @@ void shoot_init(void)
|
|||||||
PID_PositionStructureInit(&rammer_pid, GIMBAL_RAMMER_SPEED);
|
PID_PositionStructureInit(&rammer_pid, GIMBAL_RAMMER_SPEED);
|
||||||
PID_PositionSetParameter(&rammer_pid, GIMBAL_RAMMER_KP, GIMBAL_RAMMER_KI, GIMBAL_RAMMER_KD);
|
PID_PositionSetParameter(&rammer_pid, GIMBAL_RAMMER_KP, GIMBAL_RAMMER_KI, GIMBAL_RAMMER_KD);
|
||||||
PID_PositionSetEkRange(&rammer_pid, -20, 20);
|
PID_PositionSetEkRange(&rammer_pid, -20, 20);
|
||||||
PID_PositionSetOUTRange(&rammer_pid, -30000, 30000);
|
PID_PositionSetOUTRange(&rammer_pid, -10000, 10000);
|
||||||
|
|
||||||
laser_init();
|
laser_init();
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ void shoot_control(uint8_t friction_on, uint8_t fire, uint8_t eject, uint8_t sho
|
|||||||
shoot_friction_flag = 0;
|
shoot_friction_flag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 拨弹:仅在摩擦轮开启时允许 */
|
/* 拨弹:仅在摩擦轮开启后允许 */
|
||||||
if (shoot_friction_flag)
|
if (shoot_friction_flag)
|
||||||
{
|
{
|
||||||
if (fire)
|
if (fire)
|
||||||
@@ -83,19 +83,20 @@ void shoot_control(uint8_t friction_on, uint8_t fire, uint8_t eject, uint8_t sho
|
|||||||
PID_PositionCalc(&friction_l_pid, motor_friction_l.fdb.rotor_speed);
|
PID_PositionCalc(&friction_l_pid, motor_friction_l.fdb.rotor_speed);
|
||||||
PID_PositionCalc(&friction_r_pid, motor_friction_r.fdb.rotor_speed);
|
PID_PositionCalc(&friction_r_pid, motor_friction_r.fdb.rotor_speed);
|
||||||
PID_PositionCalc(&rammer_pid, motor_rammer.fdb.rotor_speed);
|
PID_PositionCalc(&rammer_pid, motor_rammer.fdb.rotor_speed);
|
||||||
|
|
||||||
/* 拨弹电流交给云台控制帧统一发送(0x1FF CAN1 共帧) */
|
|
||||||
shoot_share_rammer_current((int16_t)rammer_pid.OUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shoot_send_cmd(void)
|
void shoot_send_cmd(void)
|
||||||
{
|
{
|
||||||
|
/* 摩擦轮 2×M3508:CAN1 0x200 槽1/2 */
|
||||||
dji_motor_send_current_low(&hcan1, (int16_t)friction_l_pid.OUT, (int16_t)friction_r_pid.OUT, 0, 0);
|
dji_motor_send_current_low(&hcan1, (int16_t)friction_l_pid.OUT, (int16_t)friction_r_pid.OUT, 0, 0);
|
||||||
|
/* 拨弹盘 M2006(ID 1):CAN2 0x200 槽1 */
|
||||||
|
dji_motor_send_current_low(&hcan2, (int16_t)rammer_pid.OUT, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shoot_output_zero(void)
|
void shoot_output_zero(void)
|
||||||
{
|
{
|
||||||
dji_motor_send_current_low(&hcan1, 0, 0, 0, 0);
|
dji_motor_send_current_low(&hcan1, 0, 0, 0, 0);
|
||||||
|
dji_motor_send_current_low(&hcan2, 0, 0, 0, 0);
|
||||||
LASER_OFF();
|
LASER_OFF();
|
||||||
shoot_friction_flag = 0;
|
shoot_friction_flag = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* 发射机构:摩擦轮 2×M3508(0x200 CAN1 槽1/2)+ 拨弹 M2006(电流由云台共帧发送)
|
/* 发射机构:摩擦轮 2×M3508(0x200 CAN1 槽1/2)+ 拨弹 M2006(0x200 CAN2 槽1)
|
||||||
* 摩擦轮开启时联动激光(PC8,经 TIM3 CH3 PWM) */
|
* 摩擦轮开启时联动激光(PC8,经 TIM3 CH3 PWM) */
|
||||||
|
|
||||||
/* 初始化摩擦轮/拨弹 PID(can_start 之后调用) */
|
/* 初始化摩擦轮/拨弹 PID(can_start 之后调用) */
|
||||||
@@ -14,7 +14,7 @@ extern void shoot_init(void);
|
|||||||
* shooter_power_on:发射机构上电状态(来自底盘 0x019) */
|
* shooter_power_on:发射机构上电状态(来自底盘 0x019) */
|
||||||
extern void shoot_control(uint8_t friction_on, uint8_t fire, uint8_t eject, uint8_t shooter_power_on);
|
extern void shoot_control(uint8_t friction_on, uint8_t fire, uint8_t eject, uint8_t shooter_power_on);
|
||||||
|
|
||||||
/* 发送摩擦轮电流帧(0x200 CAN1) */
|
/* 发送摩擦轮(0x200 CAN1)与拨弹(0x200 CAN2)电流帧 */
|
||||||
extern void shoot_send_cmd(void);
|
extern void shoot_send_cmd(void);
|
||||||
|
|
||||||
/* 摩擦轮输出清零 */
|
/* 摩擦轮输出清零 */
|
||||||
@@ -23,6 +23,4 @@ extern void shoot_output_zero(void);
|
|||||||
/* 摩擦轮当前开关状态(供激光联动与调试) */
|
/* 摩擦轮当前开关状态(供激光联动与调试) */
|
||||||
extern uint8_t shoot_friction_flag;
|
extern uint8_t shoot_friction_flag;
|
||||||
|
|
||||||
/* 拨弹电流写入共享变量(由 shoot 模块调用,云台共帧发送) */
|
|
||||||
extern void shoot_share_rammer_current(int16_t current);
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,9 +6,8 @@
|
|||||||
* (无 legacy 的 +-1 圈限制,底盘小陀螺时 Yaw 可连续旋转),
|
* (无 legacy 的 +-1 圈限制,底盘小陀螺时 Yaw 可连续旋转),
|
||||||
* 记录 last_online_tick 供掉线检测
|
* 记录 last_online_tick 供掉线检测
|
||||||
* 控制路径(任务上下文):
|
* 控制路径(任务上下文):
|
||||||
* dji_motor_send_current_low/high() 0x200 / 0x1FF 电流帧(+/-16384 = 20A/10A)
|
* dji_motor_send_current_low/high() 0x200 / 0x1FF 电流帧(+/-16384 = 20A/10A)
|
||||||
* dji_motor_send_voltage_high() 0x2FF 电压帧(GM6020 ID5~7)
|
* dji_motor_send_gm6020_current_low/high() 0x1FE / 0x2FE GM6020 电流帧(+/-16384 = 3A)
|
||||||
* 注意 0x1FF 帧为 M3508/M2006 高位电流与 GM6020 低位电压共用,按槽位区分
|
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "dji_motor.h"
|
#include "dji_motor.h"
|
||||||
|
|
||||||
@@ -20,7 +19,8 @@
|
|||||||
static dji_motor_t * dji_motor_list[DJI_MOTOR_MAX];
|
static dji_motor_t * dji_motor_list[DJI_MOTOR_MAX];
|
||||||
static uint8_t dji_motor_count = 0;
|
static uint8_t dji_motor_count = 0;
|
||||||
|
|
||||||
static void dji_motor_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc);
|
static void dji_motor_can1_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc);
|
||||||
|
static void dji_motor_can2_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc);
|
||||||
|
|
||||||
/* 解析一帧反馈,多圈累计(无 ±1 圈限制,底盘小陀螺时 Yaw 电机可连续旋转) */
|
/* 解析一帧反馈,多圈累计(无 ±1 圈限制,底盘小陀螺时 Yaw 电机可连续旋转) */
|
||||||
static void dji_motor_parse(dji_motor_t * motor, const uint8_t data[8])
|
static void dji_motor_parse(dji_motor_t * motor, const uint8_t data[8])
|
||||||
@@ -71,16 +71,32 @@ void dji_motor_init(dji_motor_t * motor, hcan_t * hcan, uint16_t rx_id, dji_moto
|
|||||||
if (dji_motor_count < DJI_MOTOR_MAX)
|
if (dji_motor_count < DJI_MOTOR_MAX)
|
||||||
{
|
{
|
||||||
dji_motor_list[dji_motor_count++] = motor;
|
dji_motor_list[dji_motor_count++] = motor;
|
||||||
can_rx_register(hcan, rx_id, dji_motor_rx_callback);
|
if (hcan == &hcan1)
|
||||||
|
can_rx_register(hcan, rx_id, dji_motor_can1_rx_callback);
|
||||||
|
else
|
||||||
|
can_rx_register(hcan, rx_id, dji_motor_can2_rx_callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dji_motor_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
|
static void dji_motor_can1_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
|
||||||
{
|
{
|
||||||
(void)dlc;
|
(void)dlc;
|
||||||
for (uint8_t i = 0; i < dji_motor_count; i++)
|
for (uint8_t i = 0; i < dji_motor_count; i++)
|
||||||
{
|
{
|
||||||
if (dji_motor_list[i]->rx_id == std_id)
|
if (dji_motor_list[i]->hcan == &hcan1 && dji_motor_list[i]->rx_id == std_id)
|
||||||
|
{
|
||||||
|
dji_motor_parse(dji_motor_list[i], rx_data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dji_motor_can2_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
|
||||||
|
{
|
||||||
|
(void)dlc;
|
||||||
|
for (uint8_t i = 0; i < dji_motor_count; i++)
|
||||||
|
{
|
||||||
|
if (dji_motor_list[i]->hcan == &hcan2 && dji_motor_list[i]->rx_id == std_id)
|
||||||
{
|
{
|
||||||
dji_motor_parse(dji_motor_list[i], rx_data);
|
dji_motor_parse(dji_motor_list[i], rx_data);
|
||||||
return;
|
return;
|
||||||
@@ -119,8 +135,14 @@ void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t
|
|||||||
dji_motor_send_int16x4(hcan, 0x1FF, v);
|
dji_motor_send_int16x4(hcan, 0x1FF, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dji_motor_send_voltage_high(hcan_t * hcan, int16_t v5, int16_t v6, int16_t v7)
|
void dji_motor_send_gm6020_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4)
|
||||||
{
|
{
|
||||||
const int16_t v[4] = {v5, v6, v7, 0};
|
const int16_t v[4] = {i1, i2, i3, i4};
|
||||||
dji_motor_send_int16x4(hcan, 0x2FF, v);
|
dji_motor_send_int16x4(hcan, 0x1FE, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dji_motor_send_gm6020_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8)
|
||||||
|
{
|
||||||
|
const int16_t v[4] = {i5, i6, i7, i8};
|
||||||
|
dji_motor_send_int16x4(hcan, 0x2FE, v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
/* DJI 电机(M3508/M2006/GM6020)统一驱动
|
/* DJI 电机(M3508/M2006/GM6020)统一驱动
|
||||||
* - 反馈:can_start() 后通过 can_rx_register 按 rx_id 注册,接收中断内解析(多圈累计)
|
* - 反馈:can_start() 后通过 can_rx_register 按 rx_id 注册,接收中断内解析(多圈累计)
|
||||||
* - 控制:组装 0x200/0x1FF/0x2FF 控制帧,经 CAN_SendTxMessage 发送 */
|
* - 控制:组装 0x200/0x1FF/0x1FE/0x2FE 控制帧,经 CAN_SendTxMessage 发送 */
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
DJI_MOTOR_3508, // 减速比 3591:187(≈19:1), 转矩常数 0.3N·m/A
|
DJI_MOTOR_3508, // 减速比 3591:187(≈19:1), 转矩常数 0.3N·m/A
|
||||||
DJI_MOTOR_2006, // 减速比 36:1, 转矩常数 0.18N·m/A
|
DJI_MOTOR_2006, // 减速比 36:1, 转矩常数 0.18N·m/A
|
||||||
DJI_MOTOR_6020, // 直驱, 电压控制
|
DJI_MOTOR_6020, // 直驱, 电流控制(ID1~4 为 0x1FE 帧, ±16384 对应 ±3A)
|
||||||
} dji_motor_type_e;
|
} dji_motor_type_e;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -20,7 +20,7 @@ typedef struct
|
|||||||
int64_t total_tick; // 累计角度位置原始数据(8192*圈数+raw,无 ±1 圈限制)
|
int64_t total_tick; // 累计角度位置原始数据(8192*圈数+raw,无 ±1 圈限制)
|
||||||
float rotor_angle_deg; // 累计转子机械角(°)
|
float rotor_angle_deg; // 累计转子机械角(°)
|
||||||
int16_t rotor_speed; // 转子转速(RPM)
|
int16_t rotor_speed; // 转子转速(RPM)
|
||||||
int16_t raw_torque; // 转矩电流/转矩电压原始数据
|
int16_t raw_torque; // 转矩电流原始数据
|
||||||
float torque_current; // 转矩电流(A)
|
float torque_current; // 转矩电流(A)
|
||||||
uint8_t temperature; // 电机温度(℃)
|
uint8_t temperature; // 电机温度(℃)
|
||||||
uint32_t last_online_tick; // 最近一次收到反馈的 tick(HAL_GetTick)
|
uint32_t last_online_tick; // 最近一次收到反馈的 tick(HAL_GetTick)
|
||||||
@@ -39,11 +39,12 @@ extern void dji_motor_init(dji_motor_t * motor, hcan_t * hcan, uint16_t rx_id, d
|
|||||||
|
|
||||||
/* ---- 控制帧发送 ----
|
/* ---- 控制帧发送 ----
|
||||||
* M3508/M2006 ID1~4:0x200 电流帧(±16384 对应 ±20A/±10A)
|
* M3508/M2006 ID1~4:0x200 电流帧(±16384 对应 ±20A/±10A)
|
||||||
* M3508/M2006 ID5~8:0x1FF 电流帧;GM6020 ID1~4:0x1FF 电压帧(±25000)
|
* M3508/M2006 ID5~8:0x1FF 电流帧(±16384)
|
||||||
* GM6020 ID5~7:0x2FF 电压帧 */
|
* GM6020 电流控制:ID1~4 为 0x1FE 电流帧(±16384 对应 ±3A),ID5~8 为 0x2FE 电流帧(±16384) */
|
||||||
extern void dji_motor_send_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
extern void dji_motor_send_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
||||||
extern void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
extern void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
||||||
extern void dji_motor_send_voltage_high(hcan_t * hcan, int16_t v5, int16_t v6, int16_t v7);
|
extern void dji_motor_send_gm6020_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
||||||
|
extern void dji_motor_send_gm6020_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
||||||
|
|
||||||
/* 通用 int16x4 发送(板间通讯等复用) */
|
/* 通用 int16x4 发送(板间通讯等复用) */
|
||||||
extern void dji_motor_send_int16x4(hcan_t * hcan, uint32_t std_id, const int16_t val[4]);
|
extern void dji_motor_send_int16x4(hcan_t * hcan, uint32_t std_id, const int16_t val[4]);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
* debug_task.c - USB 虚拟串口(CDC)姿态输出(欧拉角 + 姿态链路诊断)
|
* debug_task.c - USB 虚拟串口(CDC)姿态输出(欧拉角 + 姿态链路诊断 + 控制量/模式)
|
||||||
* 每 DEBUG_OUT_PERIOD_MS 输出一行。单位: 角度 ° / 加速度 m/s² / 角速度 rad/s
|
* 每 DEBUG_OUT_PERIOD_MS 输出一行。单位: 角度 ° / 加速度 m/s² / 角速度 rad/s
|
||||||
*
|
*
|
||||||
* ---- 欧拉角(QuaternionEKF 解算结果,见 modules/ins) ----
|
* ---- 欧拉角(QuaternionEKF 解算结果,见 modules/ins) ----
|
||||||
@@ -25,7 +25,20 @@
|
|||||||
* se bmi088_spi_errors:SPI/DMA 出错次数;st=bmi088_spi_state()
|
* se bmi088_spi_errors:SPI/DMA 出错次数;st=bmi088_spi_state()
|
||||||
* (1=READY,非 1 说明 SPI 被卡住,数据路会因此停摆)
|
* (1=READY,非 1 说明 SPI 被卡住,数据路会因此停摆)
|
||||||
*
|
*
|
||||||
* 开关: DEBUG_ATT_HEALTH=0 只输出三个欧拉角;DEBUG_ATT_DIAG=0 去掉诊断位。
|
* ---- 控制量 / 控制模式(DEBUG_CMD_OUT=1 时追加) ----
|
||||||
|
* mode 底盘模式 0=OFF 1=MANUAL 2=FOLLOW 3=SPIN_SLOW 4=SPIN_FAST
|
||||||
|
* (由本板依据收到的 s2/spin 推出;模式逻辑见 robot_cmd_task.c)
|
||||||
|
* online 1=板间通讯(CToC)在线 —— 本板唯一的"控制源在线"判据
|
||||||
|
* vx/vy 底盘平移速度指令(世界系映射值) wz [已废弃,恒 0]
|
||||||
|
* spin **收到的**小陀螺使能(0x189 bit2,云台侧做 Ctrl 沿检测)
|
||||||
|
* s2 **收到的**遥控 S2 档位(小陀螺为真时它被覆盖)
|
||||||
|
* reset 跟随朝向重锁请求(跟随模式重连时置位)
|
||||||
|
* 注意:本板拿不到"遥控器还是键鼠"这一信息——0x149/0x189 不带该位,
|
||||||
|
* robot_cmd_task 里 cmd_robot.source 恒被置 0,故这里不输出假字段。
|
||||||
|
* 与姿态同源(cmd_robot/ctoc_remote),一起看才能判断"模式对不对、量给没给"。
|
||||||
|
*
|
||||||
|
* 开关: DEBUG_ATT_HEALTH=0 只输出三个欧拉角;DEBUG_ATT_DIAG=0 去掉诊断位;
|
||||||
|
* DEBUG_CMD_OUT=1 追加控制量/控制模式。
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "debug_task.h"
|
#include "debug_task.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
@@ -35,6 +48,8 @@
|
|||||||
#include "attitude.h"
|
#include "attitude.h"
|
||||||
#include "ins.h"
|
#include "ins.h"
|
||||||
#include "bmi088.h"
|
#include "bmi088.h"
|
||||||
|
#include "robot_typedef.h"
|
||||||
|
#include "c_comm.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -42,13 +57,31 @@
|
|||||||
#define DEBUG_ATT_HEALTH 1
|
#define DEBUG_ATT_HEALTH 1
|
||||||
/* 1-再附加原始陀螺/零偏/采样计数(排障用); 0-只留上面的通用健康位 */
|
/* 1-再附加原始陀螺/零偏/采样计数(排障用); 0-只留上面的通用健康位 */
|
||||||
#define DEBUG_ATT_DIAG 1
|
#define DEBUG_ATT_DIAG 1
|
||||||
|
/* 1-追加控制量/控制模式(见文件头); 0-保持原姿态输出不变 */
|
||||||
|
#define DEBUG_CMD_OUT 1
|
||||||
|
|
||||||
/* 输出周期(ms)。姿态观测建议 100ms(10Hz) */
|
/* 输出周期(ms)。姿态观测建议 100ms(10Hz) */
|
||||||
#define DEBUG_OUT_PERIOD_MS 100
|
#define DEBUG_OUT_PERIOD_MS 100
|
||||||
|
|
||||||
|
#if DEBUG_CMD_OUT
|
||||||
|
/* 底盘模式名(便于人读;数值定义见 robot_typedef.h 的 chassis_mode_e) */
|
||||||
|
static const char * cmd_mode_name(chassis_mode_e m)
|
||||||
|
{
|
||||||
|
switch (m)
|
||||||
|
{
|
||||||
|
case CHASSIS_MODE_OFF: return "OFF";
|
||||||
|
case CHASSIS_MODE_MANUAL: return "MANUAL";
|
||||||
|
case CHASSIS_MODE_FOLLOW: return "FOLLOW";
|
||||||
|
case CHASSIS_MODE_SPIN_SLOW: return "SPIN_SLOW";
|
||||||
|
case CHASSIS_MODE_SPIN_FAST: return "SPIN_FAST";
|
||||||
|
default: return "?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void debug_task(void const * argument)
|
void debug_task(void const * argument)
|
||||||
{
|
{
|
||||||
char line[192];
|
char line[448];
|
||||||
char tail[112];
|
char tail[112];
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
@@ -70,15 +103,29 @@ void debug_task(void const * argument)
|
|||||||
(unsigned long)bmi088_spi_errors, (unsigned)bmi088_spi_state());
|
(unsigned long)bmi088_spi_errors, (unsigned)bmi088_spi_state());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG_CMD_OUT
|
||||||
|
char ctl[192];
|
||||||
|
snprintf(ctl, sizeof(ctl),
|
||||||
|
" mode=%s online=%u vx=%.3f vy=%.3f wz=%.3f spin=%u s2=%u reset=%u",
|
||||||
|
cmd_mode_name(cmd_robot.chassis_mode),
|
||||||
|
(unsigned)cmd_robot.online,
|
||||||
|
cmd_robot.vx, cmd_robot.vy, cmd_robot.wz_manual,
|
||||||
|
(unsigned)ctoc_remote.spin_flag,
|
||||||
|
(unsigned)ctoc_remote.s2,
|
||||||
|
(unsigned)cmd_robot.gimbal_reset);
|
||||||
|
#else
|
||||||
|
const char * ctl = "";
|
||||||
|
#endif
|
||||||
|
|
||||||
#if DEBUG_ATT_HEALTH
|
#if DEBUG_ATT_HEALTH
|
||||||
int len = snprintf(line, sizeof(line),
|
int len = snprintf(line, sizeof(line),
|
||||||
"yaw=%.2f pitch=%.2f roll=%.2f cvg=%u rdy=%u imu=%u an=%.2f gn=%.3f%s\r\n",
|
"yaw=%.2f pitch=%.2f roll=%.2f cvg=%u rdy=%u imu=%u an=%.2f gn=%.3f%s%s\r\n",
|
||||||
att_deg_yaw, att_deg_pitch, att_deg_roll,
|
att_deg_yaw, att_deg_pitch, att_deg_roll,
|
||||||
(unsigned)INS.ConvergeFlag, (unsigned)att_ready,
|
(unsigned)INS.ConvergeFlag, (unsigned)att_ready,
|
||||||
(unsigned)bmi088_online, an, gn, tail);
|
(unsigned)bmi088_online, an, gn, tail, ctl);
|
||||||
#else
|
#else
|
||||||
int len = snprintf(line, sizeof(line), "yaw=%.2f pitch=%.2f roll=%.2f\r\n",
|
int len = snprintf(line, sizeof(line), "yaw=%.2f pitch=%.2f roll=%.2f%s\r\n",
|
||||||
att_deg_yaw, att_deg_pitch, att_deg_roll);
|
att_deg_yaw, att_deg_pitch, att_deg_roll, ctl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ static int8_t linkcheck_first_offline(void)
|
|||||||
{
|
{
|
||||||
uint32_t now = HAL_GetTick();
|
uint32_t now = HAL_GetTick();
|
||||||
#if defined(ROBOT_TYPE_GIMBAL)
|
#if defined(ROBOT_TYPE_GIMBAL)
|
||||||
/* 设备序号:0 摩擦轮L(0x201) 1 摩擦轮R(0x202) 2 Pitch(0x206)
|
/* 设备序号:0 摩擦轮L(CAN1 0x201) 1 摩擦轮R(CAN1 0x202) 2 Pitch(CAN1 0x206)
|
||||||
* 3 Yaw(0x205) 4 拨弹(0x207,安装时) 5 底盘回传(0x019) */
|
* 3 Yaw(CAN2 0x205) 4 拨弹(CAN2 0x201,安装时) 5 底盘回传(0x019) */
|
||||||
if (LINK_OFFLINE(motor_friction_l.fdb.last_online_tick))
|
if (LINK_OFFLINE(motor_friction_l.fdb.last_online_tick))
|
||||||
return 0;
|
return 0;
|
||||||
if (LINK_OFFLINE(motor_friction_r.fdb.last_online_tick))
|
if (LINK_OFFLINE(motor_friction_r.fdb.last_online_tick))
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "bsp_usart.h"
|
#include "bsp_usart.h"
|
||||||
#include "referee.h"
|
#include "referee.h"
|
||||||
|
#include "referee_ui.h"
|
||||||
|
#include "c_comm.h"
|
||||||
|
#include "attitude.h"
|
||||||
#include "robot_param.h"
|
#include "robot_param.h"
|
||||||
|
|
||||||
/* referee_task:裁判系统链路监测
|
/* referee_task:裁判系统链路监测
|
||||||
@@ -29,6 +32,37 @@ void referee_task(void const * argument)
|
|||||||
HAL_GetTick() - referee.last_update_tick > DEVICE_OFFLINE_TIME_MS * 10)
|
HAL_GetTick() - referee.last_update_tick > DEVICE_OFFLINE_TIME_MS * 10)
|
||||||
referee.link_status = 0;
|
referee.link_status = 0;
|
||||||
|
|
||||||
|
/* ---- 自定义UI:机器人 -> 裁判系统 -> 选手端 ------------------------
|
||||||
|
* 本任务 100ms 一轮,内部按 UI_SEND_HZ 分频(5Hz:约 40 图形/帧,
|
||||||
|
* 115200 链路上约 3.8KB/s)。数据来源:
|
||||||
|
* 底盘本地 = att_deg_yaw(朝向) + referee(功率/电容)
|
||||||
|
* 云台 CToC = pitch + 摩擦轮 L/R 转速(0x1B9) + 云台 yaw(0x1A9) + 陀螺位(0x189)
|
||||||
|
* ------------------------------------------------------------------ */
|
||||||
|
{
|
||||||
|
static uint8_t ui_div = 0;
|
||||||
|
if (++ui_div >= (uint8_t)(10 / UI_SEND_HZ))
|
||||||
|
{
|
||||||
|
ui_div = 0;
|
||||||
|
|
||||||
|
ui_data_t ui;
|
||||||
|
ui.pitch_deg = ctoc_ui_pitch_deg;
|
||||||
|
ui.yaw_deg = ctoc_gimbal_yaw;
|
||||||
|
ui.hdg_deg = att_deg_yaw;
|
||||||
|
ui.pwr_w = referee.chassis_power;
|
||||||
|
ui.pwr_limit_w = (float)referee.chassis_power_limit;
|
||||||
|
ui.buf_j = referee.buffer_energy;
|
||||||
|
ui.cap_pct = (uint8_t)(referee.buffer_energy >= 60.0f
|
||||||
|
? 100
|
||||||
|
: (referee.buffer_energy * 100.0f / 60.0f));
|
||||||
|
ui.fric_l_rpm = ctoc_ui_fric_l_rpm;
|
||||||
|
ui.fric_r_rpm = ctoc_ui_fric_r_rpm;
|
||||||
|
ui.spin_on = ctoc_remote.spin_flag;
|
||||||
|
ui.ref_online = referee.link_status;
|
||||||
|
|
||||||
|
referee_ui_update(&ui);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
monitor_heartbeat(HB_REFEREE);
|
monitor_heartbeat(HB_REFEREE);
|
||||||
osDelay(100);
|
osDelay(100);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ void robot_cmd_task(void const * argument)
|
|||||||
|
|
||||||
if (!keyboard_online)
|
if (!keyboard_online)
|
||||||
{
|
{
|
||||||
/* 遥控器:左摇杆,输出与摇杆偏量成比例(legacy 为过死区即全速,
|
/* 遥控器:左摇杆向上(>1050)为抬头(pitch_delta减小,pos向2260减小),门控须 pos > UPPER_LIMIT(2260);
|
||||||
* 体感过灵敏),限位门控与方向保持 legacy */
|
* 左摇杆向下(<1000)为低头(pitch_delta增大,pos向3950增大),门控须 pos < LOWER_LIMIT(3950) */
|
||||||
if (dr16.rc_l_UD > 1050 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
if (dr16.rc_l_UD > 1050 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
||||||
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
||||||
((float)dr16.rc_l_UD - 1024.0f) / 660.0f;
|
((float)dr16.rc_l_UD - 1024.0f) / 660.0f;
|
||||||
@@ -113,13 +113,13 @@ void robot_cmd_task(void const * argument)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 键鼠:同改为比例输出 */
|
/* 键鼠:鼠标前推(>8)为抬头(pitch_delta减小),门控须 pos > UPPER_LIMIT;鼠标后拉(<-8)为低头(pitch_delta增大),门控须 pos < LOWER_LIMIT */
|
||||||
if (keyboard_data.mouse_du < -8 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
if (keyboard_data.mouse_du > 8 && pos > PITCH_GM6020_POSITION_UPPER_LIMIT)
|
||||||
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
pitch_delta -= GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
||||||
(-(float)keyboard_data.mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
|
||||||
else if (keyboard_data.mouse_du > 8 && pos < PITCH_GM6020_POSITION_LOWER_LIMIT)
|
|
||||||
pitch_delta += GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
|
||||||
((float)keyboard_data.mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
((float)keyboard_data.mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
||||||
|
else if (keyboard_data.mouse_du < -8 && pos < PITCH_GM6020_POSITION_LOWER_LIMIT)
|
||||||
|
pitch_delta += GIMBAL_PITCH_LEVER_RATE / 8192.0f * 360.0f *
|
||||||
|
(-(float)keyboard_data.mouse_du * PC_MOUSE_DU_SENSITIVITY) / 660.0f;
|
||||||
|
|
||||||
if (keyboard_data.mouse_rl != 0)
|
if (keyboard_data.mouse_rl != 0)
|
||||||
yaw_delta -= GIMBAL_LEVER_SPEED_MAP_RATE * GIMBAL_YAW_PITCH_SPEED_RATE *
|
yaw_delta -= GIMBAL_LEVER_SPEED_MAP_RATE * GIMBAL_YAW_PITCH_SPEED_RATE *
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
#define ROBOT_PARAM_H
|
#define ROBOT_PARAM_H
|
||||||
|
|
||||||
/* ============================ 云台 ============================ */
|
/* ============================ 云台 ============================ */
|
||||||
#define PITCH_GM6020_POSITION_LOWER_LIMIT 3990 // Pitch 轴编码器值下限(云台抬起方向)
|
#define PITCH_GM6020_POSITION_UPPER_LIMIT 2260 // Pitch 轴抬起极限(最高位,编码器较小值;实测2203撞死限位,留余量设2260)
|
||||||
#define PITCH_GM6020_POSITION_UPPER_LIMIT 2220 // Pitch 轴编码器值上限(云台压低方向)
|
#define PITCH_GM6020_POSITION_LOWER_LIMIT 3950 // Pitch 轴压低极限(最低位,编码器较大值;实测4234撞死限位,留余量设3950)
|
||||||
#define PITCH_GM6020_ENCODER_ZERO 3245 // Pitch 轴编码器零位
|
#define PITCH_GM6020_ENCODER_ZERO 3200 // Pitch 轴编码器水平零位
|
||||||
#define YAW_GM6020_ENCODER_ZERO 4440 // Yaw 轴编码器零位(机械正前方,0~8191)
|
#define YAW_GM6020_ENCODER_ZERO 7730 // Yaw 轴编码器零位(机械正前方,0~8191)
|
||||||
#define CHASSIS_SPIN_FEEDFORWARD_K 0.0725f // 小陀螺解算时延前馈补偿系数(s)
|
#define CHASSIS_SPIN_FEEDFORWARD_K 0.008f // 小陀螺解算时延前馈补偿系数(s)
|
||||||
|
|
||||||
#define GIMBAL_FRICTION_WHEEL_SPEED 5500.0f // 摩擦轮转速(RPM)
|
#define GIMBAL_FRICTION_WHEEL_SPEED 5500.0f // 摩擦轮转速(RPM)
|
||||||
#define GIMBAL_RAMMER_SPEED -5400.0f// 拨弹盘转速(RPM,负向发射)
|
#define GIMBAL_RAMMER_SPEED -5400.0f// 拨弹盘转速(RPM,负向发射)
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
* 这是反复"疯转"的根源,已废弃;
|
* 这是反复"疯转"的根源,已废弃;
|
||||||
* - 现在两环共用陀螺,整条链只有一个装配符号,由上电自检自动测定
|
* - 现在两环共用陀螺,整条链只有一个装配符号,由上电自检自动测定
|
||||||
* (GIMBAL_YAW_DETECT 见下),无需人工猜;
|
* (GIMBAL_YAW_DETECT 见下),无需人工猜;
|
||||||
* - 单位:角度环 误差° -> 目标角速度°/s;速度环 误差°/s -> 电压。
|
* - 单位:角度环 误差° -> 目标角速度°/s;速度环 误差°/s -> 电流。
|
||||||
* 调参顺序:先速度环(点动不振荡),再位置环(刚性)——见移植 README §8.1 */
|
* 调参顺序:先速度环(点动不振荡),再位置环(刚性)——见移植 README §8.1 */
|
||||||
#define GIMBAL_YAW_ANGLE_KP 20.0f // ° -> °/s:10° 误差给 150°/s
|
#define GIMBAL_YAW_ANGLE_KP 20.0f // ° -> °/s:10° 误差给 150°/s
|
||||||
#define GIMBAL_YAW_ANGLE_KI 0.0f
|
#define GIMBAL_YAW_ANGLE_KI 0.0f
|
||||||
@@ -39,28 +39,35 @@
|
|||||||
#define GIMBAL_YAW_ANGLE_EK_DEADBAND 0.05f // 误差死区(°),QEKF 噪声小可用窄死区
|
#define GIMBAL_YAW_ANGLE_EK_DEADBAND 0.05f // 误差死区(°),QEKF 噪声小可用窄死区
|
||||||
#define GIMBAL_YAW_ANGLE_OUT_LIMIT 360.0f // 目标角速度上限(°/s)
|
#define GIMBAL_YAW_ANGLE_OUT_LIMIT 360.0f // 目标角速度上限(°/s)
|
||||||
|
|
||||||
#define GIMBAL_YAW_SPEED_KP 85.0f // °/s -> 电压:100°/s 误差给 6000(约 24% 满电压)
|
#define GIMBAL_YAW_SPEED_KP 85.0f // °/s -> 电流:100°/s 误差给 6000(约 36% 满电流)
|
||||||
#define GIMBAL_YAW_SPEED_KI 0.0f // 稳定后可回填 0.5~2 消速度稳态差
|
#define GIMBAL_YAW_SPEED_KI 0.0f // 稳定后可回填 0.5~2 消速度稳态差
|
||||||
#define GIMBAL_YAW_SPEED_KD 0.0f // 陀螺速率反馈噪声小,先不用 D
|
#define GIMBAL_YAW_SPEED_KD 0.0f // 陀螺速率反馈噪声小,先不用 D
|
||||||
#define GIMBAL_YAW_SPEED_OUT_LIMIT 25000.0f// GM6020 电压限幅
|
#define GIMBAL_YAW_SPEED_OUT_LIMIT 16384.0f// GM6020 电流限幅(±16384 对应 ±3A)
|
||||||
#define GIMBAL_YAW_SPIN_FEEDFORWARD_K 24.0f // 小陀螺底盘自旋解耦前馈系数(RPM->电压,通常15~35)
|
#define GIMBAL_YAW_SPIN_FEEDFORWARD_K 24.0f // 小陀螺底盘自旋解耦前馈系数(RPM->电流)
|
||||||
|
|
||||||
/* Yaw 装配符号自动检测:上电自检时给 Yaw 电机一个正向小电压脉冲,
|
/* Yaw 装配符号自动检测:上电自检时给 Yaw 电机一个正向小电流脉冲,
|
||||||
* 看陀螺 z 轴往哪边转——脉冲引起同向转动则符号 +1,反向则 -1。
|
* 看陀螺 z 轴往哪边转——脉冲引起同向转动则符号 +1,反向则 -1。
|
||||||
* 检测时云台会轻转几度,勿扶云台;失败(被按住/电机离线)时用 FALLBACK */
|
* 检测时云台会轻转几度,勿扶云台;失败(被按住/电机离线)时用 FALLBACK */
|
||||||
#define GIMBAL_YAW_SIGN_AUTO 1 // 1=上电自动检测 0=直接用 FALLBACK
|
#define GIMBAL_YAW_SIGN_AUTO 1 // 1=上电自动检测 0=直接用 FALLBACK
|
||||||
#define GIMBAL_YAW_SIGN_FALLBACK (1.0f)
|
#define GIMBAL_YAW_SIGN_FALLBACK (1.0f)
|
||||||
#define GIMBAL_YAW_DETECT_VOLTAGE 5000 // 检测脉冲电压(约 20% 满电压)
|
#define GIMBAL_YAW_DETECT_CURRENT 3500 // 检测脉冲电流(约 21% 满电流 16384)
|
||||||
#define GIMBAL_YAW_DETECT_RATE_MIN 20.0f // 判定转动的陀螺速率阈值(°/s)
|
#define GIMBAL_YAW_DETECT_RATE_MIN 20.0f // 判定转动的陀螺速率阈值(°/s)
|
||||||
|
|
||||||
/* ---- Pitch(位置环陀螺 Roll,速度环转子转速——Pitch 无符号史问题,维持原案) ---- */
|
/* ---- Pitch(位置环陀螺 Roll,速度环转子转速——Pitch 无符号史问题,维持原案) ---- */
|
||||||
#define GIMBAL_PITCH_ANGLE_EK_DEADBAND 0.3f // 位置环误差死区(°)
|
#define GIMBAL_PITCH_ANGLE_EK_DEADBAND 0.05f // 误差死区(°),收窄死区消除边缘阶跃
|
||||||
#define GIMBAL_PITCH_ANGLE_KP 15.0f
|
#define GIMBAL_PITCH_ANGLE_KP 40.0f
|
||||||
#define GIMBAL_PITCH_ANGLE_KI 0.0f
|
#define GIMBAL_PITCH_ANGLE_KI 0.0f
|
||||||
#define GIMBAL_PITCH_ANGLE_KD 100.0f
|
#define GIMBAL_PITCH_ANGLE_KD 0.0f // 原100.0f是万级电流振颤主因!清零以消除剧烈振荡
|
||||||
#define GIMBAL_PITCH_SPEED_KP 150.0f
|
#define GIMBAL_PITCH_SPEED_KP 100.0f // 速度/电流环Kp
|
||||||
#define GIMBAL_PITCH_SPEED_KI 0.001f
|
#define GIMBAL_PITCH_SPEED_KI 0.0f
|
||||||
#define GIMBAL_PITCH_SPEED_KD 5.0f
|
#define GIMBAL_PITCH_SPEED_KD 0.0f
|
||||||
|
|
||||||
|
/* Pitch 重力拟合前馈参数: I_g = K_COS * cos(a) + K_SIN * sin(a) + K_CONST
|
||||||
|
* 其中 a = (raw_angle - ZERO_ECD) * 360 / 8192 (°) */
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_ZERO_ECD 3200.0f // 重力补偿拟合基准编码值
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_K_COS 2856.1f// cos 项系数
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_K_SIN 4340.3f// sin 项系数
|
||||||
|
#define GIMBAL_PITCH_GRAVITY_K_CONST 2826.5f // 常数偏置项
|
||||||
|
|
||||||
#define GIMBAL_FRICTION_WHEEL_KP 16.0f
|
#define GIMBAL_FRICTION_WHEEL_KP 16.0f
|
||||||
#define GIMBAL_FRICTION_WHEEL_KI 0.0f
|
#define GIMBAL_FRICTION_WHEEL_KI 0.0f
|
||||||
@@ -97,7 +104,7 @@
|
|||||||
#define CHASSIS_FOLLOW_KP 0.4678f // w 量纲/°:10° 偏差给 w=4
|
#define CHASSIS_FOLLOW_KP 0.4678f // w 量纲/°:10° 偏差给 w=4
|
||||||
#define CHASSIS_FOLLOW_KI 0.0f // 调试期 0,同旧教训(积分残留)
|
#define CHASSIS_FOLLOW_KI 0.0f // 调试期 0,同旧教训(积分残留)
|
||||||
#define CHASSIS_FOLLOW_KD 24.452f
|
#define CHASSIS_FOLLOW_KD 24.452f
|
||||||
#define CHASSIS_FOLLOW_OUT_LIMIT 4.5f // 输出限幅(介于慢/快陀螺之间)
|
#define CHASSIS_FOLLOW_OUT_LIMIT 5.5f // 输出限幅(介于慢/快陀螺之间)
|
||||||
#define CHASSIS_FOLLOW_DEADBAND 1.0f // 误差死区(°)
|
#define CHASSIS_FOLLOW_DEADBAND 1.0f // 误差死区(°)
|
||||||
|
|
||||||
/* 跟随符号全自动综合:云台自检(0x1A9 flags)下发编码器 tick 增向,
|
/* 跟随符号全自动综合:云台自检(0x1A9 flags)下发编码器 tick 增向,
|
||||||
@@ -117,10 +124,11 @@
|
|||||||
#define CTOC_SLAVE_ID1 0x149 // 云台->底盘:摇杆数据
|
#define CTOC_SLAVE_ID1 0x149 // 云台->底盘:摇杆数据
|
||||||
#define CTOC_SLAVE_ID2 0x189 // 云台->底盘:控制状态+故障/陀螺使能位
|
#define CTOC_SLAVE_ID2 0x189 // 云台->底盘:控制状态+故障/陀螺使能位
|
||||||
#define CTOC_SLAVE_ID3 0x1A9 // 云台->底盘:云台世界系 yaw(float)+att_ready
|
#define CTOC_SLAVE_ID3 0x1A9 // 云台->底盘:云台世界系 yaw(float)+att_ready
|
||||||
|
#define CTOC_SLAVE_ID4 0x1B9 // 云台->底盘:UI 数据(pitch + 摩擦轮 L/R 转速)
|
||||||
|
|
||||||
/* ============================ CAN ID ============================ */
|
/* ============================ CAN ID ============================ */
|
||||||
/* 云台板:CAN1 = Pitch GM6020(0x206)+摩擦轮 M3508(0x201/0x202)
|
/* 云台板:CAN1 = Pitch GM6020(0x206,0x1FE)+摩擦轮 M3508(0x201/0x202,0x200)
|
||||||
* CAN2 = Yaw GM6020(0x205)+底盘回传(0x019)
|
* CAN2 = Yaw GM6020(0x205,0x1FE)+拨弹 M2006(0x201,0x200)+底盘回传(0x019)
|
||||||
* 底盘板:CAN1 = 四轮 M3508(0x201~0x204)
|
* 底盘板:CAN1 = 四轮 M3508(0x201~0x204)
|
||||||
* CAN2 = 云台数据(0x149/0x189/0x1A9) */
|
* CAN2 = 云台数据(0x149/0x189/0x1A9) */
|
||||||
|
|
||||||
@@ -128,11 +136,10 @@
|
|||||||
#define DEBUG_SHOOT_WITHOUT_REFEREE 1 // 1=无裁判系统时也允许开摩擦轮(台架调试用),比赛请改 0
|
#define DEBUG_SHOOT_WITHOUT_REFEREE 1 // 1=无裁判系统时也允许开摩擦轮(台架调试用),比赛请改 0
|
||||||
#define GIMBAL_RAMMER_INSTALLED 0 // 1=拨弹 M2006 已安装;0=暂缺,不参与掉线判定
|
#define GIMBAL_RAMMER_INSTALLED 0 // 1=拨弹 M2006 已安装;0=暂缺,不参与掉线判定
|
||||||
|
|
||||||
/* 1=调试模式:把 CAN 掉线警告音替换成循环播放的旋律(台架调试时避免连续滴滴声
|
/* 1=把 CAN 掉线警告音替换成循环播放的旋律《你》(RM动画片尾曲),报警时播放;
|
||||||
* 干扰)。红灯常亮与其它灯语完全不变,仍能看出是哪台设备掉线;比赛请改 0。
|
* 旋律音符表见 modules/dev/buzzer.c 的 buzzer_melody[] */
|
||||||
* 旋律音符表见 modules/BUZZER/buzzer.c 的 buzzer_melody[] */
|
#define DEBUG_BUZZER_MELODY 0
|
||||||
#define DEBUG_BUZZER_MELODY 1
|
#define BUZZER_MELODY_SPEED_DIV 1 // 旋律降速分频(默认1:每步100ms精准匹配原版带吐音断音节拍)
|
||||||
#define BUZZER_MELODY_SPEED_DIV 1 // 旋律降速分频(默认1:每步100ms精准匹配原版带吐音断音节拍) // 旋律降速分频(默认2:放慢一倍匹配原曲抒情节拍;设为3/4可进一步放慢)
|
|
||||||
|
|
||||||
/* ============================ 掉线检测 ============================ */
|
/* ============================ 掉线检测 ============================ */
|
||||||
#define DEVICE_OFFLINE_TIME_MS 100 // CAN 设备/裁判系统掉线判定时间
|
#define DEVICE_OFFLINE_TIME_MS 100 // CAN 设备/裁判系统掉线判定时间
|
||||||
|
|||||||
@@ -1246,6 +1246,18 @@
|
|||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<bDave2>0</bDave2>
|
<bDave2>0</bDave2>
|
||||||
|
<PathWithFileName>..\modules\comms\referee_ui.c</PathWithFileName>
|
||||||
|
<FilenameWithoutPath>referee_ui.c</FilenameWithoutPath>
|
||||||
|
<RteFlg>0</RteFlg>
|
||||||
|
<bShared>0</bShared>
|
||||||
|
</File>
|
||||||
|
<File>
|
||||||
|
<GroupNumber>10</GroupNumber>
|
||||||
|
<FileNumber>82</FileNumber>
|
||||||
|
<FileType>1</FileType>
|
||||||
|
<tvExp>0</tvExp>
|
||||||
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
|
<bDave2>0</bDave2>
|
||||||
<PathWithFileName>..\modules\dev\led.c</PathWithFileName>
|
<PathWithFileName>..\modules\dev\led.c</PathWithFileName>
|
||||||
<FilenameWithoutPath>led.c</FilenameWithoutPath>
|
<FilenameWithoutPath>led.c</FilenameWithoutPath>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
@@ -1253,7 +1265,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>82</FileNumber>
|
<FileNumber>83</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1265,7 +1277,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>83</FileNumber>
|
<FileNumber>84</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1277,7 +1289,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>84</FileNumber>
|
<FileNumber>85</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1289,7 +1301,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>85</FileNumber>
|
<FileNumber>86</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1301,7 +1313,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>86</FileNumber>
|
<FileNumber>87</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1313,7 +1325,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>87</FileNumber>
|
<FileNumber>88</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1325,7 +1337,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>88</FileNumber>
|
<FileNumber>89</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1337,7 +1349,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>89</FileNumber>
|
<FileNumber>90</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1349,7 +1361,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>10</GroupNumber>
|
<GroupNumber>10</GroupNumber>
|
||||||
<FileNumber>90</FileNumber>
|
<FileNumber>91</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1369,7 +1381,7 @@
|
|||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>11</GroupNumber>
|
<GroupNumber>11</GroupNumber>
|
||||||
<FileNumber>91</FileNumber>
|
<FileNumber>92</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1381,7 +1393,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>11</GroupNumber>
|
<GroupNumber>11</GroupNumber>
|
||||||
<FileNumber>92</FileNumber>
|
<FileNumber>93</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1393,7 +1405,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>11</GroupNumber>
|
<GroupNumber>11</GroupNumber>
|
||||||
<FileNumber>93</FileNumber>
|
<FileNumber>94</FileNumber>
|
||||||
<FileType>5</FileType>
|
<FileType>5</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1405,7 +1417,7 @@
|
|||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>11</GroupNumber>
|
<GroupNumber>11</GroupNumber>
|
||||||
<FileNumber>94</FileNumber>
|
<FileNumber>95</FileNumber>
|
||||||
<FileType>5</FileType>
|
<FileType>5</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
@@ -1425,7 +1437,7 @@
|
|||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>12</GroupNumber>
|
<GroupNumber>12</GroupNumber>
|
||||||
<FileNumber>95</FileNumber>
|
<FileNumber>96</FileNumber>
|
||||||
<FileType>4</FileType>
|
<FileType>4</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
|
|||||||
@@ -2363,6 +2363,11 @@
|
|||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>..\modules\comms\referee.c</FilePath>
|
<FilePath>..\modules\comms\referee.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
|
<File>
|
||||||
|
<FileName>referee_ui.c</FileName>
|
||||||
|
<FileType>1</FileType>
|
||||||
|
<FilePath>..\modules\comms\referee_ui.c</FilePath>
|
||||||
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<FileName>led.c</FileName>
|
<FileName>led.c</FileName>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ static volatile uint32_t ctoc_att_last_tick = 0;
|
|||||||
/* 云台自检下发的编码器方向:+1=tick增向CCW -1=CW 0=未检测(0x1A9 flags) */
|
/* 云台自检下发的编码器方向:+1=tick增向CCW -1=CW 0=未检测(0x1A9 flags) */
|
||||||
volatile int8_t ctoc_encoder_ccw = 0;
|
volatile int8_t ctoc_encoder_ccw = 0;
|
||||||
|
|
||||||
|
/* ---- 0x1B9 自定义UI 专用量(云台提供,底盘本地没有) ---- */
|
||||||
|
volatile float ctoc_ui_pitch_deg = 0.0f;
|
||||||
|
volatile float ctoc_ui_fric_l_rpm = 0.0f;
|
||||||
|
volatile float ctoc_ui_fric_r_rpm = 0.0f;
|
||||||
|
volatile uint8_t ctoc_ui_spin_flag = 0;
|
||||||
|
volatile uint32_t ctoc_ui_last_tick = 0;
|
||||||
|
|
||||||
/* 0x1A9 帧新鲜判定(两板公共:底盘跟随用它门控,云台留作诊断) */
|
/* 0x1A9 帧新鲜判定(两板公共:底盘跟随用它门控,云台留作诊断) */
|
||||||
uint8_t ctoc_att_fresh(void)
|
uint8_t ctoc_att_fresh(void)
|
||||||
{
|
{
|
||||||
@@ -179,11 +186,26 @@ static void c_comm_rx_0x1a9(uint32_t std_id, const uint8_t rx_data[8], uint32_t
|
|||||||
ctoc_att_last_tick = HAL_GetTick();
|
ctoc_att_last_tick = HAL_GetTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 0x1B9 云台->底盘:自定义UI 需要而底盘本地没有的量
|
||||||
|
* [0..1] pitch(0.01°) [2..3] 左摩擦轮(rpm/100) [4..5] 右摩擦轮(rpm/100)
|
||||||
|
* [6] bit0=小陀螺使能 */
|
||||||
|
static void c_comm_rx_0x1b9(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
|
||||||
|
{
|
||||||
|
(void)std_id;
|
||||||
|
(void)dlc;
|
||||||
|
ctoc_ui_pitch_deg = (float)(int16_t)(((uint16_t)rx_data[1] << 8) | rx_data[0]) * 0.01f;
|
||||||
|
ctoc_ui_fric_l_rpm = (float)(int16_t)(((uint16_t)rx_data[3] << 8) | rx_data[2]) * 100.0f;
|
||||||
|
ctoc_ui_fric_r_rpm = (float)(int16_t)(((uint16_t)rx_data[5] << 8) | rx_data[4]) * 100.0f;
|
||||||
|
ctoc_ui_spin_flag = rx_data[6] & 0x01;
|
||||||
|
ctoc_ui_last_tick = HAL_GetTick();
|
||||||
|
}
|
||||||
|
|
||||||
void c_comm_init(void)
|
void c_comm_init(void)
|
||||||
{
|
{
|
||||||
can_rx_register(&hcan2, CTOC_SLAVE_ID1, c_comm_rx_0x149);
|
can_rx_register(&hcan2, CTOC_SLAVE_ID1, c_comm_rx_0x149);
|
||||||
can_rx_register(&hcan2, CTOC_SLAVE_ID2, c_comm_rx_0x189);
|
can_rx_register(&hcan2, CTOC_SLAVE_ID2, c_comm_rx_0x189);
|
||||||
can_rx_register(&hcan2, CTOC_SLAVE_ID3, c_comm_rx_0x1a9);
|
can_rx_register(&hcan2, CTOC_SLAVE_ID3, c_comm_rx_0x1a9);
|
||||||
|
can_rx_register(&hcan2, CTOC_SLAVE_ID4, c_comm_rx_0x1b9);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_comm_slave_send(uint8_t motor_fault)
|
void c_comm_slave_send(uint8_t motor_fault)
|
||||||
|
|||||||
@@ -63,6 +63,18 @@ extern volatile int8_t ctoc_encoder_ccw;
|
|||||||
/* 底盘板:0x1A9 帧是否新鲜(掉线检测) */
|
/* 底盘板:0x1A9 帧是否新鲜(掉线检测) */
|
||||||
extern uint8_t ctoc_att_fresh(void);
|
extern uint8_t ctoc_att_fresh(void);
|
||||||
|
|
||||||
|
/* ---- 0x1B9 云台->底盘:自定义UI 专用数据 ---------------------------------
|
||||||
|
* 底盘本地没有、但 UI 要显示的量(见 referee_ui):pitch 角度与左右摩擦轮转速。
|
||||||
|
* 单位:0.01° / rpm(×100 压缩成 int16 传输) */
|
||||||
|
extern volatile float ctoc_ui_pitch_deg;
|
||||||
|
extern volatile float ctoc_ui_fric_l_rpm;
|
||||||
|
extern volatile float ctoc_ui_fric_r_rpm;
|
||||||
|
extern volatile uint8_t ctoc_ui_spin_flag;
|
||||||
|
extern volatile uint32_t ctoc_ui_last_tick;
|
||||||
|
|
||||||
|
/* 云台板:发送 0x1B9 UI 数据帧(2ms 周期或按需,c_comm_task 调用) */
|
||||||
|
extern void c_comm_master_send_ui(float pitch_deg, float fric_l_rpm, float fric_r_rpm, uint8_t spin_on);
|
||||||
|
|
||||||
/* 注册 CAN 接收回调(can_start() 之后调用) */
|
/* 注册 CAN 接收回调(can_start() 之后调用) */
|
||||||
extern void c_comm_init(void);
|
extern void c_comm_init(void);
|
||||||
|
|
||||||
|
|||||||
@@ -216,3 +216,48 @@ void referee_parse_bytes(const uint8_t * data, uint16_t len)
|
|||||||
while (len--)
|
while (len--)
|
||||||
referee_parse_byte(*data++);
|
referee_parse_byte(*data++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ============================================================================
|
||||||
|
* 发送:裁判系统帧(机器人 -> 裁判系统 -> 选手端)
|
||||||
|
* 帧: A5 | data_length(2,LE,=payload 字节数,不含 cmd_id) | seq | CRC8
|
||||||
|
* | cmd_id(2,LE) | data | CRC16(2,LE,低字节先)
|
||||||
|
* CRC8 覆盖前 4 字节;CRC16 覆盖除末 2 字节外全部。
|
||||||
|
* 自定义UI 走 cmd 0x0301(payload 首 6 字节为 data_cmd_id/sender_ID/receiver_ID)。
|
||||||
|
* USART6 TX DMA:静态缓冲,发送期间不得被覆盖;UI 刷新率 5Hz 远低于链路能力。
|
||||||
|
* ==========================================================================*/
|
||||||
|
#include "bsp_usart.h"
|
||||||
|
|
||||||
|
static uint8_t ref_tx_seq = 0;
|
||||||
|
|
||||||
|
void referee_send_frame(uint16_t cmd_id, const uint8_t * data, uint16_t len)
|
||||||
|
{
|
||||||
|
static uint8_t frame[REF_FRAME_MAX_LEN];
|
||||||
|
uint16_t i = 0;
|
||||||
|
|
||||||
|
if (len > (uint16_t)(REF_FRAME_MAX_LEN - 9) || data == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
frame[i++] = 0xA5;
|
||||||
|
frame[i++] = (uint8_t)(len & 0xFF);
|
||||||
|
frame[i++] = (uint8_t)(len >> 8);
|
||||||
|
frame[i++] = ref_tx_seq++;
|
||||||
|
|
||||||
|
uint8_t crc8 = 0xFF;
|
||||||
|
for (uint16_t k = 0; k < 4; k++)
|
||||||
|
crc8 = crc8_update(crc8, frame[k]);
|
||||||
|
frame[i++] = crc8;
|
||||||
|
|
||||||
|
frame[i++] = (uint8_t)(cmd_id & 0xFF);
|
||||||
|
frame[i++] = (uint8_t)(cmd_id >> 8);
|
||||||
|
|
||||||
|
for (uint16_t k = 0; k < len; k++)
|
||||||
|
frame[i++] = data[k];
|
||||||
|
|
||||||
|
uint16_t crc16 = 0xFFFF;
|
||||||
|
for (uint16_t k = 0; k < i; k++)
|
||||||
|
crc16 = crc16_update(crc16, frame[k]);
|
||||||
|
frame[i++] = (uint8_t)(crc16 & 0xFF);
|
||||||
|
frame[i++] = (uint8_t)(crc16 >> 8);
|
||||||
|
|
||||||
|
usart6_tx_dma_enable(frame, i);
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,4 +30,10 @@ extern void referee_parse_bytes(const uint8_t * data, uint16_t len);
|
|||||||
typedef void (*referee_keyboard_hook_f)(const uint8_t data[12]);
|
typedef void (*referee_keyboard_hook_f)(const uint8_t data[12]);
|
||||||
extern void referee_set_keyboard_hook(referee_keyboard_hook_f hook);
|
extern void referee_set_keyboard_hook(referee_keyboard_hook_f hook);
|
||||||
|
|
||||||
|
/* ---- 发送(机器人 -> 裁判系统/选手端) -------------------------------------
|
||||||
|
* 用于自定义UI(0x0301 机器人交互数据)。data_length 取 payload 字节数(不含 cmd_id,
|
||||||
|
* 与解析器一致);CRC8 覆盖前 4 字节,CRC16 覆盖除末 2 字节外全部(低字节先)。
|
||||||
|
* 内部静态缓冲 + USART6 TX DMA,立即返回,勿高频调用(链路 115200)。 */
|
||||||
|
extern void referee_send_frame(uint16_t cmd_id, const uint8_t * data, uint16_t len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,243 @@
|
|||||||
|
/* =============================================================================
|
||||||
|
* referee_ui.c - 裁判系统自定义UI组包与发送(版式见 referee_ui.h / hud_mock5.png)
|
||||||
|
*
|
||||||
|
* 组包: 每包 = ext_student_interactive_header_data_t{data_cmd_id, sender_ID,
|
||||||
|
* receiver_ID} + N×15 字节图形数据,N 由 data_cmd_id 决定(1/2/5/7)。
|
||||||
|
* 图形名用 3 字符自增计数器(base36)保证唯一;首轮 ADD,之后 MODIFY。
|
||||||
|
* 发送: referee_send_frame(0x0301, payload, 6 + N*15) -> USART6 DMA
|
||||||
|
* ==========================================================================*/
|
||||||
|
#include "referee_ui.h"
|
||||||
|
#include "referee.h"
|
||||||
|
#include "robot_param.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* 协议要求:图形数据恰好 15 字节(头 11 + 尾 4)。若 pack(1) 失效或位域被重排,
|
||||||
|
* 这里直接编译失败,而不是把错位的图形发给选手端。 */
|
||||||
|
_Static_assert(sizeof(ui_head_t) == 11, "ui_head_t 必须是 11 字节");
|
||||||
|
_Static_assert(sizeof(ui_draw_t) == 15, "ui_draw_t 必须是 15 字节");
|
||||||
|
_Static_assert(sizeof(ui_num_t) == 15, "ui_num_t 必须是 15 字节");
|
||||||
|
_Static_assert(sizeof(ui_graphic_t) == 15, "ui_graphic_t 必须是 15 字节");
|
||||||
|
|
||||||
|
/* ---- 图形名生成:base26 三字符(17576 个组合,足够) ---- */
|
||||||
|
static uint16_t ui_name_seq = 0;
|
||||||
|
static void ui_next_name(uint8_t name[3])
|
||||||
|
{
|
||||||
|
uint16_t v = ui_name_seq++;
|
||||||
|
name[0] = (uint8_t)('A' + (v / 676) % 26);
|
||||||
|
name[1] = (uint8_t)('A' + (v / 26) % 26);
|
||||||
|
name[2] = (uint8_t)('A' + v % 26);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- 打包缓冲 ---- */
|
||||||
|
#define UI_PAYLOAD_MAX (6 + UI_MAX_PER_PACKET * sizeof(ui_graphic_t))
|
||||||
|
static uint8_t ui_pkt[UI_PAYLOAD_MAX];
|
||||||
|
static uint8_t ui_pkt_n; /* 当前包里的图形个数 */
|
||||||
|
static uint8_t ui_op = UI_OP_ADD; /* 首轮 ADD,之后 MOD */
|
||||||
|
static uint8_t ui_ready = 0; /* 首轮是否已发完 */
|
||||||
|
|
||||||
|
static void ui_flush(void)
|
||||||
|
{
|
||||||
|
if (ui_pkt_n == 0)
|
||||||
|
return;
|
||||||
|
uint16_t cmd;
|
||||||
|
switch (ui_pkt_n)
|
||||||
|
{
|
||||||
|
case 1: cmd = UI_CMD_1; break;
|
||||||
|
case 2: cmd = UI_CMD_2; break;
|
||||||
|
case 5: cmd = UI_CMD_5; break;
|
||||||
|
case 7: cmd = UI_CMD_7; break;
|
||||||
|
default: return; /* 协议只支持 1/2/5/7,不该发生 */
|
||||||
|
}
|
||||||
|
/* header: data_cmd_id / sender_ID / receiver_ID,均小端 */
|
||||||
|
ui_pkt[0] = (uint8_t)(cmd & 0xFF);
|
||||||
|
ui_pkt[1] = (uint8_t)(cmd >> 8);
|
||||||
|
uint16_t sid = (uint16_t)referee.robot_id;
|
||||||
|
ui_pkt[2] = (uint8_t)(sid & 0xFF);
|
||||||
|
ui_pkt[3] = (uint8_t)(sid >> 8);
|
||||||
|
ui_pkt[4] = (uint8_t)(UI_RECEIVER_ID & 0xFF);
|
||||||
|
ui_pkt[5] = (uint8_t)(UI_RECEIVER_ID >> 8);
|
||||||
|
referee_send_frame(UI_CMD_BASE, ui_pkt, (uint16_t)(6 + ui_pkt_n * sizeof(ui_graphic_t)));
|
||||||
|
ui_pkt_n = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ui_graphic_t * ui_new(uint8_t type, uint8_t layer, uint8_t color)
|
||||||
|
{
|
||||||
|
if (ui_pkt_n >= UI_MAX_PER_PACKET)
|
||||||
|
ui_flush();
|
||||||
|
ui_graphic_t * g = (ui_graphic_t *)&ui_pkt[6 + ui_pkt_n * sizeof(ui_graphic_t)];
|
||||||
|
memset(g, 0, sizeof(*g));
|
||||||
|
ui_next_name(g->d.h.name); /* d.h 与 n.h 同址 */
|
||||||
|
g->d.h.type = type;
|
||||||
|
g->d.h.layer = layer;
|
||||||
|
g->d.h.color = color;
|
||||||
|
g->d.h.operate = ui_op;
|
||||||
|
ui_pkt_n++;
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- 图元封装(绘制类写 d.*,数值类写 n.val) ---- */
|
||||||
|
static void ui_line(uint8_t layer, uint8_t color, int x0, int y0, int x1, int y1, int w)
|
||||||
|
{
|
||||||
|
ui_graphic_t * g = ui_new(UI_T_LINE, layer, color);
|
||||||
|
g->d.h.x0 = (uint32_t)x0; g->d.h.y0 = (uint32_t)y0;
|
||||||
|
g->d.x1 = (uint32_t)x1; g->d.y1 = (uint32_t)y1;
|
||||||
|
g->d.h.width = (uint32_t)w;
|
||||||
|
}
|
||||||
|
static void ui_rect(uint8_t layer, uint8_t color, int x0, int y0, int x1, int y1)
|
||||||
|
{
|
||||||
|
ui_graphic_t * g = ui_new(UI_T_RECT, layer, color);
|
||||||
|
g->d.h.x0 = (uint32_t)x0; g->d.h.y0 = (uint32_t)y0;
|
||||||
|
g->d.x1 = (uint32_t)x1; g->d.y1 = (uint32_t)y1;
|
||||||
|
}
|
||||||
|
static void ui_fval(uint8_t layer, uint8_t color, int x, int y, float v, int digits)
|
||||||
|
{
|
||||||
|
ui_graphic_t * g = ui_new(UI_T_FLOAT, layer, color);
|
||||||
|
g->n.h.x0 = (uint32_t)x; g->n.h.y0 = (uint32_t)y;
|
||||||
|
g->n.h.width = (uint32_t)digits; /* 浮点:小数位数 */
|
||||||
|
g->n.val.f = v;
|
||||||
|
}
|
||||||
|
static void ui_ival(uint8_t layer, uint8_t color, int x, int y, int32_t v)
|
||||||
|
{
|
||||||
|
ui_graphic_t * g = ui_new(UI_T_INT, layer, color);
|
||||||
|
g->n.h.x0 = (uint32_t)x; g->n.h.y0 = (uint32_t)y;
|
||||||
|
g->n.val.i = v;
|
||||||
|
}
|
||||||
|
static void ui_char(uint8_t layer, uint8_t color, int x, int y, const char * s)
|
||||||
|
{
|
||||||
|
ui_graphic_t * g = ui_new(UI_T_CHAR, layer, color);
|
||||||
|
g->n.h.x0 = (uint32_t)x; g->n.h.y0 = (uint32_t)y;
|
||||||
|
g->n.h.width = (uint32_t)strlen(s);
|
||||||
|
for (int i = 0; i < 4; i++) /* 最多 4 字节 ASCII */
|
||||||
|
g->n.val.s[i] = s[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 角度归一到 [0,360) */
|
||||||
|
static float ui_norm360(float a)
|
||||||
|
{
|
||||||
|
while (a < 0.0f) a += 360.0f;
|
||||||
|
while (a >= 360.0f) a -= 360.0f;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void referee_ui_update(const ui_data_t * d)
|
||||||
|
{
|
||||||
|
if (d == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* 裁判系统离线:发一轮删除图层,然后停发(避免选手端残留最后一帧) */
|
||||||
|
if (!d->ref_online)
|
||||||
|
{
|
||||||
|
if (ui_ready)
|
||||||
|
{
|
||||||
|
ui_pkt_n = 0;
|
||||||
|
ui_graphic_t * g = ui_new(UI_T_RECT, UI_L_FRAME, UI_C_BLACK);
|
||||||
|
g->d.h.operate = UI_OP_DEL;
|
||||||
|
g->d.h.x0 = 0; g->d.h.y0 = 0; g->d.x1 = 0; g->d.y1 = 0;
|
||||||
|
ui_flush();
|
||||||
|
ui_ready = 0;
|
||||||
|
ui_name_seq = 0;
|
||||||
|
ui_op = UI_OP_ADD;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- 左上:预估底盘功率 ---------------- */
|
||||||
|
uint8_t pw_col = (d->pwr_w > d->pwr_limit_w) ? UI_C_RED
|
||||||
|
: (d->pwr_w > d->pwr_limit_w * 0.8f) ? UI_C_ORANGE : UI_C_GREEN;
|
||||||
|
ui_rect(UI_L_FRAME, UI_C_CYAN, UI_PWR_X0, UI_PWR_Y0, UI_PWR_X1, UI_PWR_Y0 + 4);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_CYAN, UI_PWR_X0 + 20, UI_PWR_Y0 + 30, "PWR");
|
||||||
|
ui_fval(UI_L_TEXT, UI_C_WHITE, UI_PWR_X0 + 20, UI_PWR_Y0 + 64, d->pwr_w, 1);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_WHITE, UI_PWR_X0 + 210, UI_PWR_Y0 + 84, "W");
|
||||||
|
int pw_w_px = (int)((UI_PWR_X1 - UI_PWR_X0 - 40) * (d->pwr_w / (d->pwr_limit_w > 1.0f ? d->pwr_limit_w : 1.0f)));
|
||||||
|
if (pw_w_px > UI_PWR_X1 - UI_PWR_X0 - 40) pw_w_px = UI_PWR_X1 - UI_PWR_X0 - 40;
|
||||||
|
if (pw_w_px < 0) pw_w_px = 0;
|
||||||
|
ui_rect(UI_L_GAUGE, pw_col, UI_PWR_X0 + 20, UI_PWR_Y0 + 120, UI_PWR_X0 + 20 + pw_w_px, UI_PWR_Y0 + 142);
|
||||||
|
ui_line(UI_L_GAUGE, UI_C_WHITE, UI_PWR_X0 + 20 + (UI_PWR_X1 - UI_PWR_X0 - 40) - 3, UI_PWR_Y0 + 116,
|
||||||
|
UI_PWR_X0 + 20 + (UI_PWR_X1 - UI_PWR_X0 - 40) - 3, UI_PWR_Y0 + 146, 2);
|
||||||
|
|
||||||
|
/* ---------------- 左中:超级电容 ---------------- */
|
||||||
|
uint8_t cap_col = (d->cap_pct < 15) ? UI_C_RED : (d->cap_pct < 40) ? UI_C_ORANGE : UI_C_CYAN;
|
||||||
|
ui_rect(UI_L_FRAME, cap_col, UI_CAP_X0, UI_CAP_Y0, UI_CAP_X1, UI_CAP_Y0 + 4);
|
||||||
|
ui_char(UI_L_TEXT, cap_col, UI_CAP_X0 + 20, UI_CAP_Y0 + 30, "CAP");
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_WHITE, UI_CAP_X0 + 20, UI_CAP_Y0 + 64, (int32_t)d->cap_pct);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_WHITE, UI_CAP_X0 + 130, UI_CAP_Y0 + 84, "%");
|
||||||
|
int cap_px = (int)((UI_CAP_X1 - UI_CAP_X0 - 40) * (d->cap_pct / 100.0f));
|
||||||
|
ui_rect(UI_L_GAUGE, cap_col, UI_CAP_X0 + 20, UI_CAP_Y0 + 118, UI_CAP_X0 + 20 + cap_px, UI_CAP_Y0 + 140);
|
||||||
|
|
||||||
|
/* ---------------- 顶部:罗盘刻度带(底盘正方向朝向) ---------------- */
|
||||||
|
{
|
||||||
|
float h = ui_norm360(d->hdg_deg);
|
||||||
|
ui_rect(UI_L_FRAME, UI_C_CYAN, UI_HDG_X0, UI_HDG_Y0, UI_HDG_X1, UI_HDG_Y0 + 4);
|
||||||
|
ui_line(UI_L_FRAME, UI_C_CYAN, UI_HDG_X0 + 20, UI_HDG_Y0 + 62, UI_HDG_X1 - 20, UI_HDG_Y0 + 62, 2);
|
||||||
|
int cx = (UI_HDG_X0 + UI_HDG_X1) / 2;
|
||||||
|
for (int k = -1; k <= 1; k++) /* 3 条刻度 */
|
||||||
|
{
|
||||||
|
int x = cx + k * (UI_HDG_TAPE_HALF / 2);
|
||||||
|
ui_line(UI_L_FRAME, UI_C_CYAN, x, UI_HDG_Y0 + 40, x, UI_HDG_Y0 + 62, k == 0 ? 3 : 2);
|
||||||
|
}
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_CYAN, cx - UI_HDG_TAPE_HALF / 2 - 24, UI_HDG_Y0 + 18,
|
||||||
|
(int32_t)ui_norm360(h - 30.0f));
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_CYAN, cx + UI_HDG_TAPE_HALF / 2 - 24, UI_HDG_Y0 + 18,
|
||||||
|
(int32_t)ui_norm360(h + 30.0f));
|
||||||
|
ui_line(UI_L_FRAME, UI_C_WHITE, cx, UI_HDG_Y0 + 62, cx - 8, UI_HDG_Y0 + 50, 2);
|
||||||
|
ui_line(UI_L_FRAME, UI_C_WHITE, cx, UI_HDG_Y0 + 62, cx + 8, UI_HDG_Y0 + 50, 2);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_CYAN, UI_HDG_X0 + 24, UI_HDG_Y0 + 70, "HDG");
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_WHITE, UI_HDG_X0 + 90, UI_HDG_Y0 + 66, (int32_t)h);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_CYAN, UI_HDG_X1 - 170, UI_HDG_Y0 + 70, "YAW");
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_WHITE, UI_HDG_X1 - 104, UI_HDG_Y0 + 66, (int32_t)ui_norm360(d->yaw_deg));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- 中央:俯仰梯 ---------------- */
|
||||||
|
ui_line(UI_L_FRAME, UI_C_WHITE, UI_LAD_CX - 44, UI_LAD_CY, UI_LAD_CX - 14, UI_LAD_CY, 4);
|
||||||
|
ui_line(UI_L_FRAME, UI_C_WHITE, UI_LAD_CX + 14, UI_LAD_CY, UI_LAD_CX + 44, UI_LAD_CY, 4);
|
||||||
|
for (int i = -2; i <= 2; i++) /* ±10/±5/0 五条梯线 */
|
||||||
|
{
|
||||||
|
if (i == 0) continue;
|
||||||
|
int v = i * 5;
|
||||||
|
int yy = UI_LAD_CY - v * UI_LAD_PX_PER_DEG;
|
||||||
|
int half = (i % 2 == 0) ? UI_LAD_HALF_LONG : UI_LAD_HALF_SHORT;
|
||||||
|
ui_line(UI_L_GAUGE, UI_C_CYAN, UI_LAD_CX - half, yy, UI_LAD_CX - 18, yy, 2);
|
||||||
|
ui_line(UI_L_GAUGE, UI_C_CYAN, UI_LAD_CX + 18, yy, UI_LAD_CX + half, yy, 2);
|
||||||
|
}
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_CYAN, UI_LAD_CX - UI_LAD_HALF_SHORT - 40, UI_LAD_CY - 10 * UI_LAD_PX_PER_DEG - 10, 10);
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_CYAN, UI_LAD_CX + UI_LAD_HALF_SHORT + 12, UI_LAD_CY - 10 * UI_LAD_PX_PER_DEG - 10, 10);
|
||||||
|
{
|
||||||
|
int py = UI_LAD_CY - (int)(d->pitch_deg * UI_LAD_PX_PER_DEG);
|
||||||
|
ui_line(UI_L_GAUGE, UI_C_ORANGE, UI_LAD_CX - UI_LAD_HALF_LONG - 20, py, UI_LAD_CX - UI_LAD_HALF_LONG - 4, py, 4);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_ORANGE, UI_LAD_CX - UI_LAD_HALF_LONG - 132, py - 10, "PIT");
|
||||||
|
ui_fval(UI_L_TEXT, UI_C_WHITE, UI_LAD_CX - UI_LAD_HALF_LONG - 76, py - 14, d->pitch_deg, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- 右上:摩擦轮速度 ---------------- */
|
||||||
|
{
|
||||||
|
uint8_t f_col = (d->fric_l_rpm > 1000.0f && d->fric_r_rpm > 1000.0f) ? UI_C_GREEN : UI_C_ORANGE;
|
||||||
|
ui_rect(UI_L_FRAME, f_col, UI_FRIC_X0, UI_FRIC_Y0, UI_FRIC_X1, UI_FRIC_Y0 + 4);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_CYAN, UI_FRIC_X0 + 24, UI_FRIC_Y0 + 34, "FRIC");
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_WHITE, UI_FRIC_X0 + 24, UI_FRIC_Y0 + 74, (int32_t)d->fric_l_rpm);
|
||||||
|
ui_ival(UI_L_TEXT, UI_C_WHITE, UI_FRIC_X0 + 250, UI_FRIC_Y0 + 74, (int32_t)d->fric_r_rpm);
|
||||||
|
ui_char(UI_L_TEXT, f_col, UI_FRIC_X0 + 24, UI_FRIC_Y1 - 60,
|
||||||
|
(d->fric_l_rpm > 1000.0f && d->fric_r_rpm > 1000.0f) ? "ARMED" : "IDLE");
|
||||||
|
int bl = (int)((UI_FRIC_Y1 - UI_FRIC_Y0 - 140) * (d->fric_l_rpm / 7000.0f));
|
||||||
|
int br = (int)((UI_FRIC_Y1 - UI_FRIC_Y0 - 140) * (d->fric_r_rpm / 7000.0f));
|
||||||
|
if (bl < 0) bl = 0; if (bl > UI_FRIC_Y1 - UI_FRIC_Y0 - 140) bl = UI_FRIC_Y1 - UI_FRIC_Y0 - 140;
|
||||||
|
if (br < 0) br = 0; if (br > UI_FRIC_Y1 - UI_FRIC_Y0 - 140) br = UI_FRIC_Y1 - UI_FRIC_Y0 - 140;
|
||||||
|
ui_rect(UI_L_GAUGE, UI_C_GREEN, UI_FRIC_X0 + 30, UI_FRIC_Y1 - 40 - bl, UI_FRIC_X0 + 74, UI_FRIC_Y1 - 40);
|
||||||
|
ui_rect(UI_L_GAUGE, UI_C_GREEN, UI_FRIC_X0 + 256, UI_FRIC_Y1 - 40 - br, UI_FRIC_X0 + 300, UI_FRIC_Y1 - 40);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- 底部:小陀螺状态 ---------------- */
|
||||||
|
ui_rect(UI_L_FRAME, d->spin_on ? UI_C_GREEN : UI_C_CYAN, UI_SPIN_X0, UI_SPIN_Y0, UI_SPIN_X1, UI_SPIN_Y0 + 4);
|
||||||
|
ui_char(UI_L_TEXT, UI_C_CYAN, UI_SPIN_X0 + 24, UI_SPIN_Y0 + 34, "SPIN");
|
||||||
|
if (d->spin_on)
|
||||||
|
ui_rect(UI_L_GAUGE, UI_C_GREEN, UI_SPIN_X0 + 160, UI_SPIN_Y0 + 26, UI_SPIN_X0 + 268, UI_SPIN_Y0 + 66);
|
||||||
|
ui_char(UI_L_TEXT, d->spin_on ? UI_C_BLACK : UI_C_WHITE, UI_SPIN_X0 + 184, UI_SPIN_Y0 + 36,
|
||||||
|
d->spin_on ? "ON" : "OFF");
|
||||||
|
|
||||||
|
/* 收尾:最后一包;首轮发完切换为 MODIFY */
|
||||||
|
ui_flush();
|
||||||
|
if (!ui_ready)
|
||||||
|
{
|
||||||
|
ui_ready = 1;
|
||||||
|
ui_op = UI_OP_MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
#ifndef REFEREE_UI_H
|
||||||
|
#define REFEREE_UI_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* ============================================================================
|
||||||
|
* referee_ui.h - 裁判系统"自定义UI"(机器人 -> 选手端 图形绘制)
|
||||||
|
*
|
||||||
|
* 通道: 底盘板 USART6(裁判系统) --cmd 0x0301 机器人交互数据--> 选手端叠加显示
|
||||||
|
* 依据: 裁判系统串口协议 自定义UI 章节 + ARUW Taproot / Triton TR-mbed 两套实现
|
||||||
|
* 版式: 详见 E:\\ELCT\\_mcp_recon\\hud_mock5.png(坐标与本文 UI_* 宏一一对应)
|
||||||
|
*
|
||||||
|
* 硬约束(协议):
|
||||||
|
* 1. 一条消息最多携带 7 个图形(0x0101/0x0102/0x0103/0x0104 = 1/2/5/7 个)
|
||||||
|
* 2. 图形总数有限,且图形用"名称"标识 -> 首轮用 ADD,之后一律 MODIFY,
|
||||||
|
* 否则会在选手端把图形表撑爆
|
||||||
|
* 3. 图层数 0~9;坐标原点在屏幕左上角,x 向右、y 向下,画布 1920x1080
|
||||||
|
* 4. 不得绘制官方保留区(顶部比分条 / 左下小地图 / 右下战车模块 / 中部两块保留)
|
||||||
|
* 5. 协议无"圆角矩形/渐变/图标"原语,只能用 线/矩形/圆/椭圆/弧 + 数值/字符
|
||||||
|
* ==========================================================================*/
|
||||||
|
|
||||||
|
/* ---- 图形数据 -------------------------------------------------------------
|
||||||
|
* 绘制类(线/矩形/圆/椭圆/弧) 与 数值类(浮点/整型/字符) 都是 15 字节:
|
||||||
|
* 头 11 字节(所有类型共用): name[3] + operate:3 type:3 layer:4 color:4
|
||||||
|
* sa:9 ea:9 width:10 x0:11 y0:11
|
||||||
|
* 后 4 字节: 绘制类 = radius:10 x1:11 y1:11;数值类 = 一个 float/int32/char[4]
|
||||||
|
* 所以用"共用头 + 联合体"表达,两种视图都是 15 字节。
|
||||||
|
* 必须 pack(1):否则位域会对齐到 4 字节,整体变 16 字节。 */
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t name[3]; /* 图形名(3 字节 ASCII) */
|
||||||
|
uint32_t operate : 3; /* UI_OP_* 空/加/改/删 */
|
||||||
|
uint32_t type : 3; /* UI_T_* 图形类型 */
|
||||||
|
uint32_t layer : 4; /* UI_L_* 图层 0~9 */
|
||||||
|
uint32_t color : 4; /* UI_C_* 颜色 */
|
||||||
|
uint32_t sa : 9; /* 起始角(弧/椭圆) */
|
||||||
|
uint32_t ea : 9; /* 结束角 */
|
||||||
|
uint32_t width : 10; /* 线宽 / 小数位 / 字符串长度 */
|
||||||
|
uint32_t x0 : 11; /* 起点 x */
|
||||||
|
uint32_t y0 : 11; /* 起点 y */
|
||||||
|
} ui_head_t; /* 3 + 8 = 11 字节 */
|
||||||
|
|
||||||
|
typedef struct { ui_head_t h; uint32_t radius : 10, x1 : 11, y1 : 11; } ui_draw_t;
|
||||||
|
typedef struct { ui_head_t h; union { float f; int32_t i; char s[4]; } val; } ui_num_t;
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
ui_draw_t d; /* 绘制类视图 */
|
||||||
|
ui_num_t n; /* 数值类视图 */
|
||||||
|
uint8_t raw[15];
|
||||||
|
} ui_graphic_t;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/* ---- 命令 / 操作码 / 图形类型 -------------------------------------------- */
|
||||||
|
#define UI_CMD_BASE 0x0301 /* 机器人交互数据 */
|
||||||
|
#define UI_CMD_1 0x0101
|
||||||
|
#define UI_CMD_2 0x0102
|
||||||
|
#define UI_CMD_5 0x0103
|
||||||
|
#define UI_CMD_7 0x0104
|
||||||
|
#define UI_MAX_PER_PACKET 7
|
||||||
|
|
||||||
|
#define UI_OP_NOP 0
|
||||||
|
#define UI_OP_ADD 1
|
||||||
|
#define UI_OP_MOD 2 /* 稳态刷新一律用它 */
|
||||||
|
#define UI_OP_DEL 3
|
||||||
|
|
||||||
|
#define UI_T_LINE 0
|
||||||
|
#define UI_T_RECT 1
|
||||||
|
#define UI_T_CIRCLE 2
|
||||||
|
#define UI_T_ELLIPSE 3
|
||||||
|
#define UI_T_ARC 4
|
||||||
|
#define UI_T_FLOAT 5
|
||||||
|
#define UI_T_INT 6
|
||||||
|
#define UI_T_CHAR 7
|
||||||
|
|
||||||
|
/* ---- 颜色(官方 0~8) ------------------------------------------------------ */
|
||||||
|
#define UI_C_RED 0
|
||||||
|
#define UI_C_YELLOW 1
|
||||||
|
#define UI_C_GREEN 2
|
||||||
|
#define UI_C_ORANGE 3
|
||||||
|
#define UI_C_PURPLE 4
|
||||||
|
#define UI_C_PINK 5
|
||||||
|
#define UI_C_CYAN 6
|
||||||
|
#define UI_C_BLACK 7
|
||||||
|
#define UI_C_WHITE 8
|
||||||
|
|
||||||
|
/* ---- 图层(协议 0~9) ------------------------------------------------------ */
|
||||||
|
#define UI_L_FRAME 0 /* 卡片边框/刻度 */
|
||||||
|
#define UI_L_GAUGE 1 /* 能量条/进度条 */
|
||||||
|
#define UI_L_TEXT 2 /* 数值/字符 */
|
||||||
|
|
||||||
|
/* ---- 刷新率:5Hz 约 3.8KB/s(115200 链路),协议允许再调高 ---------------- */
|
||||||
|
#define UI_SEND_HZ 5
|
||||||
|
|
||||||
|
/* ---- 发送/接收方 ID -----------------------------------------------------
|
||||||
|
* sender = 本机机器人 ID(referee.robot_id,无裁判系统时用 0)
|
||||||
|
* receiver= 选手端/客户端(官方 UI 约定 0x8080);若你的协议版本要求填机器人 ID,
|
||||||
|
* 改这里一处即可。 */
|
||||||
|
#define UI_RECEIVER_ID 0x8080
|
||||||
|
|
||||||
|
/* ---- 画布 ---------------------------------------------------------------- */
|
||||||
|
#define UI_SCREEN_W 1920
|
||||||
|
#define UI_SCREEN_H 1080
|
||||||
|
|
||||||
|
/* ---- 版式坐标(与 hud_mock5.png 对应,全部避开官方保留区) ---------------- */
|
||||||
|
/* 左上:预估底盘功率 */ /* 左上 x56..520 y176..386 */
|
||||||
|
#define UI_PWR_X0 56
|
||||||
|
#define UI_PWR_Y0 176
|
||||||
|
#define UI_PWR_X1 520
|
||||||
|
#define UI_PWR_Y1 386
|
||||||
|
/* 左中:超级电容 */ /* x56..520 y404..566 */
|
||||||
|
#define UI_CAP_X0 56
|
||||||
|
#define UI_CAP_Y0 404
|
||||||
|
#define UI_CAP_X1 520
|
||||||
|
#define UI_CAP_Y1 566
|
||||||
|
/* 顶部:罗盘刻度带(底盘正方向) */ /* x626..1258 y186..270 */
|
||||||
|
#define UI_HDG_X0 626
|
||||||
|
#define UI_HDG_Y0 186
|
||||||
|
#define UI_HDG_X1 1258
|
||||||
|
#define UI_HDG_Y1 270
|
||||||
|
#define UI_HDG_TAPE_HALF 216 /* 刻度带半宽(像素,对应 ±30°) */
|
||||||
|
/* 中央:俯仰梯 */ /* 以屏幕中心为基准 */
|
||||||
|
#define UI_LAD_CX 960
|
||||||
|
#define UI_LAD_CY 540
|
||||||
|
#define UI_LAD_PX_PER_DEG 11 /* 每度 11 像素 */
|
||||||
|
#define UI_LAD_HALF_LONG 96
|
||||||
|
#define UI_LAD_HALF_SHORT 62
|
||||||
|
/* 右上:摩擦轮速度 */ /* x1420..1864 y176..520 */
|
||||||
|
#define UI_FRIC_X0 1420
|
||||||
|
#define UI_FRIC_Y0 176
|
||||||
|
#define UI_FRIC_X1 1864
|
||||||
|
#define UI_FRIC_Y1 520
|
||||||
|
/* 底部:小陀螺状态 */ /* x700..1220 y874..1000 */
|
||||||
|
#define UI_SPIN_X0 700
|
||||||
|
#define UI_SPIN_Y0 874
|
||||||
|
#define UI_SPIN_X1 1220
|
||||||
|
#define UI_SPIN_Y1 1000
|
||||||
|
|
||||||
|
/* ---- 输入数据(referee_task 每周期填) ----------------------------------- */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
float pitch_deg; /* 云台 pitch(来自 CToC) */
|
||||||
|
float yaw_deg; /* 云台 yaw(来自 CToC 姿态帧) */
|
||||||
|
float hdg_deg; /* 底盘正方向朝向(本板 att_deg_yaw) */
|
||||||
|
float pwr_w; /* 底盘实时功率(裁判 0x0202) */
|
||||||
|
float pwr_limit_w; /* 功率上限(裁判 0x0201) */
|
||||||
|
float buf_j; /* 缓冲能量/超级电容(J) */
|
||||||
|
uint8_t cap_pct; /* 电容百分比(0~100) */
|
||||||
|
float fric_l_rpm; /* 左摩擦轮转速(来自 CToC) */
|
||||||
|
float fric_r_rpm; /* 右摩擦轮转速 */
|
||||||
|
uint8_t spin_on; /* 小陀螺使能 */
|
||||||
|
uint8_t ref_online; /* 裁判系统在线(离线时整屏删图形) */
|
||||||
|
} ui_data_t;
|
||||||
|
|
||||||
|
/* 周期调用(建议 5Hz):组包并发送;裁判系统离线时发一次"删除全部图层" */
|
||||||
|
extern void referee_ui_update(const ui_data_t * d);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,9 +6,8 @@
|
|||||||
* (无 legacy 的 +-1 圈限制,底盘小陀螺时 Yaw 可连续旋转),
|
* (无 legacy 的 +-1 圈限制,底盘小陀螺时 Yaw 可连续旋转),
|
||||||
* 记录 last_online_tick 供掉线检测
|
* 记录 last_online_tick 供掉线检测
|
||||||
* 控制路径(任务上下文):
|
* 控制路径(任务上下文):
|
||||||
* dji_motor_send_current_low/high() 0x200 / 0x1FF 电流帧(+/-16384 = 20A/10A)
|
* dji_motor_send_current_low/high() 0x200 / 0x1FF 电流帧(+/-16384 = 20A/10A)
|
||||||
* dji_motor_send_voltage_high() 0x2FF 电压帧(GM6020 ID5~7)
|
* dji_motor_send_gm6020_current_low/high() 0x1FE / 0x2FE GM6020 电流帧(+/-16384 = 3A)
|
||||||
* 注意 0x1FF 帧为 M3508/M2006 高位电流与 GM6020 低位电压共用,按槽位区分
|
|
||||||
* ========================================================================== */
|
* ========================================================================== */
|
||||||
#include "dji_motor.h"
|
#include "dji_motor.h"
|
||||||
|
|
||||||
@@ -20,7 +19,8 @@
|
|||||||
static dji_motor_t * dji_motor_list[DJI_MOTOR_MAX];
|
static dji_motor_t * dji_motor_list[DJI_MOTOR_MAX];
|
||||||
static uint8_t dji_motor_count = 0;
|
static uint8_t dji_motor_count = 0;
|
||||||
|
|
||||||
static void dji_motor_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc);
|
static void dji_motor_can1_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc);
|
||||||
|
static void dji_motor_can2_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc);
|
||||||
|
|
||||||
/* 解析一帧反馈,多圈累计(无 ±1 圈限制,底盘小陀螺时 Yaw 电机可连续旋转) */
|
/* 解析一帧反馈,多圈累计(无 ±1 圈限制,底盘小陀螺时 Yaw 电机可连续旋转) */
|
||||||
static void dji_motor_parse(dji_motor_t * motor, const uint8_t data[8])
|
static void dji_motor_parse(dji_motor_t * motor, const uint8_t data[8])
|
||||||
@@ -71,16 +71,32 @@ void dji_motor_init(dji_motor_t * motor, hcan_t * hcan, uint16_t rx_id, dji_moto
|
|||||||
if (dji_motor_count < DJI_MOTOR_MAX)
|
if (dji_motor_count < DJI_MOTOR_MAX)
|
||||||
{
|
{
|
||||||
dji_motor_list[dji_motor_count++] = motor;
|
dji_motor_list[dji_motor_count++] = motor;
|
||||||
can_rx_register(hcan, rx_id, dji_motor_rx_callback);
|
if (hcan == &hcan1)
|
||||||
|
can_rx_register(hcan, rx_id, dji_motor_can1_rx_callback);
|
||||||
|
else
|
||||||
|
can_rx_register(hcan, rx_id, dji_motor_can2_rx_callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dji_motor_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
|
static void dji_motor_can1_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
|
||||||
{
|
{
|
||||||
(void)dlc;
|
(void)dlc;
|
||||||
for (uint8_t i = 0; i < dji_motor_count; i++)
|
for (uint8_t i = 0; i < dji_motor_count; i++)
|
||||||
{
|
{
|
||||||
if (dji_motor_list[i]->rx_id == std_id)
|
if (dji_motor_list[i]->hcan == &hcan1 && dji_motor_list[i]->rx_id == std_id)
|
||||||
|
{
|
||||||
|
dji_motor_parse(dji_motor_list[i], rx_data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dji_motor_can2_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
|
||||||
|
{
|
||||||
|
(void)dlc;
|
||||||
|
for (uint8_t i = 0; i < dji_motor_count; i++)
|
||||||
|
{
|
||||||
|
if (dji_motor_list[i]->hcan == &hcan2 && dji_motor_list[i]->rx_id == std_id)
|
||||||
{
|
{
|
||||||
dji_motor_parse(dji_motor_list[i], rx_data);
|
dji_motor_parse(dji_motor_list[i], rx_data);
|
||||||
return;
|
return;
|
||||||
@@ -119,8 +135,14 @@ void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t
|
|||||||
dji_motor_send_int16x4(hcan, 0x1FF, v);
|
dji_motor_send_int16x4(hcan, 0x1FF, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dji_motor_send_voltage_high(hcan_t * hcan, int16_t v5, int16_t v6, int16_t v7)
|
void dji_motor_send_gm6020_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4)
|
||||||
{
|
{
|
||||||
const int16_t v[4] = {v5, v6, v7, 0};
|
const int16_t v[4] = {i1, i2, i3, i4};
|
||||||
dji_motor_send_int16x4(hcan, 0x2FF, v);
|
dji_motor_send_int16x4(hcan, 0x1FE, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dji_motor_send_gm6020_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8)
|
||||||
|
{
|
||||||
|
const int16_t v[4] = {i5, i6, i7, i8};
|
||||||
|
dji_motor_send_int16x4(hcan, 0x2FE, v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
/* DJI 电机(M3508/M2006/GM6020)统一驱动
|
/* DJI 电机(M3508/M2006/GM6020)统一驱动
|
||||||
* - 反馈:can_start() 后通过 can_rx_register 按 rx_id 注册,接收中断内解析(多圈累计)
|
* - 反馈:can_start() 后通过 can_rx_register 按 rx_id 注册,接收中断内解析(多圈累计)
|
||||||
* - 控制:组装 0x200/0x1FF/0x2FF 控制帧,经 CAN_SendTxMessage 发送 */
|
* - 控制:组装 0x200/0x1FF/0x1FE/0x2FE 控制帧,经 CAN_SendTxMessage 发送 */
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
DJI_MOTOR_3508, // 减速比 3591:187(≈19:1), 转矩常数 0.3N·m/A
|
DJI_MOTOR_3508, // 减速比 3591:187(≈19:1), 转矩常数 0.3N·m/A
|
||||||
DJI_MOTOR_2006, // 减速比 36:1, 转矩常数 0.18N·m/A
|
DJI_MOTOR_2006, // 减速比 36:1, 转矩常数 0.18N·m/A
|
||||||
DJI_MOTOR_6020, // 直驱, 电压控制
|
DJI_MOTOR_6020, // 直驱, 电流控制(ID1~4 为 0x1FE 帧, ±16384 对应 ±3A)
|
||||||
} dji_motor_type_e;
|
} dji_motor_type_e;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -20,7 +20,7 @@ typedef struct
|
|||||||
int64_t total_tick; // 累计角度位置原始数据(8192*圈数+raw,无 ±1 圈限制)
|
int64_t total_tick; // 累计角度位置原始数据(8192*圈数+raw,无 ±1 圈限制)
|
||||||
float rotor_angle_deg; // 累计转子机械角(°)
|
float rotor_angle_deg; // 累计转子机械角(°)
|
||||||
int16_t rotor_speed; // 转子转速(RPM)
|
int16_t rotor_speed; // 转子转速(RPM)
|
||||||
int16_t raw_torque; // 转矩电流/转矩电压原始数据
|
int16_t raw_torque; // 转矩电流原始数据
|
||||||
float torque_current; // 转矩电流(A)
|
float torque_current; // 转矩电流(A)
|
||||||
uint8_t temperature; // 电机温度(℃)
|
uint8_t temperature; // 电机温度(℃)
|
||||||
uint32_t last_online_tick; // 最近一次收到反馈的 tick(HAL_GetTick)
|
uint32_t last_online_tick; // 最近一次收到反馈的 tick(HAL_GetTick)
|
||||||
@@ -39,11 +39,12 @@ extern void dji_motor_init(dji_motor_t * motor, hcan_t * hcan, uint16_t rx_id, d
|
|||||||
|
|
||||||
/* ---- 控制帧发送 ----
|
/* ---- 控制帧发送 ----
|
||||||
* M3508/M2006 ID1~4:0x200 电流帧(±16384 对应 ±20A/±10A)
|
* M3508/M2006 ID1~4:0x200 电流帧(±16384 对应 ±20A/±10A)
|
||||||
* M3508/M2006 ID5~8:0x1FF 电流帧;GM6020 ID1~4:0x1FF 电压帧(±25000)
|
* M3508/M2006 ID5~8:0x1FF 电流帧(±16384)
|
||||||
* GM6020 ID5~7:0x2FF 电压帧 */
|
* GM6020 电流控制:ID1~4 为 0x1FE 电流帧(±16384 对应 ±3A),ID5~8 为 0x2FE 电流帧(±16384) */
|
||||||
extern void dji_motor_send_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
extern void dji_motor_send_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
||||||
extern void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
extern void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
||||||
extern void dji_motor_send_voltage_high(hcan_t * hcan, int16_t v5, int16_t v6, int16_t v7);
|
extern void dji_motor_send_gm6020_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
||||||
|
extern void dji_motor_send_gm6020_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
||||||
|
|
||||||
/* 通用 int16x4 发送(板间通讯等复用) */
|
/* 通用 int16x4 发送(板间通讯等复用) */
|
||||||
extern void dji_motor_send_int16x4(hcan_t * hcan, uint32_t std_id, const int16_t val[4]);
|
extern void dji_motor_send_int16x4(hcan_t * hcan, uint32_t std_id, const int16_t val[4]);
|
||||||
|
|||||||
Reference in New Issue
Block a user