代码风格更新以及加入超电的对接

This commit is contained in:
lyf committed 2026-11-25 17:24:46 +08:00
1 parent 957c535bda
commit 9de485e4ef
117 files changed
+9046 -6457

No files matched your search

+58 -39
View File
@@ -1,8 +1,8 @@
/* =============================================================================
* referee_task.c - 裁判系统链路监测
* 解析在 USART6 空闲中断完成(referee_parse_bytes 流式喂入),
* 本任务仅做 100ms 周期的链路超时监测与心跳上报
* ========================================================================== */
/*
*文件名称:referee_task.c
*功能描述:裁判系统链路监测与自定义UI刷新任务(100ms)
*备注:数据解析在USART6空闲中断内完成,本任务负责超时监测、心跳上报与UI周期发送
*/
#include "app_tasks.h"
#include "cmsis_os.h"
#include "bsp_usart.h"
@@ -12,57 +12,76 @@
#include "attitude.h"
#include "robot_param.h"
/* referee_task:裁判系统链路监测
* 解析在接收中断完成(referee_parse_bytes),本任务仅做超时监测与心跳 */
/*
*函数简介:按UI_SEND_HZ分频组装并发送选手端自定义UI数据
*参数说明:无
*返回类型:无
*备注:内部函数,由referee_task每100ms调用一次
*/
static void referee_ui_step(void)
{
static uint8_t ui_div = 0U;
if (++ui_div < (uint8_t)(10U / UI_SEND_HZ))
return;
ui_div = 0U;
ui_data_t ui = {0};
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
? 100U
: (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);
}
/*
*函数简介:USART6裁判系统整帧接收回调
*参数说明:frame:接收帧数据指针
*参数说明:len:接收帧字节长度
*返回类型:无
*备注:将接收字节流喂入裁判系统解析状态机
*/
void referee_frame_callback(const uint8_t * frame, uint16_t len)
{
if (frame == NULL || len == 0U)
return;
referee_parse_bytes(frame, len);
}
/*
*函数简介:裁判系统链路超时监测与UI发送任务(100ms)
*参数说明:argument:FreeRTOS任务参数(未使用)
*返回类型:无
*备注:无
*/
void referee_task(void const * argument)
{
(void)argument;
while (!app_ready)
osDelay(2);
for (;;)
{
/* 链路超时置断线 */
if (referee.link_status &&
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)
* ------------------------------------------------------------------ */
(HAL_GetTick() - referee.last_update_tick > DEVICE_OFFLINE_TIME_MS * 10U))
{
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);
}
referee.link_status = 0U;//链路超时置断线
}
referee_ui_step();
monitor_heartbeat(HB_REFEREE);
osDelay(100);
}