添加了裁判系统三要素的发送

This commit is contained in:
Xiaocheng 2026-03-17 23:36:40 +08:00
parent dbf000d55d
commit f121d4057a
10 changed files with 150 additions and 62 deletions

View File

@ -1,26 +1,29 @@
OpenDocument="rc.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/task/rc.c", Line=31
OpenDocument="atti_esti.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/task/atti_esti.c", Line=0
OpenDocument="cmd.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/task/cmd.c", Line=0
GraphedExpression="temp_for_cap[0]", Color=#e56a6f, Show=0
GraphedExpression="temp_for_cap[1]", Color=#35792b, Show=0
OpenDocument="ai.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/task/ai.c", Line=24
OpenDocument="gimbal.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/task/gimbal.c", Line=0
OpenDocument="port.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c", Line=407
OpenDocument="tasks.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/Middlewares/Third_Party/FreeRTOS/Source/tasks.c", Line=3640
OpenDocument="can.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/bsp/can.c", Line=380
OpenDocument="startup_stm32f407xx.s", FilePath="D:/STM32CubeMX/103/Er(Sentry)/startup_stm32f407xx.s", Line=51
OpenDocument="chassis.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/task/chassis.c", Line=0
OpenDocument="ai.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/task/ai.c", Line=0
OpenDocument="main.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/Core/Src/main.c", Line=62
OpenDocument="supercap.c", FilePath="D:/STM32CubeMX/103/Er(Sentry)/User/device/supercap.c", Line=0
OpenToolbar="Debug", Floating=0, x=0, y=0
OpenWindow="Registers 1", DockArea=RIGHT, x=0, y=1, w=273, h=577, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, FilteredItems=[], RefreshRate=1
OpenWindow="Source Files", DockArea=LEFT, x=0, y=1, w=738, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=0, w=273, h=114, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=0, w=738, h=376, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Data Sampling", DockArea=BOTTOM, x=0, y=0, w=422, h=292, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VisibleTab=0, UniformSampleSpacing=0
OpenWindow="Timeline", DockArea=BOTTOM, x=1, y=0, w=1497, h=292, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=1, DataPaneShown=1, PowerPaneShown=1, CodePaneShown=1, PinCursor="Cursor Movable", TimePerDiv="1 ns / Div", TimeStampFormat="Time", DataGraphDrawAsPoints=0, DataGraphLegendShown=1, DataGraphUniformSampleSpacing=0, DataGraphLegendPosition="1295;0", DataGraphShowNamesAtCursor=0, PowerGraphDrawAsPoints=0, PowerGraphLegendShown=1, PowerGraphAvgFilterTime=Off, PowerGraphAvgFilterLen=Off, PowerGraphUniformSampleSpacing=0, PowerGraphLegendPosition="1294;0", CodeGraphLegendShown=1, CodeGraphLegendPosition="1253;4"
OpenWindow="Registers 1", DockArea=RIGHT, x=0, y=1, w=273, h=566, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, FilteredItems=[], RefreshRate=1
OpenWindow="Source Files", DockArea=LEFT, x=0, y=1, w=738, h=351, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=0, w=273, h=125, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=0, w=738, h=340, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Data Sampling", DockArea=BOTTOM, x=0, y=0, w=575, h=292, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VisibleTab=0, UniformSampleSpacing=0
OpenWindow="Timeline", DockArea=BOTTOM, x=1, y=0, w=1344, h=292, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=1, DataPaneShown=1, PowerPaneShown=1, CodePaneShown=1, PinCursor="Cursor Movable", TimePerDiv="2 s / Div", TimeStampFormat="Time", DataGraphDrawAsPoints=0, DataGraphLegendShown=1, DataGraphUniformSampleSpacing=0, DataGraphLegendPosition="997;1", DataGraphShowNamesAtCursor=0, PowerGraphDrawAsPoints=0, PowerGraphLegendShown=1, PowerGraphAvgFilterTime=Off, PowerGraphAvgFilterLen=Off, PowerGraphUniformSampleSpacing=0, PowerGraphLegendPosition="1141;0", CodeGraphLegendShown=1, CodeGraphLegendPosition="1100;0"
SmartViewPlugin="", Page="", Toolbar="Hidden", Window="SmartView 1"
TableHeader="Watched Data 1", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Value";"Location";"Refresh"], ColWidths=[210;144;100;263]
TableHeader="Source Files", SortCol="File", SortOrder="ASCENDING", VisibleCols=["File";"Status";"Size";"#Insts";"Path"], ColWidths=[191;100;100;100;931]
TableHeader="Data Sampling Table", SortCol="None", SortOrder="ASCENDING", VisibleCols=["Index";"Time"], ColWidths=[100;100]
TableHeader="Data Sampling Setup", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Type";"Value";"Min";"Max";"Average";"# Changes";"Min. Change";"Max. Change"], ColWidths=[100;100;100;100;100;100;100;107;107]
TableHeader="Data Sampling Table", SortCol="None", SortOrder="ASCENDING", VisibleCols=["Index";"Time";" temp_for_cap[0]";" temp_for_cap[1]"], ColWidths=[100;100;100;100]
TableHeader="Data Sampling Setup", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Type";"Value";"Min";"Max";"Average";"# Changes";"Min. Change";"Max. Change"], ColWidths=[100;100;126;126;126;126;100;107;107]
TableHeader="Power Sampling", SortCol="None", SortOrder="ASCENDING", VisibleCols=["Index";"Time";"Ch 0"], ColWidths=[100;100;100]
TableHeader="Registers 1", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Description"], ColWidths=[100;118;259]
TableHeader="Watched Data 1", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Value";"Location";"Refresh"], ColWidths=[210;144;100;263]
TableHeader="RegisterSelectionDialog", SortCol="None", SortOrder="ASCENDING", VisibleCols=[], ColWidths=[]
TableHeader="TargetExceptionDialog", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Address";"Description"], ColWidths=[200;100;100;351]
WatchedExpression="shoot_mcu_package", RefreshRate=5, Window=Watched Data 1
@ -31,4 +34,7 @@ WatchedExpression="cmd_chassis", RefreshRate=5, Window=Watched Data 1
WatchedExpression="rc_c", RefreshRate=5, Window=Watched Data 1
WatchedExpression="imu_eulr", RefreshRate=5, Window=Watched Data 1
WatchedExpression="ai_result", RefreshRate=5, Window=Watched Data 1
WatchedExpression="et16s", Window=Watched Data 1
WatchedExpression="et16s", RefreshRate=5, Window=Watched Data 1
WatchedExpression="temp_for_cap", RefreshRate=5, Window=Watched Data 1
WatchedExpression="CAN_SuperCapRXData", Window=Watched Data 1
WatchedExpression="gimbal", RefreshRate=5, Window=Watched Data 1

View File

@ -2,6 +2,41 @@
#include "device/device.h"
#include "bsp/uart.h"
#include "component/crc16.h"
#include "device/referee.h"
static int8_t Package_BuildAndVerify(uint8_t *raw, uint16_t len, uint8_t id) {
uint16_t *crc = NULL;
if (raw == NULL || len <= sizeof(uint16_t)) {
return DEVICE_ERR;
}
raw[0] = id;
crc = (uint16_t *)(void *)(raw + len - sizeof(uint16_t));
*crc = CRC16_Calc(raw, len - sizeof(uint16_t), CRC16_INIT);
if (CRC16_Verify(raw, len) != true) {
return DEVICE_ERR;
}
return DEVICE_OK;
}
static int8_t Package_Check(const uint8_t *raw, uint16_t len, uint8_t expected_id) {
if (raw == NULL || len <= sizeof(uint16_t)) {
return DEVICE_ERR;
}
if (raw[0] != expected_id) {
return DEVICE_ERR;
}
if (CRC16_Verify(raw, len) != true) {
return DEVICE_ERR;
}
return DEVICE_OK;
}
int8_t AI_StartReceiving(PackageAI_t *ai) {
@ -11,10 +46,14 @@ int8_t AI_StartReceiving(PackageAI_t *ai) {
}
int8_t AI_Get_NUC(PackageAI_t *ai,AI_result_t* result) {
if (ai == NULL || result == NULL) {
return DEVICE_ERR;
}
if (Package_Check((const uint8_t *)ai, sizeof(*ai), ID_AI) != DEVICE_OK) {
return DEVICE_ERR;
}
if(ai->id==ID_AI){
// if(CRC16_Verify((const uint8_t*)&(ai), sizeof(&ai))==true)
// {
result->mode=ai->data.mode;
result->gimbal_t.setpoint.yaw=ai->data.yaw;
result->gimbal_t.vel.yaw=ai->data.yaw_vel;
@ -26,16 +65,17 @@ int8_t AI_Get_NUC(PackageAI_t *ai,AI_result_t* result) {
result->chassis_t.Vx=ai->data.vx;
result->chassis_t.Vy=ai->data.vy;
result->chassis_t.Vw=ai->data.wz;
// }
return DEVICE_OK;
}
}
int8_t MCU_Send(PackageMCU_t* mcu,Gimbal_feedback_t* motor,AHRS_Quaternion_t* quat) {
int8_t MCU_Send(PackageMCU_t* mcu,Gimbal_feedback_t* motor,AHRS_Quaternion_t* quat ){
(void)quat;
if (mcu == NULL || motor == NULL) {
return DEVICE_ERR;
}
mcu->id=ID_MCU;
mcu->data.mode=0;
mcu->data.q[0]=motor->imu.quat.q0;
mcu->data.q[1]=motor->imu.quat.q1;
@ -48,16 +88,36 @@ int8_t MCU_Send(PackageMCU_t* mcu,Gimbal_feedback_t* motor,AHRS_Quaternion_t* qu
mcu->data.bullet_count=0;
mcu->data.bullet_speed=22;
mcu->crc16=CRC16_Calc(((const uint8_t*)&(mcu)),sizeof(&mcu)-sizeof(uint16_t), CRC16_INIT );
if(CRC16_Verify(((const uint8_t*)&(mcu)), sizeof(&mcu))!=true){
return Package_BuildAndVerify((uint8_t *)mcu, sizeof(*mcu), ID_MCU);
}
int8_t REF_Send(PackageReferee_t *referee,Referee_RobotStatus_t* robot_status,Referee_GameStatus_t *game_status) {
if (referee == NULL || robot_status == NULL || game_status == NULL) {
return DEVICE_ERR;
}
return DEVICE_OK;
referee->data.remain_hp=robot_status->current_HP;
referee->data.game_progress = game_status->game_progress & 0x0F;
referee->data.stage_remain_time= game_status->stage_remain_time;
return Package_BuildAndVerify((uint8_t *)referee, sizeof(*referee), ID_REF);
}
int8_t REF_StartSend(PackageReferee_t *referee) {
if (referee == NULL) {
return DEVICE_ERR;
}
if(BSP_UART_Transmit(BSP_UART_1, (uint8_t *)referee, sizeof(*referee), true)==HAL_OK)
return DEVICE_OK;
return DEVICE_ERR;
}
int8_t MCU_StartSend(PackageMCU_t *mcu) {
if(BSP_UART_Transmit(BSP_UART_1, (uint8_t *)mcu, sizeof(*mcu), true)==HAL_OK)
return DEVICE_OK;
return DEVICE_ERR;
}

View File

@ -9,6 +9,7 @@ extern "C" {
#include "component\user_math.h"
#include "remote_control.h"
#include "module/gimbal.h"
#include "device/referee.h"
#include "stdint.h"
// struct __attribute__((packed)) GimbalToVision
// {
@ -162,6 +163,8 @@ typedef struct __attribute__((packed)) {
int8_t MCU_Send(PackageMCU_t* mcu,Gimbal_feedback_t* motor,AHRS_Quaternion_t* quat);
int8_t REF_Send(PackageReferee_t *referee,Referee_RobotStatus_t* robot_status,Referee_GameStatus_t *game_status);
int8_t REF_StartSend(PackageReferee_t *referee);
int8_t MCU_StartSend(PackageMCU_t *mcu);
int8_t AI_Get_NUC(PackageAI_t *ai,AI_result_t* result);
int8_t AI_StartReceiving(PackageAI_t *ai);

View File

@ -614,6 +614,8 @@ uint8_t Referee_PackCap(Referee_ForCap_t *cap, const Referee_t *ref) {
uint8_t Referee_PackAI(Referee_ForAI_t *ai, const Referee_t *ref) {
ai->ref_status = ref->ref_status;
memcpy(&(ai->robot_status), &(ref->robot_status), sizeof(ai->robot_status));
memcpy(&(ai->game_status), &(ref->game_status), sizeof(ai->game_status));
return 0;
}

View File

@ -701,6 +701,8 @@ typedef struct {
typedef struct {
Referee_Status_t ref_status;
Referee_RobotStatus_t robot_status;
Referee_GameStatus_t game_status;
} Referee_ForAI_t;
typedef struct {

View File

@ -130,7 +130,7 @@ int8_t chassis_init(Chassis_t *c, Chassis_Param_t *param, float target_freq)
}
// 舵轮安装时的6020机械误差机械校准时1号轮在左前方所有轮的编码器朝向右面
MotorOffset_t motor_offset = {{1.6467284 / M_PI * 180.0f, 5.77390385 / M_PI * 180.0f,
MotorOffset_t motor_offset = {{1.6359905 / M_PI * 180.0f, 6.26170969 / M_PI * 180.0f,
1.56696141 / M_PI * 180.0f, 5.77160311 / M_PI * 180.0f}}; // 右右右右
c->motoroffset = motor_offset;

View File

@ -17,7 +17,9 @@
/* USER STRUCT BEGIN */
PackageAI_t ai;
PackageMCU_t mcu;
PackageReferee_t ref_pkg;
AI_result_t ai_result;
Referee_ForAI_t ref_for_ai;
AHRS_Quaternion_t quat;
Gimbal_feedback_t gimbal_motor;
PackageMCU_t shoot_mcu_package; /* 新增的 ai 数据包 主要是给自瞄发送射击数量*/
@ -45,10 +47,15 @@ void Task_ai(void *argument) {
osMessageQueueGet(task_runtime.msgq.gimbal.ai.quat, &quat, NULL, 0);
osMessageQueueGet(task_runtime.msgq.gimbal.ai.feedback, &gimbal_motor, NULL, 0);
osMessageQueueGet(task_runtime.msgq.shoot.ai.s_cmd_ai_bool_count, &shoot_mcu_package, NULL, 0);
osMessageQueueGet(task_runtime.msgq.referee.ai, &ref_for_ai, NULL, 0);
MCU_Send(&mcu,&gimbal_motor,&quat);
mcu.data.bullet_count=shoot_mcu_package.data.bullet_count; /* 从 shoot 任务获取射击数量并放入 mcu 数据包中 */
MCU_StartSend(&mcu);
if (REF_Send(&ref_pkg, &ref_for_ai.robot_status, &ref_for_ai.game_status) == DEVICE_OK) {
REF_StartSend(&ref_pkg);
}
AI_StartReceiving(&ai);
AI_Get_NUC(&ai,&ai_result);
osMessageQueueReset(task_runtime.msgq.gimbal.ai.g_cmd);

View File

@ -10,6 +10,7 @@
#include "module/config.h"
#include "device/ai.h"
#include "device/supercap.h"
#include "component/limiter.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
@ -21,7 +22,7 @@ Chassis_t chassis;
Chassis_CMD_t cmd_chassis;
AI_result_t c_cmd_ai_result; /* 新增的 ai 结果变量 主要是给底盘接收自瞄相关的命令*/
float temp_for_cap[7];//cap-add//supercap-add
float P3508[4],P6020[4],I6020[4],S6020[4],I3508[4],S3508[4],power_limit_3508=300;
float P3508[4],P6020[4],I6020[4],S6020[4],I3508[4],S3508[4],power_limit_3508=100;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
@ -89,26 +90,33 @@ osMessageQueueGet(task_runtime.msgq.navi.c_cmd, &c_cmd_ai_result, NULL, 0);
// {
// P_3508+=chassis.out.rotor3508_out[i]*S3508[i]*0.0000048;
// }
if(CAN_SuperCapRXData.SuperCapReady == 1)
{
if(CAN_SuperCapRXData.SuperCapEnergy<=10)
power_limit_3508 = 100;
else
power_limit_3508 = 320;
}
else
{
//启动老方案进行限制
}
if(CAN_SuperCapRXData.ChassisPower>power_limit_3508&&power_limit_3508>=0)
{
for(int i=0;i<4;i++)
{
chassis.out.rotor3508_out[i]*=(power_limit_3508)/
CAN_SuperCapRXData.ChassisPower>power_limit_3508; // 如果总功率超过限制按比例降低3508的输出
}
}
// if(CAN_SuperCapRXData.SuperCapReady == 1)
// {
// if(CAN_SuperCapRXData.SuperCapEnergy<=10)
// power_limit_3508 = 100;
// else
// power_limit_3508 = 320;
// if(CAN_SuperCapRXData.ChassisPower>power_limit_3508&&power_limit_3508>=0)
// {
// for(int i=0;i<4;i++)
// {
// chassis.out.rotor3508_out[i]*=(power_limit_3508)/
// CAN_SuperCapRXData.ChassisPower>power_limit_3508; // 如果总功率超过限制按比例降低3508的输出
// }
// }
// }
// else
// {
// //启动老方案进行限制
// PowerLimit_ChassicOutput(power_limit_3508,chassis.out.rotor3508_out,
// chassis.motorfeedback.rotor_rpm3508, 4); // 根据功率限制调整3508输出
// }
Chassis_Setoutput(&chassis);
/* USER CODE END */

View File

@ -21,7 +21,7 @@ Referee_ForCap_t for_cap;
Referee_ForAI_t for_ai;
Referee_ForChassis_t for_chassis;
Referee_ForShoot_t for_shoot;
int hhh;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
@ -47,7 +47,7 @@ void Task_referee(void *argument) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
Referee_StartReceiving(&ref);
if(ref.ref_status==0){hhh++;}
if (osThreadFlagsWait(SIGNAL_REFEREE_RAW_REDY, osFlagsWaitAll, 10) !=
SIGNAL_REFEREE_RAW_REDY) {
if (osKernelGetTickCount() - last_online_tick > 3000)

View File

@ -35,19 +35,19 @@ void Task_super_cap(void *argument) {
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
SuperCap_Init();
SuperCap_CanTX.Enable = 1 ; //超级电容使能。1使能0失能
SuperCap_CanTX.Charge = 0 ; //此标志位无效,超电的充放电是自动的
SuperCap_CanTX.Powerlimit = 120 ; //裁判系统功率限制
SuperCap_CanTX.ChargePower = 1 ; //此参数无效,超电的充电功率随着底盘功率变化
// SuperCap_Init();
// SuperCap_CanTX.Enable = 1 ; //超级电容使能。1使能0失能
// SuperCap_CanTX.Charge = 0 ; //此标志位无效,超电的充放电是自动的
// SuperCap_CanTX.Powerlimit = 120 ; //裁判系统功率限制
// SuperCap_CanTX.ChargePower = 1 ; //此参数无效,超电的充电功率随着底盘功率变化
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
// osMessageQueueGet(task_runtime.msgq.referee.cap, &SuperCap_CanTX.Powerlimit , NULL, 0);
SuperCap_Update();
CAN_TX_SuperCapData(&SuperCap_CanTX);
// SuperCap_Update();
// CAN_TX_SuperCapData(&SuperCap_CanTX);
/* 锁住RTOS内核防止控制过程中断造成错误 */
// osKernelLock();
/* 根据裁判系统数据计算输出功率 */