重新组织了裁判系统相关模块的结构

This commit is contained in:
NeoZng 2023-04-19 18:52:40 +08:00
parent 5c9c7962c8
commit f6c686598d
18 changed files with 615 additions and 704 deletions

View File

@ -145,7 +145,7 @@ modules/oled/oled.c \
modules/referee/crc_ref.c \ modules/referee/crc_ref.c \
modules/referee/rm_referee.c \ modules/referee/rm_referee.c \
modules/referee/referee_UI.c \ modules/referee/referee_UI.c \
modules/referee/referee_communication.c \ modules/referee/referee_task.c \
modules/remote/remote_control.c \ modules/remote/remote_control.c \
modules/super_cap/super_cap.c \ modules/super_cap/super_cap.c \
modules/can_comm/can_comm.c \ modules/can_comm/can_comm.c \
@ -155,7 +155,6 @@ modules/vofa/vofa.c \
application/gimbal/gimbal.c \ application/gimbal/gimbal.c \
application/chassis/chassis.c \ application/chassis/chassis.c \
application/shoot/shoot.c \ application/shoot/shoot.c \
application/referee/referee.c \
application/cmd/robot_cmd.c \ application/cmd/robot_cmd.c \
application/balance_chassis/balance.c \ application/balance_chassis/balance.c \
application/robot.c application/robot.c
@ -237,7 +236,6 @@ C_INCLUDES = \
-Iapplication/gimbal \ -Iapplication/gimbal \
-Iapplication/cmd \ -Iapplication/cmd \
-Iapplication/balance_chassis \ -Iapplication/balance_chassis \
-Iapplication/referee \
-Iapplication \ -Iapplication \
-Ibsp/dwt \ -Ibsp/dwt \
-Ibsp/can \ -Ibsp/can \

View File

@ -28,6 +28,7 @@
#include "ins_task.h" #include "ins_task.h"
#include "motor_task.h" #include "motor_task.h"
#include "led_task.h" #include "led_task.h"
#include "referee_task.h"
#include "daemon.h" #include "daemon.h"
#include "robot.h" #include "robot.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -62,6 +63,10 @@ void StartMOTORTASK(void const * argument);
void StartDAEMONTASK(void const *argument); void StartDAEMONTASK(void const *argument);
void StartROBOTTASK(void const *argument); void StartROBOTTASK(void const *argument);
void StartROBOTTASK(void const *argument);
void StartUITASK(void const *argument);
/* USER CODE END FunctionPrototypes */ /* USER CODE END FunctionPrototypes */
void StartDefaultTask(void const *argument); void StartDefaultTask(void const *argument);
@ -90,7 +95,8 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackTy
* @param None * @param None
* @retval None * @retval None
*/ */
void MX_FREERTOS_Init(void) { void MX_FREERTOS_Init(void)
{
/* USER CODE BEGIN Init */ /* USER CODE BEGIN Init */
/* USER CODE END Init */ /* USER CODE END Init */
@ -129,8 +135,11 @@ void MX_FREERTOS_Init(void) {
osThreadDef(robottask, StartROBOTTASK, osPriorityNormal, 0, 1024); osThreadDef(robottask, StartROBOTTASK, osPriorityNormal, 0, 1024);
defaultTaskHandle = osThreadCreate(osThread(robottask), NULL); defaultTaskHandle = osThreadCreate(osThread(robottask), NULL);
/* USER CODE END RTOS_THREADS */
osThreadDef(uitask, StartUITASK, osPriorityNormal, 0, 512);
defaultTaskHandle = osThreadCreate(osThread(uitask), NULL);
/* USER CODE END RTOS_THREADS */
} }
/* USER CODE BEGIN Header_StartDefaultTask */ /* USER CODE BEGIN Header_StartDefaultTask */
@ -160,7 +169,7 @@ void StartINSTASK(void const * argument)
while (1) while (1)
{ {
// 1kHz // 1kHz
INS_Task(); // INS_Task();
osDelay(1); osDelay(1);
} }
} }
@ -191,7 +200,16 @@ void StartROBOTTASK(void const * argument)
{ {
// 200Hz // 200Hz
RobotTask(); RobotTask();
osDelay(10);//syh此处æšæ—¶å°†æ—¶é—´æ”¹ä¸?10ms,原å åœ¨äºŽæœªä½¿ç”¨ç¼“冲区å<C2BA>é€<C3A9>,å<C592>é?<3F>时延时5ms osDelay(10); // syh此处暂时将时间改<E997B4>?10ms原因在于未使用缓冲区发送<EFBC8C>?<3F>时延时5ms
}
}
void StartUITASK(void const *argument)
{
Referee_Interactive_init();
while (1)
{
Referee_Interactive_task();
} }
} }
/* USER CODE END Application */ /* USER CODE END Application */

View File

@ -7,11 +7,11 @@
#include "HT04.h" #include "HT04.h"
#include "LK9025.h" #include "LK9025.h"
#include "bmi088.h" #include "bmi088.h"
#include "referee.h"
#include "super_cap.h" #include "super_cap.h"
#include "controller.h" #include "controller.h"
#include "can_comm.h" #include "can_comm.h"
#include "user_lib.h" #include "user_lib.h"
#include "rm_referee.h"
// standard // standard
#include "stdint.h" #include "stdint.h"
#include "arm_math.h" // 需要用到较多三角函数 #include "arm_math.h" // 需要用到较多三角函数

View File

@ -16,12 +16,7 @@
#include "dji_motor.h" #include "dji_motor.h"
#include "super_cap.h" #include "super_cap.h"
#include "message_center.h" #include "message_center.h"
// referee需要移动到module层
/////////////////////////
#include "rm_referee.h" #include "rm_referee.h"
/////////////////////////
#include "general_def.h" #include "general_def.h"
#include "bsp_dwt.h" #include "bsp_dwt.h"
@ -47,6 +42,9 @@ static Subscriber_t *chassis_sub; // 用于订阅底盘的控
static Chassis_Ctrl_Cmd_s chassis_cmd_recv; // 底盘接收到的控制命令 static Chassis_Ctrl_Cmd_s chassis_cmd_recv; // 底盘接收到的控制命令
static Chassis_Upload_Data_s chassis_feedback_data; // 底盘回传的反馈数据 static Chassis_Upload_Data_s chassis_feedback_data; // 底盘回传的反馈数据
static referee_info_t* referee_data; // 用于获取裁判系统的数据
static Referee_Interactive_info_t ui_data; // UI数据
static SuperCapInstance *cap; // 超级电容 static SuperCapInstance *cap; // 超级电容
static DJIMotorInstance *motor_lf, *motor_rf, *motor_lb, *motor_rb; // left right forward back static DJIMotorInstance *motor_lf, *motor_rf, *motor_lb, *motor_rb; // left right forward back
@ -105,7 +103,7 @@ void ChassisInit()
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE; chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE;
motor_rb = DJIMotorInit(&chassis_motor_config); motor_rb = DJIMotorInit(&chassis_motor_config);
// referee_data = RefereeInit(&huart6); // 裁判系统初始化 referee_data = RefereeInit(&huart6,&ui_data); // 裁判系统初始化
// while (referee_data->GameRobotState.robot_id ==0); // while (referee_data->GameRobotState.robot_id ==0);
// Referee_Interactive_init(referee_data); // Referee_Interactive_init(referee_data);

View File

@ -1,50 +0,0 @@
#ifndef REFEREE_H
#define REFEREE_H
#include "rm_referee.h"
#include "robot_def.h"
#pragma pack(1)
//模式是否切换标志位0为未切换1为切换static定义默认为0
typedef struct
{
uint32_t chassis_flag : 1;
uint32_t gimbal_flag : 1;
uint32_t shoot_flag : 1;
uint32_t lid_flag : 1;
uint32_t friction_flag : 1;
uint32_t Power_flag : 1;
} Referee_Interactive_Flag_t;
// 此结构体包含UI绘制与机器人车间通信的需要的其他非裁判系统数据
typedef struct
{
Referee_Interactive_Flag_t Referee_Interactive_Flag;
//为UI绘制以及交互数据所用
Robot_Status_e Robot_Status;// 机器人状态
App_Status_e App_Status;// 应用状态
chassis_mode_e chassis_mode;//底盘模式
gimbal_mode_e gimbal_mode;//云台模式
shoot_mode_e shoot_mode;//发射模式设置
friction_mode_e friction_mode;//摩擦轮关闭
lid_mode_e lid_mode;//弹舱盖打开
loader_mode_e loader_mode;//单发...连发
Chassis_Power_Data_s Chassis_Power_Data;// 功率控制
chassis_mode_e chassis_last_mode;//底盘模式
gimbal_mode_e gimbal_last_mode;//云台模式
shoot_mode_e shoot_last_mode;//发射模式设置
friction_mode_e friction_last_mode;//摩擦轮关闭
lid_mode_e lid_last_mode;//弹舱盖打开
} Referee_Interactive_info_t;
#pragma pack()
void Referee_Interactive_init(void);
void Referee_Interactive_task(void);
#endif // REFEREE_H

View File

@ -1,3 +0,0 @@
# referee
需要将此模块移动到module层并新建一个rtos任务以一定频率运行用于ui刷新和多机通信

View File

@ -22,7 +22,6 @@
#include "balance.h" #include "balance.h"
#endif // BALANCE_BOARD #endif // BALANCE_BOARD
void RobotInit() void RobotInit()
{ {
// 关闭中断,防止在初始化过程中发生中断 // 关闭中断,防止在初始化过程中发生中断
@ -39,7 +38,7 @@ void RobotInit()
#endif #endif
#if defined(ONE_BOARD) || defined(CHASSIS_BOARD) #if defined(ONE_BOARD) || defined(CHASSIS_BOARD)
// ChassisInit(); ChassisInit();
#endif #endif
#ifdef BALANCE_BAORD #ifdef BALANCE_BAORD
@ -48,7 +47,6 @@ void RobotInit()
// 初始化完成,开启中断 // 初始化完成,开启中断
__enable_irq(); __enable_irq();
Referee_Interactive_init();
} }
void RobotTask() void RobotTask()

View File

@ -1,3 +1 @@
# referee # referee
当前模块组织较为混乱,后续统一为多机通信+裁判系统信息接收+UI绘制。UI绘制和多机通信的发送部分在referee任务中以一定的频率运行信息的接收通过中断完成。

View File

@ -10,7 +10,7 @@
*/ */
#include "referee_UI.h" #include "referee_UI.h"
#include "string.h" #include "string.h"
#include "crc.h" #include "crc_ref.h"
#include "stdio.h" #include "stdio.h"
#include "rm_referee.h" #include "rm_referee.h"
@ -20,7 +20,7 @@
Del_Operate Del_Operate
Del_Layer 0-9 Del_Layer 0-9
*****************************************************************************************/ *****************************************************************************************/
void UI_Delete(referee_id_t *_id, uint8_t Del_Operate, uint8_t Del_Layer) void UIDelete(referee_id_t *_id, uint8_t Del_Operate, uint8_t Del_Layer)
{ {
UI_delete_t UI_delete_data; UI_delete_t UI_delete_data;
uint8_t temp_datalength = Interactive_Data_LEN_Head + UI_Operate_LEN_Del; // 计算交互数据长度 uint8_t temp_datalength = Interactive_Data_LEN_Head + UI_Operate_LEN_Del; // 计算交互数据长度
@ -42,7 +42,7 @@ void UI_Delete(referee_id_t *_id, uint8_t Del_Operate, uint8_t Del_Layer)
UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF); UI_delete_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF);
/* 填入0xFFFF,关于crc校验 */ /* 填入0xFFFF,关于crc校验 */
RefereeLoadToBuffer((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送 RefereeSend((uint8_t *)&UI_delete_data, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送
UI_Seq++; // 包序号+1 UI_Seq++; // 包序号+1
} }
@ -306,9 +306,13 @@ void Integer_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate
Graph_Size Graph_Size
Graph_Width 线 Graph_Width 线
Start_xStart_y Start_xStart_y
***graph Graph_Data类型变量指针
fmt需要显示的字符串
使printf函数
**********************************************************************************************************/ **********************************************************************************************************/
void Char_Draw(String_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, void Char_Draw(String_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color,
uint32_t Graph_Size, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y) uint32_t Graph_Size, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, char *fmt, ...)
{ {
int i; int i;
for (i = 0; i < 3 && graphname[i] != '\0'; i++) for (i = 0; i < 3 && graphname[i] != '\0'; i++)
@ -328,22 +332,12 @@ void Char_Draw(String_Data_t *graph, char graphname[3], uint32_t Graph_Operate,
graph->Graph_Control.radius = 0; graph->Graph_Control.radius = 0;
graph->Graph_Control.end_x = 0; graph->Graph_Control.end_x = 0;
graph->Graph_Control.end_y = 0; graph->Graph_Control.end_y = 0;
}
/************************************************绘制字符型数据*************************************************
***graph Graph_Data类型变量指针
fmt需要显示的字符串
使printf函数
**********************************************************************************************************/
void Char_Write(String_Data_t *graph, char *fmt, ...)
{
uint16_t i = 0;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsprintf((char *)graph->show_Data, fmt, ap); // 使用参数列表进行格式化并输出到字符串 vsprintf((char *)graph->show_Data, fmt, ap); // 使用参数列表进行格式化并输出到字符串
va_end(ap); va_end(ap);
i = strlen((const char *)graph->show_Data); graph->Graph_Control.end_angle = strlen((const char *)graph->show_Data);
graph->Graph_Control.end_angle = i;
} }
/* UI推送函数使更改生效 /* UI推送函数使更改生效
@ -353,10 +347,13 @@ void Char_Write(String_Data_t *graph, char *fmt, ...)
*/ */
void UI_ReFresh(referee_id_t *_id, int cnt, ...) void UI_ReFresh(referee_id_t *_id, int cnt, ...)
{ {
int i;
UI_GraphReFresh_t UI_GraphReFresh_data; UI_GraphReFresh_t UI_GraphReFresh_data;
Graph_Data_t graphData; Graph_Data_t graphData;
uint8_t temp_datalength = LEN_HEADER + LEN_CMDID + Interactive_Data_LEN_Head + UI_Operate_LEN_PerDraw * cnt + LEN_TAIL; // 计算交互数据长度
uint8_t buffer[temp_datalength]; // 交互数据缓存
va_list ap; // 创建一个 va_list 类型变量 va_list ap; // 创建一个 va_list 类型变量
va_start(ap, cnt); // 初始化 va_list 变量为一个参数列表 va_start(ap, cnt); // 初始化 va_list 变量为一个参数列表
@ -385,23 +382,17 @@ void UI_ReFresh(referee_id_t *_id, int cnt, ...)
UI_GraphReFresh_data.datahead.receiver_ID = _id->Cilent_ID; UI_GraphReFresh_data.datahead.receiver_ID = _id->Cilent_ID;
UI_GraphReFresh_data.datahead.sender_ID = _id->Robot_ID; UI_GraphReFresh_data.datahead.sender_ID = _id->Robot_ID;
memcpy(buffer, (uint8_t *)&UI_GraphReFresh_data, LEN_HEADER + LEN_CMDID + Interactive_Data_LEN_Head); // 将帧头、命令码、交互数据帧头三部分复制到缓存中
// 先发送帧头、命令码、交互数据帧头三部分并计算CRC16校验值 for (uint8_t i = 0; i < cnt; i++) // 发送交互数据的数据帧并计算CRC16校验值
UI_GraphReFresh_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_GraphReFresh_data, LEN_HEADER + LEN_CMDID + Interactive_Data_LEN_Head, 0xFFFF);
RefereeLoadToBuffer((uint8_t *)&UI_GraphReFresh_data, LEN_HEADER + LEN_CMDID + Interactive_Data_LEN_Head);
for (i = 0; i < cnt; i++) // 发送交互数据的数据帧并计算CRC16校验值
{ {
graphData = va_arg(ap, Graph_Data_t); // 访问参数列表中的每个项,第二个参数是你要返回的参数的类型,在取值时需要将其强制转化为指定类型的变量 graphData = va_arg(ap, Graph_Data_t); // 访问参数列表中的每个项,第二个参数是你要返回的参数的类型,在取值时需要将其强制转化为指定类型的变量
// 发送并计算CRC16 memcpy(buffer + (LEN_HEADER + LEN_CMDID + Interactive_Data_LEN_Head + UI_Operate_LEN_PerDraw * i), (uint8_t *)&graphData, UI_Operate_LEN_PerDraw);
RefereeLoadToBuffer((uint8_t *)&graphData, UI_Operate_LEN_PerDraw);
UI_GraphReFresh_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&graphData, UI_Operate_LEN_PerDraw, UI_GraphReFresh_data.frametail);
} }
Append_CRC16_Check_Sum(buffer,temp_datalength);
RefereeLoadToBuffer((uint8_t *)&UI_GraphReFresh_data.frametail, LEN_TAIL); // 发送CRC16校验值 RefereeSend(buffer, temp_datalength); // 发送CRC16校验值
va_end(ap); // 结束可变参数的获取 va_end(ap); // 结束可变参数的获取
UI_Seq++; // 包序号+1
} }
/************************************************UI推送字符使更改生效*********************************/ /************************************************UI推送字符使更改生效*********************************/
@ -427,7 +418,7 @@ void Char_ReFresh(referee_id_t *_id, String_Data_t string_Data)
UI_CharReFresh_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_CharReFresh_data, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF); UI_CharReFresh_data.frametail = Get_CRC16_Check_Sum((uint8_t *)&UI_CharReFresh_data, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF);
RefereeLoadToBuffer((uint8_t *)&UI_CharReFresh_data, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送 RefereeSend((uint8_t *)&UI_CharReFresh_data, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送
UI_Seq++; // 包序号+1 UI_Seq++; // 包序号+1
} }

View File

@ -3,7 +3,7 @@
#include "stdarg.h" #include "stdarg.h"
#include "stdint.h" #include "stdint.h"
#include "referee_def.h" #include "referee_protocol.h"
#include "rm_referee.h" #include "rm_referee.h"
#pragma pack(1) // 按1字节对齐 #pragma pack(1) // 按1字节对齐
@ -38,10 +38,7 @@ typedef struct
#pragma pack() #pragma pack()
void UIDelete(referee_id_t *_id, uint8_t Del_Operate, uint8_t Del_Layer);
void UI_Delete(referee_id_t *_id,uint8_t Del_Operate,uint8_t Del_Layer);
void Line_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, void Line_Draw(Graph_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color,
uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, uint32_t End_x, uint32_t End_y); uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, uint32_t End_x, uint32_t End_y);
@ -66,9 +63,7 @@ void Integer_Draw(Graph_Data_t *graph,char graphname[3],uint32_t Graph_Operate,u
uint32_t Graph_Size, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, int32_t Graph_Integer); uint32_t Graph_Size, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, int32_t Graph_Integer);
void Char_Draw(String_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color, void Char_Draw(String_Data_t *graph, char graphname[3], uint32_t Graph_Operate, uint32_t Graph_Layer, uint32_t Graph_Color,
uint32_t Graph_Size,uint32_t Graph_Width,uint32_t Start_x,uint32_t Start_y); uint32_t Graph_Size, uint32_t Graph_Width, uint32_t Start_x, uint32_t Start_y, char *fmt, ...);
void Char_Write(String_Data_t *graph,char* fmt, ...);
void UI_ReFresh(referee_id_t *_id, int cnt, ...); void UI_ReFresh(referee_id_t *_id, int cnt, ...);

View File

@ -1,45 +0,0 @@
/**
* @file referee_communication.h
* @author kidneygood (you@domain.com)
* @version 0.1
* @date 2022-12-02
*
* @copyright Copyright (c) HNU YueLu EC 2022 all rights reserved
*
*/
#include "referee_communication.h"
#include "crc_ref.h"
#include "stdio.h"
#include "rm_referee.h"
/**
* @brief
* @param referee_id_t *_id sender为本机器人receiver为接收方机器人Receiver_Robot_ID再调用该函数
* robot_interactive_data_t *data
* @retval none
* @attention
*/
void Communicate_SendData(referee_id_t *_id,robot_interactive_data_t *_data)
{
Communicate_SendData_t SendData;
uint8_t temp_datalength = Interactive_Data_LEN_Head + Communicate_Data_LEN; // 计算交互数据长度 6+n,n为交互数据长度
SendData.FrameHeader.SOF = REFEREE_SOF;
SendData.FrameHeader.DataLength = temp_datalength;
SendData.FrameHeader.Seq = UI_Seq;
SendData.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&SendData, LEN_CRC8, 0xFF);
SendData.CmdID = ID_student_interactive;
SendData.datahead.data_cmd_id = Communicate_Data_ID;
SendData.datahead.sender_ID = _id->Robot_ID;
SendData.datahead.receiver_ID = _id->Receiver_Robot_ID;
SendData.Data = *_data;
SendData.frametail = Get_CRC16_Check_Sum((uint8_t *)&SendData,LEN_HEADER+LEN_CMDID+temp_datalength,0xFFFF);
RefereeLoadToBuffer((uint8_t *)&SendData,LEN_HEADER+LEN_CMDID+temp_datalength+LEN_TAIL); //发送
UI_Seq++; // 包序号+1
}

View File

@ -1,10 +0,0 @@
#ifndef REFEREE_COMMUNICATION_H
#define REFEREE_COMMUNICATION_H
#include "stdint.h"
#include "referee_def.h"
#include "rm_referee.h"
void Communicate_SendData(referee_id_t *_id,robot_interactive_data_t *_data);
#endif

View File

@ -1,5 +1,5 @@
/** /**
* @file referee_def.h * @file referee_protocol.h
* @author kidneygood (you@domain.com) * @author kidneygood (you@domain.com)
* @version 0.1 * @version 0.1
* @date 2022-12-02 * @date 2022-12-02
@ -8,12 +8,11 @@
* *
*/ */
#ifndef REFEREE_DEF_H #ifndef referee_protocol_H
#define REFEREE_DEF_H #define referee_protocol_H
#include "stdint.h" #include "stdint.h"
/****************************宏定义部分****************************/
/****************************宏定义部分****************************/ /****************************宏定义部分****************************/
#define REFEREE_SOF 0xA5 // 起始字节,协议固定为0xA5 #define REFEREE_SOF 0xA5 // 起始字节,协议固定为0xA5
@ -23,7 +22,6 @@
#pragma pack(1) #pragma pack(1)
/****************************通信协议格式****************************/
/****************************通信协议格式****************************/ /****************************通信协议格式****************************/
/* 通信协议格式偏移,枚举类型,代替#define声明 */ /* 通信协议格式偏移,枚举类型,代替#define声明 */
@ -290,7 +288,6 @@ typedef enum
} Interactive_Data_Length_e; } Interactive_Data_Length_e;
/****************************自定义交互数据****************************/
/****************************自定义交互数据****************************/ /****************************自定义交互数据****************************/
/* /*
cmd_id 0x0301 ID:0x0200~0x02FF cmd_id 0x0301 ID:0x0200~0x02FF
@ -319,8 +316,6 @@ typedef struct
robot_interactive_data_t Data; // 数据段 robot_interactive_data_t Data; // 数据段
} Communicate_ReceiveData_t; } Communicate_ReceiveData_t;
/****************************UI交互数据****************************/
/****************************UI交互数据****************************/ /****************************UI交互数据****************************/
/* 图形数据 */ /* 图形数据 */

View File

@ -8,17 +8,15 @@
* @copyright Copyright (c) 2022 * @copyright Copyright (c) 2022
* *
*/ */
#include "referee.h" #include "referee_task.h"
#include "robot_def.h" #include "robot_def.h"
#include "rm_referee.h" #include "rm_referee.h"
#include "referee_UI.h" #include "referee_UI.h"
#include "referee_communication.h"
static Referee_Interactive_info_t Interactive_data; // 非裁判系统数据 static Referee_Interactive_info_t *Interactive_data; // UI绘制需要的机器人状态数据
static referee_info_t *referee_data; // 裁判系统相关数据 static referee_info_t *referee_recv_info; // 接收到的裁判系统数据
static robot_interactive_data_t *SendData;
static void determine_ID(referee_info_t *_referee_info); static void DeterminRobotID(referee_info_t *_referee_info);
static void My_UI_init(referee_info_t *_referee_info); static void My_UI_init(referee_info_t *_referee_info);
static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data); static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_info_t *_Interactive_data);
static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data); // 模式切换检测 static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data); // 模式切换检测
@ -29,23 +27,16 @@ static void UI_test_init(referee_info_t *_referee_info); //
void Referee_Interactive_init() void Referee_Interactive_init()
{ {
referee_data = RefereeInit(&huart6); // 裁判系统初始化 RefereeGetUIData(&referee_recv_info, &Interactive_data);
// while (referee_data->GameRobotState.robot_id == 0); while (referee_recv_info->GameRobotState.robot_id == 0);
referee_data->GameRobotState.robot_id = 103; // syhtodo RobotInit中关闭了中断进行初始化无法读取到裁判系统的ID暂时在此处写死 DeterminRobotID(referee_recv_info);
determine_ID(referee_data); My_UI_init(referee_recv_info);
My_UI_init(referee_data);
// UI_test_init(referee_data); // 测试函数
RefereeSend();
//如果此处还要加入车间通信初始化注意将referee和车间通信的数据合并后再使用
//refereesend函数永远是最后一步
//串口接收需要设置喂狗
} }
void Referee_Interactive_task() void Referee_Interactive_task()
{ {
robot_mode_change(&Interactive_data); // 测试用函数,实现模式自动变化 robot_mode_change(Interactive_data); // 测试用函数,实现模式自动变化
My_UI_Refresh(referee_data, &Interactive_data); My_UI_Refresh(referee_recv_info, Interactive_data);
} }
static Graph_Data_t UI_shoot_line[10]; // 射击准线 static Graph_Data_t UI_shoot_line[10]; // 射击准线
@ -55,9 +46,9 @@ static uint32_t shoot_line_location[10] = {540, 960, 490, 515, 565};
static void My_UI_init(referee_info_t *_referee_info) static void My_UI_init(referee_info_t *_referee_info)
{ {
UI_Delete(&_referee_info->referee_id, UI_Data_Del_ALL, 0); UIDelete(&_referee_info->referee_id, UI_Data_Del_ALL, 0);
// 绘制发射基准线 // // 绘制发射基准线
Line_Draw(&UI_shoot_line[0], "sl0", UI_Graph_ADD, 7, UI_Color_White, 3, 710, shoot_line_location[0], 1210, shoot_line_location[0]); Line_Draw(&UI_shoot_line[0], "sl0", UI_Graph_ADD, 7, UI_Color_White, 3, 710, shoot_line_location[0], 1210, shoot_line_location[0]);
Line_Draw(&UI_shoot_line[1], "sl1", UI_Graph_ADD, 7, UI_Color_White, 3, shoot_line_location[1], 340, shoot_line_location[1], 740); Line_Draw(&UI_shoot_line[1], "sl1", UI_Graph_ADD, 7, UI_Color_White, 3, shoot_line_location[1], 340, shoot_line_location[1], 740);
Line_Draw(&UI_shoot_line[2], "sl2", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[2], 1110, shoot_line_location[2]); Line_Draw(&UI_shoot_line[2], "sl2", UI_Graph_ADD, 7, UI_Color_Yellow, 2, 810, shoot_line_location[2], 1110, shoot_line_location[2]);
@ -66,57 +57,37 @@ static void My_UI_init(referee_info_t *_referee_info)
UI_ReFresh(&_referee_info->referee_id, 5, UI_shoot_line[0], UI_shoot_line[1], UI_shoot_line[2], UI_shoot_line[3], UI_shoot_line[4]); UI_ReFresh(&_referee_info->referee_id, 5, UI_shoot_line[0], UI_shoot_line[1], UI_shoot_line[2], UI_shoot_line[3], UI_shoot_line[4]);
// 绘制车辆状态标志,静态 // 绘制车辆状态标志指示
Char_Draw(&UI_State_sta[0], "ss0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 150, 750); Char_Draw(&UI_State_sta[0], "ss0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 150, 750, "chassis:");
Char_Write(&UI_State_sta[0], "chassis:");
Char_ReFresh(&_referee_info->referee_id, UI_State_sta[0]); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[0]);
Char_Draw(&UI_State_sta[1], "ss1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 150, 700, "gimbal:");
Char_Draw(&UI_State_sta[1], "ss1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 150, 700);
Char_Write(&UI_State_sta[1], "gimbal:");
Char_ReFresh(&_referee_info->referee_id, UI_State_sta[1]); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[1]);
Char_Draw(&UI_State_sta[2], "ss2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 150, 650, "shoot:");
Char_Draw(&UI_State_sta[2], "ss2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 150, 650);
Char_Write(&UI_State_sta[2], "shoot:");
Char_ReFresh(&_referee_info->referee_id, UI_State_sta[2]); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[2]);
Char_Draw(&UI_State_sta[3], "ss3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 600, "frict:");
Char_Draw(&UI_State_sta[3], "ss3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 600);
Char_Write(&UI_State_sta[3], "frict:");
Char_ReFresh(&_referee_info->referee_id, UI_State_sta[3]); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[3]);
Char_Draw(&UI_State_sta[4], "ss4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 550, "lid:");
Char_Draw(&UI_State_sta[4], "ss4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 550);
Char_Write(&UI_State_sta[4], "lid:");
Char_ReFresh(&_referee_info->referee_id, UI_State_sta[4]); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[4]);
// 底盘功率显示,静态 // 底盘功率显示,静态
Char_Draw(&UI_State_sta[5], "ss5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 720, 210); Char_Draw(&UI_State_sta[5], "ss5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 720, 210, "Power:");
Char_Write(&UI_State_sta[5], "Power:");
Char_ReFresh(&_referee_info->referee_id, UI_State_sta[5]); Char_ReFresh(&_referee_info->referee_id, UI_State_sta[5]);
// 绘制车辆状态标志,动态 // 绘制车辆状态标志,动态
// 由于初始化时xxx_last_mode默认为0所以此处对应UI也应该设为0时对应的UI防止模式不变的情况下无法置位flag导致UI无法刷新 // 由于初始化时xxx_last_mode默认为0所以此处对应UI也应该设为0时对应的UI防止模式不变的情况下无法置位flag导致UI无法刷新
Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 270, 750); Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_ADD, 8, UI_Color_Main, 15, 2, 270, 750, "zeroforce");
Char_Write(&UI_State_dyn[0], "zeroforce");
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]);
Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 270, 700, "zeroforce");
Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_ADD, 8, UI_Color_Yellow, 15, 2, 270, 700);
Char_Write(&UI_State_dyn[1], "zeroforce");
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[1]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[1]);
Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 270, 650, "off");
Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_ADD, 8, UI_Color_Orange, 15, 2, 270, 650);
Char_Write(&UI_State_dyn[2], "off");
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[2]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[2]);
Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 600, "off");
Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 600);
Char_Write(&UI_State_dyn[3], "off");
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]);
Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 550, "open ");
Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 270, 550);
Char_Write(&UI_State_dyn[4], "open ");
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[4]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[4]);
// 底盘功率显示,动态 // 底盘功率显示,动态
Char_Draw(&UI_State_dyn[5], "sd5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 840, 210); Char_Draw(&UI_State_dyn[5], "sd5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 840, 210, "0000");
Char_Write(&UI_State_dyn[5], "0000");
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[5]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[5]);
} }
@ -143,7 +114,6 @@ static void robot_mode_change(Referee_Interactive_info_t *_Interactive_data) //
} }
case 1: case 1:
{ {
;
_Interactive_data->chassis_mode = CHASSIS_ROTATE; _Interactive_data->chassis_mode = CHASSIS_ROTATE;
_Interactive_data->gimbal_mode = GIMBAL_FREE_MODE; _Interactive_data->gimbal_mode = GIMBAL_FREE_MODE;
_Interactive_data->shoot_mode = SHOOT_OFF; _Interactive_data->shoot_mode = SHOOT_OFF;
@ -183,30 +153,19 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf
switch (_Interactive_data->chassis_mode) switch (_Interactive_data->chassis_mode)
{ {
case CHASSIS_ZERO_FORCE: case CHASSIS_ZERO_FORCE:
{ Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "zeroforce");
Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750);
Char_Write(&UI_State_dyn[0], "zeroforce");
break; break;
}
case CHASSIS_ROTATE: case CHASSIS_ROTATE:
{ Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "rotate ");
Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750); // 此处注意字数对齐问题,字数相同才能覆盖掉
Char_Write(&UI_State_dyn[0], "rotate "); // 此处注意字数对齐问题,字数相同才能覆盖掉
break; break;
}
case CHASSIS_NO_FOLLOW: case CHASSIS_NO_FOLLOW:
{ Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "nofollow ");
Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750);
Char_Write(&UI_State_dyn[0], "nofollow ");
break; break;
}
case CHASSIS_FOLLOW_GIMBAL_YAW: case CHASSIS_FOLLOW_GIMBAL_YAW:
{ Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750, "follow ");
Char_Draw(&UI_State_dyn[0], "sd0", UI_Graph_Change, 8, UI_Color_Main, 15, 2, 270, 750);
Char_Write(&UI_State_dyn[0], "follow ");
break; break;
} }
}
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[0]);
_Interactive_data->Referee_Interactive_Flag.chassis_flag = 0; _Interactive_data->Referee_Interactive_Flag.chassis_flag = 0;
} }
@ -217,20 +176,17 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf
{ {
case GIMBAL_ZERO_FORCE: case GIMBAL_ZERO_FORCE:
{ {
Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700); Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700, "zeroforce");
Char_Write(&UI_State_dyn[1], "zeroforce");
break; break;
} }
case GIMBAL_FREE_MODE: case GIMBAL_FREE_MODE:
{ {
Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700); Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700, "free ");
Char_Write(&UI_State_dyn[1], "free ");
break; break;
} }
case GIMBAL_GYRO_MODE: case GIMBAL_GYRO_MODE:
{ {
Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700); Char_Draw(&UI_State_dyn[1], "sd1", UI_Graph_Change, 8, UI_Color_Yellow, 15, 2, 270, 700, "gyro ");
Char_Write(&UI_State_dyn[1], "gyro ");
break; break;
} }
} }
@ -244,14 +200,12 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf
{ {
case SHOOT_OFF: case SHOOT_OFF:
{ {
Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650); Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650, "off");
Char_Write(&UI_State_dyn[2], "off");
break; break;
} }
case SHOOT_ON: case SHOOT_ON:
{ {
Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650); Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650, "on ");
Char_Write(&UI_State_dyn[2], "on ");
break; break;
} }
} }
@ -259,42 +213,37 @@ static void My_UI_Refresh(referee_info_t *_referee_info, Referee_Interactive_inf
_Interactive_data->Referee_Interactive_Flag.shoot_flag = 0; _Interactive_data->Referee_Interactive_Flag.shoot_flag = 0;
} }
// friction
if (_Interactive_data->Referee_Interactive_Flag.friction_flag == 1) if (_Interactive_data->Referee_Interactive_Flag.friction_flag == 1)
{ {
switch (_Interactive_data->friction_mode) switch (_Interactive_data->friction_mode)
{ {
case FRICTION_OFF: case FRICTION_OFF:
{ {
Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600); Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600, "off");
Char_Write(&UI_State_dyn[3], "off");
break; break;
} }
case FRICTION_ON: case FRICTION_ON:
{ {
Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600); Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600, "on ");
Char_Write(&UI_State_dyn[3], "on ");
break; break;
} }
} }
Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]); Char_ReFresh(&_referee_info->referee_id, UI_State_dyn[3]);
_Interactive_data->Referee_Interactive_Flag.friction_flag = 0; _Interactive_data->Referee_Interactive_Flag.friction_flag = 0;
} }
// lid
if (_Interactive_data->Referee_Interactive_Flag.lid_flag == 1) if (_Interactive_data->Referee_Interactive_Flag.lid_flag == 1)
{ {
switch (_Interactive_data->lid_mode) switch (_Interactive_data->lid_mode)
{ {
case LID_CLOSE: case LID_CLOSE:
{ {
Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550); Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550, "close");
Char_Write(&UI_State_dyn[4], "close");
break; break;
} }
case LID_OPEN: case LID_OPEN:
{ {
Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550); Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550, "open ");
Char_Write(&UI_State_dyn[4], "open ");
break; break;
} }
} }
@ -348,7 +297,7 @@ static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data)
* @retval none * @retval none
* @attention * @attention
*/ */
static void determine_ID(referee_info_t *_referee_info) static void DeterminRobotID(referee_info_t *_referee_info)
{ {
// id小于7是红色,大于7是蓝色,0为红色1为蓝色 #define Robot_Red 0 #define Robot_Blue 1 // id小于7是红色,大于7是蓝色,0为红色1为蓝色 #define Robot_Red 0 #define Robot_Blue 1
_referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id > 7 ? Robot_Blue : Robot_Red; _referee_info->referee_id.Robot_Color = _referee_info->GameRobotState.robot_id > 7 ? Robot_Blue : Robot_Red;
@ -363,7 +312,7 @@ static void UI_test_init(referee_info_t *_referee_info)
Graph_Data_t graph[5]; Graph_Data_t graph[5];
Graph_Data_t num[2]; Graph_Data_t num[2];
String_Data_t sdata[1]; String_Data_t sdata[1];
UI_Delete(&_referee_info->referee_id, UI_Data_Del_ALL, 0); UIDelete(&_referee_info->referee_id, UI_Data_Del_ALL, 0);
Line_Draw(&graph[0], "s0", UI_Graph_ADD, 0, UI_Color_White, 3, 710, 540, 1210, 540); Line_Draw(&graph[0], "s0", UI_Graph_ADD, 0, UI_Color_White, 3, 710, 540, 1210, 540);
Rectangle_Draw(&graph[1], "s1", UI_Graph_ADD, 0, UI_Color_Yellow, 4, 600, 200, 800, 500); Rectangle_Draw(&graph[1], "s1", UI_Graph_ADD, 0, UI_Color_Yellow, 4, 600, 200, 800, 500);
@ -375,7 +324,6 @@ static void UI_test_init(referee_info_t *_referee_info)
Integer_Draw(&num[1], "s6", UI_Graph_ADD, 0, UI_Color_Cyan, 50, 5, 1050, 460, 12345); Integer_Draw(&num[1], "s6", UI_Graph_ADD, 0, UI_Color_Cyan, 50, 5, 1050, 460, 12345);
UI_ReFresh(&_referee_info->referee_id, 7, graph[0], graph[1], graph[2], graph[3], graph[4], num[0], num[1]); UI_ReFresh(&_referee_info->referee_id, 7, graph[0], graph[1], graph[2], graph[3], graph[4], num[0], num[1]);
Char_Draw(&sdata[0], "s7", UI_Graph_ADD, 0, UI_Color_Green, 20, 2, 620, 710); Char_Draw(&sdata[0], "s7", UI_Graph_ADD, 0, UI_Color_Green, 20, 2, 620, 710, "number:%d", 123);
Char_Write(&sdata[0], "number:%d", 123);
Char_ReFresh(&_referee_info->referee_id, sdata[0]); Char_ReFresh(&_referee_info->referee_id, sdata[0]);
} }

View File

@ -0,0 +1,19 @@
#ifndef REFEREE_H
#define REFEREE_H
#include "rm_referee.h"
#include "robot_def.h"
/**
* @brief (UI和多机通信)
*
*/
void Referee_Interactive_init();
/**
* @brief (UI和多机通信)
*
*/
void Referee_Interactive_task();
#endif // REFEREE_H

View File

@ -13,51 +13,72 @@
#include "string.h" #include "string.h"
#include "crc_ref.h" #include "crc_ref.h"
#include "bsp_usart.h" #include "bsp_usart.h"
#include "task.h"
#define RE_RX_BUFFER_SIZE 200 #define RE_RX_BUFFER_SIZE 200
static USARTInstance *referee_usart_instance; static USARTInstance *referee_usart_instance; // 裁判系统串口实例
static referee_tx_buffer_t referee_tx_buffer={{0},0}; static referee_info_t referee_info; // 裁判系统数据
static referee_info_t referee_info; static Referee_Interactive_info_t *UI_tmp; // UI绘制需要的机器人状态数据
static void JudgeReadData(uint8_t *ReadFromUsart);
static void RefereeRxCallback(); static void RefereeRxCallback();
static void JudgeReadData(uint8_t *buff);
uint8_t UI_Seq = 0; // 包序号供整个referee文件使用 uint8_t UI_Seq = 0; // 包序号供整个referee文件使用
/* 裁判系统通信初始化 */ /* 裁判系统通信初始化 */
referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle, Referee_Interactive_info_t *UI_data)
{ {
USART_Init_Config_s conf; USART_Init_Config_s conf;
conf.module_callback = RefereeRxCallback; conf.module_callback = RefereeRxCallback;
conf.usart_handle = referee_usart_handle; conf.usart_handle = referee_usart_handle;
conf.recv_buff_size = RE_RX_BUFFER_SIZE; conf.recv_buff_size = RE_RX_BUFFER_SIZE;
referee_usart_instance = USARTRegister(&conf); referee_usart_instance = USARTRegister(&conf);
UI_tmp = UI_data;
return &referee_info; return &referee_info;
} }
/** void RefereeGetUIData(referee_info_t **recv_info_pp, Referee_Interactive_info_t **UI_data_pp)
* @brief
* @param send
*/
void RefereeLoadToBuffer(uint8_t *send, uint16_t tx_len)
{ {
memcpy((uint8_t *)(&referee_tx_buffer.buffer)+referee_tx_buffer.pos,send,tx_len); *recv_info_pp = &referee_info;
referee_tx_buffer.pos+=tx_len; *UI_data_pp = UI_tmp;
} }
void CommBetweenRobotSend(referee_id_t *_id, robot_interactive_data_t *_data)
{
Communicate_SendData_t SendData;
uint8_t temp_datalength = Interactive_Data_LEN_Head + Communicate_Data_LEN; // 计算交互数据长度 6+n,n为交互数据长度
SendData.FrameHeader.SOF = REFEREE_SOF;
SendData.FrameHeader.DataLength = temp_datalength;
SendData.FrameHeader.Seq = UI_Seq;
SendData.FrameHeader.CRC8 = Get_CRC8_Check_Sum((uint8_t *)&SendData, LEN_CRC8, 0xFF);
SendData.CmdID = ID_student_interactive;
SendData.datahead.data_cmd_id = Communicate_Data_ID;
SendData.datahead.sender_ID = _id->Robot_ID;
SendData.datahead.receiver_ID = _id->Receiver_Robot_ID;
SendData.Data = *_data;
SendData.frametail = Get_CRC16_Check_Sum((uint8_t *)&SendData, LEN_HEADER + LEN_CMDID + temp_datalength, 0xFFFF);
RefereeSend((uint8_t *)&SendData, LEN_HEADER + LEN_CMDID + temp_datalength + LEN_TAIL); // 发送
UI_Seq++; // 包序号+1
}
/** /**
* @brief * @brief ,使
* @param * @param
*/ */
void RefereeSend() void RefereeSend(uint8_t *send, uint16_t tx_len)
{ {
USARTSend(referee_usart_instance, (uint8_t *)(&referee_tx_buffer.buffer), referee_tx_buffer.pos,USART_TRANSFER_DMA); static TickType_t xLastWakeTime;
referee_tx_buffer.pos=0; USARTSend(referee_usart_instance, send, tx_len, USART_TRANSFER_DMA);
vTaskDelayUntil(&xLastWakeTime, 120);
} }
/*裁判系统串口接收回调函数,解析数据 */ /*裁判系统串口接收回调函数,解析数据 */
static void RefereeRxCallback() static void RefereeRxCallback()
{ {
@ -66,83 +87,82 @@ static void RefereeRxCallback()
/** /**
* @brief , * @brief ,
* @param ReadFromUsart: * @param buff:
* @retval * @retval
* @attention CRC校验, * @attention CRC校验,
*/ */
static void JudgeReadData(uint8_t *ReadFromUsart) static void JudgeReadData(uint8_t *buff)
{ {
uint16_t judge_length; // 统计一帧数据长度 uint16_t judge_length; // 统计一帧数据长度
if (ReadFromUsart == NULL) // 空数据包,则不作任何处理 if (buff == NULL) // 空数据包,则不作任何处理
return; return;
// 写入帧头数据(5-byte),用于判断是否开始存储裁判数据 // 写入帧头数据(5-byte),用于判断是否开始存储裁判数据
memcpy(&referee_info.FrameHeader, ReadFromUsart, LEN_HEADER); memcpy(&referee_info.FrameHeader, buff, LEN_HEADER);
// 判断帧头数据(0)是否为0xA5 // 判断帧头数据(0)是否为0xA5
if (ReadFromUsart[SOF] == REFEREE_SOF) if (buff[SOF] == REFEREE_SOF)
{ {
// 帧头CRC8校验 // 帧头CRC8校验
if (Verify_CRC8_Check_Sum(ReadFromUsart, LEN_HEADER) == TRUE) if (Verify_CRC8_Check_Sum(buff, LEN_HEADER) == TRUE)
{ {
// 统计一帧数据长度(byte),用于CR16校验 // 统计一帧数据长度(byte),用于CR16校验
judge_length = ReadFromUsart[DATA_LENGTH] + LEN_HEADER + LEN_CMDID + LEN_TAIL; judge_length = buff[DATA_LENGTH] + LEN_HEADER + LEN_CMDID + LEN_TAIL;
// 帧尾CRC16校验 // 帧尾CRC16校验
if (Verify_CRC16_Check_Sum(ReadFromUsart, judge_length) == TRUE) if (Verify_CRC16_Check_Sum(buff, judge_length) == TRUE)
{ {
// 2个8位拼成16位int // 2个8位拼成16位int
referee_info.CmdID = (ReadFromUsart[6] << 8 | ReadFromUsart[5]); referee_info.CmdID = (buff[6] << 8 | buff[5]);
// 解析数据命令码,将数据拷贝到相应结构体中(注意拷贝数据的长度) // 解析数据命令码,将数据拷贝到相应结构体中(注意拷贝数据的长度)
// 第8个字节开始才是数据 data=7 // 第8个字节开始才是数据 data=7
switch (referee_info.CmdID) switch (referee_info.CmdID)
{ {
case ID_game_state: // 0x0001 case ID_game_state: // 0x0001
memcpy(&referee_info.GameState, (ReadFromUsart + DATA_Offset), LEN_game_state); memcpy(&referee_info.GameState, (buff + DATA_Offset), LEN_game_state);
break; break;
case ID_game_result: // 0x0002 case ID_game_result: // 0x0002
memcpy(&referee_info.GameResult, (ReadFromUsart + DATA_Offset), LEN_game_result); memcpy(&referee_info.GameResult, (buff + DATA_Offset), LEN_game_result);
break; break;
case ID_game_robot_survivors: // 0x0003 case ID_game_robot_survivors: // 0x0003
memcpy(&referee_info.GameRobotHP, (ReadFromUsart + DATA_Offset), LEN_game_robot_HP); memcpy(&referee_info.GameRobotHP, (buff + DATA_Offset), LEN_game_robot_HP);
break; break;
case ID_event_data: // 0x0101 case ID_event_data: // 0x0101
memcpy(&referee_info.EventData, (ReadFromUsart + DATA_Offset), LEN_event_data); memcpy(&referee_info.EventData, (buff + DATA_Offset), LEN_event_data);
break; break;
case ID_supply_projectile_action: // 0x0102 case ID_supply_projectile_action: // 0x0102
memcpy(&referee_info.SupplyProjectileAction, (ReadFromUsart + DATA_Offset), LEN_supply_projectile_action); memcpy(&referee_info.SupplyProjectileAction, (buff + DATA_Offset), LEN_supply_projectile_action);
break; break;
case ID_game_robot_state: // 0x0201 case ID_game_robot_state: // 0x0201
memcpy(&referee_info.GameRobotState, (ReadFromUsart + DATA_Offset), LEN_game_robot_state); memcpy(&referee_info.GameRobotState, (buff + DATA_Offset), LEN_game_robot_state);
break; break;
case ID_power_heat_data: // 0x0202 case ID_power_heat_data: // 0x0202
memcpy(&referee_info.PowerHeatData, (ReadFromUsart + DATA_Offset), LEN_power_heat_data); memcpy(&referee_info.PowerHeatData, (buff + DATA_Offset), LEN_power_heat_data);
break; break;
case ID_game_robot_pos: // 0x0203 case ID_game_robot_pos: // 0x0203
memcpy(&referee_info.GameRobotPos, (ReadFromUsart + DATA_Offset), LEN_game_robot_pos); memcpy(&referee_info.GameRobotPos, (buff + DATA_Offset), LEN_game_robot_pos);
break; break;
case ID_buff_musk: // 0x0204 case ID_buff_musk: // 0x0204
memcpy(&referee_info.BuffMusk, (ReadFromUsart + DATA_Offset), LEN_buff_musk); memcpy(&referee_info.BuffMusk, (buff + DATA_Offset), LEN_buff_musk);
break; break;
case ID_aerial_robot_energy: // 0x0205 case ID_aerial_robot_energy: // 0x0205
memcpy(&referee_info.AerialRobotEnergy, (ReadFromUsart + DATA_Offset), LEN_aerial_robot_energy); memcpy(&referee_info.AerialRobotEnergy, (buff + DATA_Offset), LEN_aerial_robot_energy);
break; break;
case ID_robot_hurt: // 0x0206 case ID_robot_hurt: // 0x0206
memcpy(&referee_info.RobotHurt, (ReadFromUsart + DATA_Offset), LEN_robot_hurt); memcpy(&referee_info.RobotHurt, (buff + DATA_Offset), LEN_robot_hurt);
break; break;
case ID_shoot_data: // 0x0207 case ID_shoot_data: // 0x0207
memcpy(&referee_info.ShootData, (ReadFromUsart + DATA_Offset), LEN_shoot_data); memcpy(&referee_info.ShootData, (buff + DATA_Offset), LEN_shoot_data);
break; break;
case ID_student_interactive: // 0x0301 syhtodo接收代码未测试 case ID_student_interactive: // 0x0301 syhtodo接收代码未测试
memcpy(&referee_info.ReceiveData, (ReadFromUsart + DATA_Offset), LEN_receive_data); memcpy(&referee_info.ReceiveData, (buff + DATA_Offset), LEN_receive_data);
break; break;
} }
} }
} }
// 首地址加帧长度,指向CRC16下一字节,用来判断是否为0xA5,从而判断一个数据包是否有多帧数据 // 首地址加帧长度,指向CRC16下一字节,用来判断是否为0xA5,从而判断一个数据包是否有多帧数据
if (*(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL) == 0xA5) if (*(buff + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL) == 0xA5)
{ { // 如果一个数据包出现了多帧数据,则再次调用解析函数,直到所有数据包解析完毕
// 如果一个数据包出现了多帧数据,则再次调用解析函数,直到所有数据包解析完毕 JudgeReadData(buff + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL);
JudgeReadData(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL);
} }
} }
} }

View File

@ -2,19 +2,14 @@
#define RM_REFEREE_H #define RM_REFEREE_H
#include "usart.h" #include "usart.h"
#include "referee_def.h" #include "referee_protocol.h"
#include "robot_def.h"
#include "bsp_usart.h" #include "bsp_usart.h"
#include "FreeRTOS.h"
extern uint8_t UI_Seq; extern uint8_t UI_Seq;
#pragma pack(1) #pragma pack(1)
#define RE_TX_BUFFER_SIZE 512
//发送缓冲区结构体定义
typedef struct
{
uint8_t buffer[RE_TX_BUFFER_SIZE];
uint16_t pos;
} referee_tx_buffer_t;
typedef struct typedef struct
{ {
uint8_t Robot_Color; // 机器人颜色 uint8_t Robot_Color; // 机器人颜色
@ -48,28 +43,74 @@ typedef struct
} referee_info_t; } referee_info_t;
// 模式是否切换标志位0为未切换1为切换static定义默认为0
typedef struct
{
uint32_t chassis_flag : 1;
uint32_t gimbal_flag : 1;
uint32_t shoot_flag : 1;
uint32_t lid_flag : 1;
uint32_t friction_flag : 1;
uint32_t Power_flag : 1;
} Referee_Interactive_Flag_t;
// 此结构体包含UI绘制与机器人车间通信的需要的其他非裁判系统数据
typedef struct
{
Referee_Interactive_Flag_t Referee_Interactive_Flag;
// 为UI绘制以及交互数据所用
Robot_Status_e Robot_Status; // 机器人状态
App_Status_e App_Status; // 应用状态
chassis_mode_e chassis_mode; // 底盘模式
gimbal_mode_e gimbal_mode; // 云台模式
shoot_mode_e shoot_mode; // 发射模式设置
friction_mode_e friction_mode; // 摩擦轮关闭
lid_mode_e lid_mode; // 弹舱盖打开
loader_mode_e loader_mode; // 单发...连发
Chassis_Power_Data_s Chassis_Power_Data; // 功率控制
//上一次的模式用于flag判断
chassis_mode_e chassis_last_mode; // 底盘模式
gimbal_mode_e gimbal_last_mode; // 云台模式
shoot_mode_e shoot_last_mode; // 发射模式设置
friction_mode_e friction_last_mode; // 摩擦轮关闭
lid_mode_e lid_last_mode; // 弹舱盖打开
} Referee_Interactive_info_t;
#pragma pack() #pragma pack()
/** /**
* @brief , * @brief , ,,UI绘制的数据指针传入
* *
* @param referee_usart_handle * @param referee_usart_handle handle,C板一般用串口6
* @return referee_info_t* * @param UI_data UI绘制数据指针,UI绘制的各种状态数据
* @return referee_info_t* ,//
*/ */
referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle); referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle, Referee_Interactive_info_t *UI_data);
/** /**
* @brief * @brief UI绘制的任务初始化调用,UI绘制的数据指针,便UI绘制任务使用
* @param send *
* @param recv_info_pp
* @param UI_data_pp
*/ */
void RefereeLoadToBuffer(uint8_t *send, uint16_t tx_len); void RefereeGetUIData(referee_info_t **recv_info_pp, Referee_Interactive_info_t **UI_data_pp);
/**
* @brief
* @param referee_id_t *_id sender为本机器人receiver为接收方机器人Receiver_Robot_ID再调用该函数
* robot_interactive_data_t *data
* @retval none
* @attention
*/
void CommBetweenRobotSend(referee_id_t *_id, robot_interactive_data_t *_data);
/** /**
* @brief * @brief
* @todo * @todo
* @param * @param
*/ */
void RefereeSend(void); void RefereeSend(uint8_t *send, uint16_t tx_len);
#endif // !REFEREE_H #endif // !REFEREE_H