feat(ui): 新增裁判系统自定义UI(0x0301)并打通键鼠→底盘链路
键鼠控制(此前 WASD 无反应): - 云台 robot_cmd_task:0x0304 与 USART3 帧内键鼠合并为共享视图 keyboard_merged(0x0304 优先); 键鼠模式由帧内键鼠动作进入,动云台左摇杆退出 - c_comm_task/c_comm:键鼠在控时底盘摇杆由 WASD+鼠标合成,改读共享视图(此前只认 0x0304) - dr16/调试输出:新增帧内键鼠原始字节诊断(key_lo/key_hi/mouse_*/s1/frames) 自定义UI(底盘板经裁判系统 USART6 绘制到选手端): - 新增 底盘/modules/comms/referee_ui.c|h:15 字节图形组包(带编译期断言), v5 卡片式 HUD = 俯仰梯(pitch) + 罗盘刻度带(底盘朝向) + 预估底盘功率 + 超级电容 + 摩擦轮 L/R 转速 + 小陀螺状态,yaw 在刻度带右侧;5Hz 刷新,约 50 图元/8 包 - referee.c 新增 referee_send_frame()(cmd 0x0301 机器人交互数据,CRC8+CRC16,USART6 TX DMA) - 新增 CToC 0x1B9:云台把 pitch 与摩擦轮转速带给底盘(底盘本地没有这两个量) - 版式避开官方保留区:顶部比分条/左下小地图/右下战车模块/中部两块官方保留 验证:云台 Code=99540 RO=1764 RW=420 ZI=62572;底盘 Code=99452 RO=1928 RW=416 ZI=62584;均 0 错误 0 警告。 未做实机验证(当前无板/无图传);UI 协议常量(UI_RECEIVER_ID/UI_SEND_HZ)与版式坐标集中在 referee_ui.h 宏区,便于按协议 PDF 一处校正。
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* =============================================================================
|
||||
* debug_task.c - USB 虚拟串口(CDC)姿态输出(欧拉角 + 姿态链路诊断)
|
||||
* debug_task.c - USB 虚拟串口(CDC)姿态输出(欧拉角 + 姿态链路诊断 + 控制量/模式)
|
||||
* 每 DEBUG_OUT_PERIOD_MS 输出一行。单位: 角度 ° / 加速度 m/s² / 角速度 rad/s
|
||||
*
|
||||
* ---- 欧拉角(QuaternionEKF 解算结果,见 modules/ins) ----
|
||||
@@ -25,7 +25,20 @@
|
||||
* se bmi088_spi_errors:SPI/DMA 出错次数;st=bmi088_spi_state()
|
||||
* (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 "cmsis_os.h"
|
||||
@@ -35,6 +48,8 @@
|
||||
#include "attitude.h"
|
||||
#include "ins.h"
|
||||
#include "bmi088.h"
|
||||
#include "robot_typedef.h"
|
||||
#include "c_comm.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
@@ -42,13 +57,31 @@
|
||||
#define DEBUG_ATT_HEALTH 1
|
||||
/* 1-再附加原始陀螺/零偏/采样计数(排障用); 0-只留上面的通用健康位 */
|
||||
#define DEBUG_ATT_DIAG 1
|
||||
/* 1-追加控制量/控制模式(见文件头); 0-保持原姿态输出不变 */
|
||||
#define DEBUG_CMD_OUT 1
|
||||
|
||||
/* 输出周期(ms)。姿态观测建议 100ms(10Hz) */
|
||||
#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)
|
||||
{
|
||||
char line[192];
|
||||
char line[448];
|
||||
char tail[112];
|
||||
|
||||
for (;;)
|
||||
@@ -70,15 +103,29 @@ void debug_task(void const * argument)
|
||||
(unsigned long)bmi088_spi_errors, (unsigned)bmi088_spi_state());
|
||||
#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
|
||||
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,
|
||||
(unsigned)INS.ConvergeFlag, (unsigned)att_ready,
|
||||
(unsigned)bmi088_online, an, gn, tail);
|
||||
(unsigned)bmi088_online, an, gn, tail, ctl);
|
||||
#else
|
||||
int len = snprintf(line, sizeof(line), "yaw=%.2f pitch=%.2f roll=%.2f\r\n",
|
||||
att_deg_yaw, att_deg_pitch, att_deg_roll);
|
||||
int len = snprintf(line, sizeof(line), "yaw=%.2f pitch=%.2f roll=%.2f%s\r\n",
|
||||
att_deg_yaw, att_deg_pitch, att_deg_roll, ctl);
|
||||
#endif
|
||||
|
||||
if (len > 0)
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include "cmsis_os.h"
|
||||
#include "bsp_usart.h"
|
||||
#include "referee.h"
|
||||
#include "referee_ui.h"
|
||||
#include "c_comm.h"
|
||||
#include "attitude.h"
|
||||
#include "robot_param.h"
|
||||
|
||||
/* referee_task:裁判系统链路监测
|
||||
@@ -29,6 +32,37 @@ void referee_task(void const * argument)
|
||||
HAL_GetTick() - referee.last_update_tick > DEVICE_OFFLINE_TIME_MS * 10)
|
||||
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);
|
||||
osDelay(100);
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
#define CTOC_SLAVE_ID1 0x149 // 云台->底盘:摇杆数据
|
||||
#define CTOC_SLAVE_ID2 0x189 // 云台->底盘:控制状态+故障/陀螺使能位
|
||||
#define CTOC_SLAVE_ID3 0x1A9 // 云台->底盘:云台世界系 yaw(float)+att_ready
|
||||
#define CTOC_SLAVE_ID4 0x1B9 // 云台->底盘:UI 数据(pitch + 摩擦轮 L/R 转速)
|
||||
|
||||
/* ============================ CAN ID ============================ */
|
||||
/* 云台板:CAN1 = Pitch GM6020(0x206,0x1FE)+摩擦轮 M3508(0x201/0x202,0x200)
|
||||
|
||||
Reference in New Issue
Block a user