From 3d7a4592c4c66a79d3ecb4a1c60a261f91187b57 Mon Sep 17 00:00:00 2001 From: guoxy06 <209087794@qq.com> Date: Fri, 3 Apr 2026 05:06:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=9B=E5=9C=BA=5Fv1.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chassis/chassis.c | 5 +++- application/cmd/robot_cmd.c | 10 ++++++++ application/gimbal/gimbal.c | 2 +- application/robot_def.h | 2 +- modules/referee/referee_task.c | 44 +++++++++++++++------------------- modules/referee/rm_referee.h | 5 +++- 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 2c87627..891c619 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -440,6 +440,9 @@ void ChassisTask() // 根据电机的反馈速度和IMU(如果有)计算真实速度 EstimateSpeed(); + // 将robot_level传递给UI数据 + ui_data.robot_level = chassis_cmd_recv.robot_level; + // // 获取裁判系统数据 建议将裁判系统与底盘分离,所以此处数据应使用消息中心发送 // // 我方颜色id小于7是红色,大于7是蓝色,注意这里发送的是对方的颜色, 0:blue , 1:red // chassis_feedback_data.enemy_color = referee_data->GameRobotState.robot_id > 7 ? 1 : 0; @@ -454,4 +457,4 @@ void ChassisTask() #ifdef CHASSIS_BOARD CANCommSend(chasiss_can_comm, (void *)&chassis_feedback_data); #endif // CHASSIS_BOARD -} +} \ No newline at end of file diff --git a/application/cmd/robot_cmd.c b/application/cmd/robot_cmd.c index 514071a..d3956d4 100644 --- a/application/cmd/robot_cmd.c +++ b/application/cmd/robot_cmd.c @@ -8,6 +8,7 @@ #include "message_center.h" #include "general_def.h" #include "dji_motor.h" +#include "referee_task.h" // bsp #include "bsp_dwt.h" #include "bsp_log.h" @@ -255,6 +256,15 @@ static void MouseKeySet() rc_data[TEMP].key_count[KEY_PRESS][Key_G] = 0; // 清除计数器,防止重复执行 } + // B键刷新裁判系统UI + if (rc_data[TEMP].key[KEY_PRESS].b && rc_data[TEMP].key_count[KEY_PRESS][Key_B] > 0) { + MyUIInit(); // 重新初始化UI + rc_data[TEMP].key_count[KEY_PRESS][Key_B] = 0; // 清除计数器,防止重复执行 + } + + // 将robot_level传递给底盘控制命令 + chassis_cmd_send.robot_level = robot_level; + switch (robot_level) { case 1: diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index 27de29b..e613b04 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -85,7 +85,7 @@ void GimbalInit() // }, .controller_param_init_config = { .angle_PID = { - .Kp = 0.75, //0.55 + .Kp = 1.00, //0.90 .Ki = 0.05,//0.05 .Kd = 0.02,//0.02 .CoefA =0.5,//0.5 diff --git a/application/robot_def.h b/application/robot_def.h index 7ee35df..7835bb2 100644 --- a/application/robot_def.h +++ b/application/robot_def.h @@ -154,7 +154,7 @@ typedef struct chassis_mode_e chassis_mode; int chassis_speed_buff; // UI部分 - // ... + uint8_t robot_level; // 机器人等级 } Chassis_Ctrl_Cmd_s; diff --git a/modules/referee/referee_task.c b/modules/referee/referee_task.c index 7971265..715e196 100644 --- a/modules/referee/referee_task.c +++ b/modules/referee/referee_task.c @@ -57,7 +57,7 @@ static Graph_Data_t UI_shoot_line[10]; // 射击准线 static Graph_Data_t UI_Energy[3]; // 电容能量条 static String_Data_t UI_State_sta[6]; // 机器人状态,静态只需画一次 static String_Data_t UI_State_dyn[6]; // 机器人状态,动态先add才能change -static uint32_t shoot_line_location[10] = {540, 960, 490, 515, 565}; +static uint32_t shoot_line_location[10] = {525, 950, 490, 515, 565}; void MyUIInit() { @@ -73,12 +73,12 @@ void MyUIInit() UILineDraw(&UI_shoot_line[0], "sl0", UI_Graph_ADD, 7, UI_Color_White, 3, 710, shoot_line_location[0], 1210, shoot_line_location[0]); UILineDraw(&UI_shoot_line[1], "sl1", UI_Graph_ADD, 7, UI_Color_White, 3, shoot_line_location[1], 340, shoot_line_location[1], 740); UILineDraw(&UI_shoot_line[2], "sl2", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[2], 1110, shoot_line_location[2]); - UILineDraw(&UI_shoot_line[3], "sl3", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[3], 1110, shoot_line_location[3]); + UILineDraw(&UI_shoot_line[3], "sl3", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 860, 475, 1060, 475); UILineDraw(&UI_shoot_line[4], "sl4", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[4], 1110, shoot_line_location[4]); UIGraphRefresh(&referee_recv_info->referee_id, 5, UI_shoot_line[0], UI_shoot_line[1], UI_shoot_line[2], UI_shoot_line[3], UI_shoot_line[4]); // 绘制车辆状态标志指示 - UICharDraw(&UI_State_sta[0], "ss0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 150, 750, "chassis:"); + UICharDraw(&UI_State_sta[0], "ss0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 150, 750, "level:"); UICharRefresh(&referee_recv_info->referee_id, UI_State_sta[0]); UICharDraw(&UI_State_sta[1], "ss1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 150, 700, "gimbal:"); UICharRefresh(&referee_recv_info->referee_id, UI_State_sta[1]); @@ -91,7 +91,7 @@ void MyUIInit() // 绘制车辆状态标志,动态 // 由于初始化时xxx_last_mode默认为0,所以此处对应UI也应该设为0时对应的UI,防止模式不变的情况下无法置位flag,导致UI无法刷新 - UICharDraw(&UI_State_dyn[0], "sd0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 270, 750, "zeroforce"); + UICharDraw(&UI_State_dyn[0], "sd0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 270, 750, "1"); UICharRefresh(&referee_recv_info->referee_id, UI_State_dyn[0]); UICharDraw(&UI_State_dyn[1], "sd1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 270, 700, "zeroforce"); UICharRefresh(&referee_recv_info->referee_id, UI_State_dyn[1]); @@ -116,7 +116,7 @@ void MyUIInit() UIGraphRefresh(&referee_recv_info->referee_id, 2, UI_Energy[1], UI_Energy[2]); } -// 测试用函数,实现模式自动变化,用于检查该任务和裁判系统是否连接正常 +// 测试用函数,实现模式自动变化,用于检查该任务和裁判系统是否连接正常. static uint8_t count = 0; static uint16_t count1 = 0; static void RobotModeTest(Referee_Interactive_info_t *_Interactive_data) // 测试用函数,实现模式自动变化 @@ -176,27 +176,15 @@ static void RobotModeTest(Referee_Interactive_info_t *_Interactive_data) // 测 static void MyUIRefresh(referee_info_t *referee_recv_info, Referee_Interactive_info_t *_Interactive_data) { UIChangeCheck(_Interactive_data); - // chassis - if (_Interactive_data->Referee_Interactive_Flag.chassis_flag == 1) + // robot level + if (_Interactive_data->Referee_Interactive_Flag.robot_level_flag == 1) { - switch (_Interactive_data->chassis_mode) - { - case CHASSIS_ZERO_FORCE: - UICharDraw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "zeroforce"); - break; - case CHASSIS_ROTATE: - UICharDraw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "rotate "); - // 此处注意字数对齐问题,字数相同才能覆盖掉 - break; - case CHASSIS_NO_FOLLOW: - UICharDraw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "nofollow "); - break; - case CHASSIS_FOLLOW_GIMBAL_YAW: - UICharDraw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "follow "); - break; - } + char level_str[2]; + level_str[0] = '0' + _Interactive_data->robot_level; + level_str[1] = '\0'; + UICharDraw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, level_str); UICharRefresh(&referee_recv_info->referee_id, UI_State_dyn[0]); - _Interactive_data->Referee_Interactive_Flag.chassis_flag = 0; + _Interactive_data->Referee_Interactive_Flag.robot_level_flag = 0; } // gimbal if (_Interactive_data->Referee_Interactive_Flag.gimbal_flag == 1) @@ -261,6 +249,12 @@ static void MyUIRefresh(referee_info_t *referee_recv_info, Referee_Interactive_i */ static void UIChangeCheck(Referee_Interactive_info_t *_Interactive_data) { + if (_Interactive_data->robot_level != _Interactive_data->robot_last_level) + { + _Interactive_data->Referee_Interactive_Flag.robot_level_flag = 1; + _Interactive_data->robot_last_level = _Interactive_data->robot_level; + } + if (_Interactive_data->chassis_mode != _Interactive_data->chassis_last_mode) { _Interactive_data->Referee_Interactive_Flag.chassis_flag = 1; @@ -296,4 +290,4 @@ static void UIChangeCheck(Referee_Interactive_info_t *_Interactive_data) _Interactive_data->Referee_Interactive_Flag.Power_flag = 1; _Interactive_data->Chassis_last_Power_Data.chassis_power_mx = _Interactive_data->Chassis_Power_Data.chassis_power_mx; } -} +} \ No newline at end of file diff --git a/modules/referee/rm_referee.h b/modules/referee/rm_referee.h index e935e94..3b5b323 100644 --- a/modules/referee/rm_referee.h +++ b/modules/referee/rm_referee.h @@ -54,6 +54,7 @@ typedef struct uint32_t lid_flag : 1; uint32_t friction_flag : 1; uint32_t Power_flag : 1; + uint32_t robot_level_flag : 1; } Referee_Interactive_Flag_t; // 此结构体包含UI绘制与机器人车间通信的需要的其他非裁判系统数据 @@ -61,6 +62,7 @@ typedef struct { Referee_Interactive_Flag_t Referee_Interactive_Flag; // 为UI绘制以及交互数据所用 + uint8_t robot_level; // 机器人等级 chassis_mode_e chassis_mode; // 底盘模式 gimbal_mode_e gimbal_mode; // 云台模式 shoot_mode_e shoot_mode; // 发射模式设置 @@ -69,6 +71,7 @@ typedef struct Chassis_Power_Data_s Chassis_Power_Data; // 功率控制 // 上一次的模式,用于flag判断 + uint8_t robot_last_level; chassis_mode_e chassis_last_mode; gimbal_mode_e gimbal_last_mode; shoot_mode_e shoot_last_mode; @@ -97,4 +100,4 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle); */ void RefereeSend(uint8_t *send, uint16_t tx_len); -#endif // !REFEREE_H +#endif // !REFEREE_H \ No newline at end of file