键鼠控制(此前 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 一处校正。
91 lines
4.2 KiB
C
91 lines
4.2 KiB
C
#ifndef C_COMM_H
|
||
#define C_COMM_H
|
||
|
||
#include <stdint.h>
|
||
#include "bsp_can.h"
|
||
#include "dr16.h"
|
||
|
||
/* 云台<->底盘 板间通讯(CToC),帧 ID 与 legacy 完全一致
|
||
* 0x149 云台->底盘:Data[0..1]右摇杆RL [2..3]右摇杆UD [4..5]左摇杆RL [6..7]左摇杆UD(大端16bit)
|
||
* 0x189 云台->底盘:Data[0]遥控状态 [1]S2 [3]Shift翻转 [4]启动标志 [5]S1
|
||
* Data[2] 保留(原 Ctrl 翻转态——沿检测已移至云台侧,
|
||
* 底盘误判沿会误开小陀螺,勿再使用)
|
||
* Data[6] bit0=键1 bit1=键2 bit2=小陀螺使能(本工程扩展)
|
||
* bit7=云台电机故障(本工程扩展)
|
||
* 0x1A9 云台->底盘:Data[0..3]=云台世界系 yaw(float,LE)
|
||
* Data[4] flags:bit0=att_ready bit1=编码器tick增向为CCW
|
||
* bit2=该位有效(自检完成)
|
||
* (双 INS 跟随方案 + 跟随符号自动综合的数据源,2026-09)
|
||
* 0x019 底盘->云台:Data[0]发射机构上电状态 Data[1] bit0=底盘电机故障(本工程扩展)
|
||
*
|
||
* 故障位语义:任一侧电机掉线即置位,对侧收到后必须停止自己的输出(整车安全) */
|
||
|
||
/* 底盘板:从 0x149/0x189 解析出的"虚拟遥控器"数据(布局同 dr16_t 的子集) */
|
||
typedef struct
|
||
{
|
||
uint16_t rc_r_rl;
|
||
uint16_t rc_r_ud;
|
||
uint16_t rc_l_rl;
|
||
uint16_t rc_l_ud;
|
||
uint8_t s1;
|
||
uint8_t s2;
|
||
uint8_t ctrl_push;
|
||
uint8_t shift_push;
|
||
uint8_t start_flag;
|
||
uint8_t status; // 云台侧遥控器在线状态
|
||
uint8_t spin_flag; // 小陀螺使能(0x189 Data[6] bit2,云台侧沿检测)
|
||
uint8_t gimbal_fault; // 云台电机故障标志(0x189 Data[6] bit7)
|
||
uint32_t last_tick; // 最近收帧 tick(掉线检测)
|
||
} ctoc_remote_t;
|
||
|
||
extern volatile ctoc_remote_t ctoc_remote;
|
||
|
||
/* 云台板:底盘回传的发射机构上电状态 */
|
||
extern volatile uint8_t ctoc_shooter_power;
|
||
/* 云台板:最近收到 0x019 的 tick(掉线检测/诊断) */
|
||
extern volatile uint32_t ctoc_reply_last_tick;
|
||
/* 云台板:底盘电机故障标志(0x019 Data[1] bit0,ISR 内更新) */
|
||
extern volatile uint8_t ctoc_remote_fault;
|
||
|
||
/* 云台板:底盘故障综合判定(故障位置位 或 0x019 超时;从未收到过 0x019
|
||
* 视为底盘不在场不判故障,便于仅云台台架调试) */
|
||
extern uint8_t ctoc_chassis_fault(void);
|
||
|
||
/* 云台板:发送 0x1A9 姿态帧(2ms 周期,c_comm_task 调用)
|
||
* yaw_deg 为世界系多圈角(att_deg_yaw),flags bit0=att_ready */
|
||
extern void c_comm_master_send_attitude(float yaw_deg, uint8_t flags);
|
||
|
||
/* 底盘板:云台姿态(0x1A9 解析,ISR 内更新) */
|
||
extern volatile float ctoc_gimbal_yaw;
|
||
extern volatile uint8_t ctoc_att_ready;
|
||
/* 云台自检的编码器方向:+1=tick增向CCW -1=CW 0=未检测 */
|
||
extern volatile int8_t ctoc_encoder_ccw;
|
||
/* 底盘板:0x1A9 帧是否新鲜(掉线检测) */
|
||
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() 之后调用) */
|
||
extern void c_comm_init(void);
|
||
|
||
/* 云台板:发送摇杆帧与控制状态帧(2ms 周期,keyboard_online=1 时用键鼠合成量替代摇杆)
|
||
* kb 参数为图传 0x0304 解析出的键鼠数据(keyboard_online 时有效),布局:
|
||
* [0..1]鼠标X [2..3]鼠标Y [4..5]滚轮 [6]左键 [7]右键 [8]键位bitmap
|
||
* motor_fault:本板电机掉线标志,随 0x189 Data[6] bit7 广播 */
|
||
extern void c_comm_master_send(uint8_t keyboard_online, const uint8_t kb[12], uint8_t motor_fault, uint8_t spin_enable);
|
||
|
||
/* 底盘板:回传发射机构状态与底盘电机故障位(2ms 周期) */
|
||
extern void c_comm_slave_send(uint8_t motor_fault);
|
||
|
||
#endif
|