diff --git a/CMakeLists.txt b/CMakeLists.txt index fa18e30..9380cb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,8 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE User/task/rc.c User/task/shoot.c User/task/user_task.c + User/task/ai.c + User/task/Task8.c ) # Add include paths diff --git a/User/device/ai.c b/User/device/ai.c index 45e5b40..065a657 100644 --- a/User/device/ai.c +++ b/User/device/ai.c @@ -1,15 +1,15 @@ #include "ai.h" #include "bsp/uart.h" #include "component/crc16.h" -#include "module/gimbal.h" -void ai_init(AI_t* ai){ - ai->RX.head[0]="M"; - ai->RX.head[0]="R"; - ai->TX.head[0]="M"; - ai->TX.head[0]="R"; -} + +// void ai_init(AI_t* ai){ +// ai->RX.head[0]="M"; +// ai->RX.head[0]="R"; +// ai->TX.head[0]="M"; +// ai->TX.head[0]="R"; +// } @@ -49,10 +49,10 @@ int8_t AI_ParseHost(AI_t *ai,Gimbal_feedback_t* motor,AHRS_Quaternion_t* quat) { ai->TX.yaw=motor->motor.yaw_4310_motor_feedback.rotor_abs_angle; ai->TX.pitch_vel=motor->motor.pitch_4310_motor_feedback.rotor_speed; ai->TX.yaw_vel=motor->motor.yaw_4310_motor_feedback.rotor_speed; - ai->TX.q[0]=quat->q1; - ai->TX.q[1]=quat->q2; - ai->TX.q[2]=quat->q3; - ai->TX.q[3]=quat->q0; + ai->TX.q[0]=motor->imu.quat.q1; + ai->TX.q[1]=motor->imu.quat.q2; + ai->TX.q[2]=motor->imu.quat.q3; + ai->TX.q[3]=motor->imu.quat.q0; ai->TX.bullet_count=10; ai->TX.bullet_speed=10; diff --git a/User/device/ai.h b/User/device/ai.h index 0f23ca0..acb2fa9 100644 --- a/User/device/ai.h +++ b/User/device/ai.h @@ -8,6 +8,7 @@ extern "C" { /* Includes ----------------------------------------------------------------- */ #include "component\user_math.h" #include "remote_control.h" +#include "module/gimbal.h" struct __attribute__((packed)) GimbalToVision { @@ -63,6 +64,18 @@ typedef struct __attribute__((packed)) { struct GimbalToVision TX; struct VisionToGimbal RX; }AI_t; + + + +int8_t AI_StartReceiving(AI_t *ai) ; + +int8_t AI_Get_NUC(AI_t * ai,AI_cmd_t* ai_cmd) ; + + +int8_t AI_ParseHost(AI_t * ai,Gimbal_feedback_t* motor,AHRS_Quaternion_t* quat) ; + +int8_t AI_StartSend(AI_t *ai) ; + #ifdef __cplusplus } #endif diff --git a/User/device/remote_control.c b/User/device/remote_control.c index 2ae5e10..bc37c0b 100644 --- a/User/device/remote_control.c +++ b/User/device/remote_control.c @@ -212,7 +212,7 @@ int8_t REMOTE_ParseRC(DR16_t *dr16, CMD_RC_t *rc,ET16s_raw_t *et16s) { // rc->ET16s.knob_left = ET16s->sw[7]; //200 330 479 629 778 928 1075 1224 1373 1522 1670 1800 // /*离线处理,和dr16位置不同*/ - if(et16s->sw[3]==1695) + if(et16s->sw[6]==1695) { ET16s_HandleOffline(et16s,rc); // memset(cbuf, 0, sizeof(cbuf)); //有时候会出现消息数组错位,所以直接清空,在离线和指定按键不对的情况下,原数据不可信 diff --git a/User/module/chassis.c b/User/module/chassis.c index b304188..499aafd 100644 --- a/User/module/chassis.c +++ b/User/module/chassis.c @@ -129,7 +129,7 @@ int8_t chassis_init(Chassis_t *c, Chassis_Param_t *param, float target_freq) // 舵轮安装时的6020机械误差,机械校准时1号轮在左前方,所有轮的编码器朝向右面 MotorOffset_t motor_offset = {{3.67848611 / M_PI * 180.0f, 2.61390328 / M_PI * 180.0f, - 4.71852493 / M_PI * 180.0f, 2.62694216 / M_PI * 180.0f}}; // 右右右右 + 2.11075759 / M_PI * 180.0f, 2.62694216 / M_PI * 180.0f}}; // 右右右右 c->motoroffset = motor_offset; /*对3508的速度环和6020的角速度以及位置环pid进行初始化*/ @@ -416,7 +416,7 @@ int8_t Chassis_Control(Chassis_t *c, Chassis_CMD_t *c_cmd,uint32_t now) for (int i = 0; i < 4; i++) { - float chassis6020_detangle[4]; // 6020解算出的角度 + float chassis6020_detangle[4]; // 6020解算出的角度 c->hopemotorout.motor6020_target[i] = c->hopemotorout.rotor6020_jiesuan_2[i]; chassis6020_detangle[i] = PID_Calc(&(c->pid.chassis_6020anglePid[i]), c->hopemotorout.motor6020_target[i], c->motorfeedback.rotor_angle6020[i], 0.0f, c->dt); diff --git a/User/module/cmd.c b/User/module/cmd.c index d4cd0bd..116fd7e 100644 --- a/User/module/cmd.c +++ b/User/module/cmd.c @@ -177,15 +177,21 @@ int8_t CMD_CtrlSet(Chassis_CMD_t *c_cmd, const CMD_RC_t *rc, Gimbal_CMD_t *g_cmd { case CMD_SW_UP: s_cmd->firecmd = false; + s_cmd->ready = false; + break; case CMD_SW_MID: s_cmd->firecmd = false; + s_cmd->ready = true; + break; case CMD_SW_DOWN: s_cmd->firecmd = true; + s_cmd->ready = true; break; case CMD_SW_ERR: s_cmd->firecmd = false; + s_cmd->ready = false; break; } } diff --git a/User/module/config.c b/User/module/config.c index b620a16..973433b 100644 --- a/User/module/config.c +++ b/User/module/config.c @@ -213,16 +213,16 @@ static const Config_Param_t config = { }, .shoot = { - .motor.fric[0] = {BSP_CAN_2, 0x205, MOTOR_M3508, false, false}, - .motor.fric[1] = {BSP_CAN_2, 0x206, MOTOR_M3508, false, false}, - .motor.trig = {BSP_CAN_2, 0x207, MOTOR_M2006, false, true}, + .motor.fric[0] = {{BSP_CAN_2, 0x201, MOTOR_M3508, false, false},.level=1}, + .motor.fric[1] = {{BSP_CAN_2, 0x202, MOTOR_M3508, true, false},.level=1}, + .motor.trig = {BSP_CAN_2, 0x203, MOTOR_M2006, false, true}, .basic.projectileType = SHOOT_PROJECTILE_17MM, .basic.fric_num = 2, - .basic.ratio_multilevel = {1.0f, 1.0f}, .basic.extra_deceleration_ratio = 1, + .basic.ratio_multilevel[0] = 1.0f, .basic.num_trig_tooth = 8, - .basic.shot_freq = 1.0f, + .basic.shot_freq = 20.0f, .basic.shot_burst_num = 5, .jamDetection.enable = true, @@ -253,20 +253,20 @@ static const Config_Param_t config = { }, .trig_2006={ - .k=2.5f, - .p=1.0f, - .i=0.1f, - .d=0.04f, - .i_limit=0.4f, + .k=0.5f, + .p=0.5f, + .i=0.5f, + .d=0.05f, + .i_limit=0.2f, .out_limit=1.0f, .d_cutoff_freq=-1.0f, .range=M_2PI, }, .trig_omg_2006={ - .k=1.0f, - .p=1.5f, - .i=0.3f, + .k=3.0f, + .p=2.0f, + .i=0.2f, .d=0.5f, .i_limit=0.2f, .out_limit=1.0f, diff --git a/User/module/gimbal.c b/User/module/gimbal.c index 215251d..caf91cd 100644 --- a/User/module/gimbal.c +++ b/User/module/gimbal.c @@ -245,8 +245,8 @@ const float delta_min_6020 = CircleError(g->limit.yaw_6020.min, if(delta_yaw_6020 > delta_max_6020) delta_yaw_6020 = delta_max_6020; if(delta_yaw_6020 < delta_min_6020) delta_yaw_6020 = delta_min_6020; } - // CircleAdd(&(g->setpoint.eulr.yaw), delta_yaw_6020, M_2PI); - g->setpoint.eulr.yaw = g->setpoint.NUC_Yaw; + CircleAdd(&(g->setpoint.eulr.yaw), delta_yaw_6020, M_2PI); + // g->setpoint.eulr.yaw = g->setpoint.NUC_Yaw; /*处理大yaw控制命令,软件限位 - 使用电机绝对角度*/ /*获得小YAW的中点位置,如果小YAW大于中点的一定范围,大YAW开始运动, @@ -280,8 +280,8 @@ if(g->param->travel.pitch_4310 > 0) // 有限位才处理 if (delta_pitch_4310 > delta_max_pitch) delta_pitch_4310 = delta_max_pitch; if (delta_pitch_4310 < delta_min_pitch) delta_pitch_4310 = delta_min_pitch; } - // CircleAdd(&(g->setpoint.eulr.pit), delta_pitch_4310, M_2PI); - g->setpoint.eulr.pit = g->setpoint.NUC_Pitch; + CircleAdd(&(g->setpoint.eulr.pit), delta_pitch_4310, M_2PI); + // g->setpoint.eulr.pit = g->setpoint.NUC_Pitch; /* 控制相关逻辑 */ float yaw_omega_set_point, pitch_omega_set_point,yaw_6020_omega_set_point; diff --git a/User/module/shoot.c b/User/module/shoot.c index 555d071..9e97fdd 100644 --- a/User/module/shoot.c +++ b/User/module/shoot.c @@ -42,12 +42,10 @@ void Task(void *argument) { /* Private typedef ---------------------------------------------------------- */ /* Private define ----------------------------------------------------------- */ #define MAX_FRIC_RPM 7000.0f -#define MAX_TRIG_RPM 1500.0f//这里可能也会影响最高发射频率,待测试 +#define MAX_TRIG_RPM 6000.0f//这里可能也会影响最高发射频率,待测试 /* Private macro ------------------------------------------------------------ */ /* Private variables -------------------------------------------------------- */ static bool last_firecmd; - -float maxTrigrpm=4000.0f; /* Private function -------------------------------------------------------- */ /** @@ -286,7 +284,7 @@ int8_t Shoot_UpdateFeedback(Shoot_t *s) s->var_trig.trig_agl = M_2PI - s->var_trig.trig_agl; } s->var_trig.fil_trig_rpm = LowPassFilter2p_Apply(&s->filter.trig.in, s->feedback.trig.feedback.rotor_speed); - s->var_trig.trig_rpm = s->feedback.trig.feedback.rotor_speed / maxTrigrpm; + s->var_trig.trig_rpm = s->feedback.trig.feedback.rotor_speed / MAX_TRIG_RPM; if(s->var_trig.trig_rpm>1.0f)s->var_trig.trig_rpm=1.0f; if(s->var_trig.trig_rpm<-1.0f)s->var_trig.trig_rpm=-1.0f; diff --git a/User/module/shoot.h b/User/module/shoot.h index c061ff1..4cb2705 100644 --- a/User/module/shoot.h +++ b/User/module/shoot.h @@ -14,8 +14,8 @@ extern "C" { #include "device/motor_rm.h" #include "module/cmd.h" /* Exported constants ------------------------------------------------------- */ -#define MAX_FRIC_NUM 6 -#define MAX_NUM_MULTILEVEL 2 /* 多级发射级数 */ +#define MAX_FRIC_NUM 2 +#define MAX_NUM_MULTILEVEL 1 /* 多级发射级数 */ #define SHOOT_OK (0) /* 运行正常 */ #define SHOOT_ERR_NULL (-1) /* 运行时发现NULL指针 */ diff --git a/User/task/Task8.c b/User/task/Task8.c new file mode 100644 index 0000000..a137390 --- /dev/null +++ b/User/task/Task8.c @@ -0,0 +1,44 @@ +/* + Task8 Task + +*/ + +/* Includes ----------------------------------------------------------------- */ +#include "task/user_task.h" +/* USER INCLUDE BEGIN */ + +/* USER INCLUDE END */ + +/* Private typedef ---------------------------------------------------------- */ +/* Private define ----------------------------------------------------------- */ +/* Private macro ------------------------------------------------------------ */ +/* Private variables -------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + +/* Private function --------------------------------------------------------- */ +/* Exported functions ------------------------------------------------------- */ +void Task_Task8(void *argument) { + (void)argument; /* 未使用argument,消除警告 */ + + + /* 计算任务运行到指定频率需要等待的tick数 */ + const uint32_t delay_tick = osKernelGetTickFreq() / TASK8_FREQ; + + osDelay(TASK8_INIT_DELAY); /* 延时一段时间再开启任务 */ + + uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */ + /* USER CODE INIT BEGIN */ + + /* USER CODE INIT END */ + + while (1) { + tick += delay_tick; /* 计算下一个唤醒时刻 */ + /* USER CODE BEGIN */ + + /* USER CODE END */ + osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */ + } + +} \ No newline at end of file diff --git a/User/task/ai.c b/User/task/ai.c new file mode 100644 index 0000000..545cef9 --- /dev/null +++ b/User/task/ai.c @@ -0,0 +1,56 @@ +/* + ai Task + +*/ + +/* Includes ----------------------------------------------------------------- */ +#include "task/user_task.h" +/* USER INCLUDE BEGIN */ +#include "device/ai.h" +#include "module/gimbal.h" +/* USER INCLUDE END */ + +/* Private typedef ---------------------------------------------------------- */ +/* Private define ----------------------------------------------------------- */ +/* Private macro ------------------------------------------------------------ */ +/* Private variables -------------------------------------------------------- */ +/* USER STRUCT BEGIN */ +AI_t ai; +AI_cmd_t ai_cmd; +AHRS_Quaternion_t quat; +Gimbal_feedback_t gimbal_motor; +/* USER STRUCT END */ + +/* Private function --------------------------------------------------------- */ +/* Exported functions ------------------------------------------------------- */ +void Task_ai(void *argument) { + (void)argument; /* 未使用argument,消除警告 */ + + + /* 计算任务运行到指定频率需要等待的tick数 */ + const uint32_t delay_tick = osKernelGetTickFreq() / AI_FREQ; + + osDelay(AI_INIT_DELAY); /* 延时一段时间再开启任务 */ + + uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */ + /* USER CODE INIT BEGIN */ + + /* USER CODE INIT END */ + + while (1) { + tick += delay_tick; /* 计算下一个唤醒时刻 */ + /* USER CODE BEGIN */ + osMessageQueueGet(task_runtime.msgq.gimbal.ai.quat, &quat, NULL, 0); + osMessageQueueGet(task_runtime.msgq.gimbal.ai.feedback, &gimbal_motor, NULL, 0); + AI_ParseHost(&ai,&gimbal_motor,&quat); + AI_StartSend(&ai); + + AI_StartReceiving(&ai); + AI_Get_NUC(&ai,&ai_cmd); + osMessageQueueReset(task_runtime.msgq.gimbal.ai.g_cmd); + osMessageQueuePut(task_runtime.msgq.gimbal.ai.g_cmd, &ai_cmd, 0, 0); + /* USER CODE END */ + osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */ + } + +} \ No newline at end of file diff --git a/User/task/atti_esti.c b/User/task/atti_esti.c index ef2b3a6..ad290c3 100644 --- a/User/task/atti_esti.c +++ b/User/task/atti_esti.c @@ -1,9 +1,6 @@ /* atti_esti Task - 任务一用来进行c板自带的陀螺仪bmi088的数据采集和姿态解算,同时对陀螺仪进行温控 - 控制IMU加热到指定温度防止温漂,收集IMU数据给AHRS算法。 - 收集BMI088的数据,解算后得到四元数,转换为欧拉角之后放到消息队列中, - 等待其他任务取用。 + */ /* Includes ----------------------------------------------------------------- */ diff --git a/User/task/chassis.c b/User/task/chassis.c index 59da349..246c4ad 100644 --- a/User/task/chassis.c +++ b/User/task/chassis.c @@ -53,7 +53,7 @@ chassis_init(&chassis,&Config_GetRobotParam()->chassis,CHASSIS_FREQ); Chassis_CMD_t safe_cmd = {.mode = STOP, .Vx = 0, .Vy = 0, .Vw = 0}; Chassis_Control(&chassis, &safe_cmd,tick); } - // Chassis_Setoutput(&chassis); + Chassis_Setoutput(&chassis); /* USER CODE END */ osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */ } diff --git a/User/task/cmd.c b/User/task/cmd.c index 4ba86bc..a2464ac 100644 --- a/User/task/cmd.c +++ b/User/task/cmd.c @@ -4,7 +4,6 @@ */ /* Includes ----------------------------------------------------------------- */ -#include "cmsis_os2.h" #include "task/user_task.h" /* USER INCLUDE BEGIN */ #include "module/cmd.h" diff --git a/User/task/config.yaml b/User/task/config.yaml index d119ce3..1528273 100644 --- a/User/task/config.yaml +++ b/User/task/config.yaml @@ -40,3 +40,17 @@ function: Task_shoot name: shoot stack: 256 +- delay: 0 + description: '' + freq_control: true + frequency: 250.0 + function: Task_ai + name: ai + stack: 256 +- delay: 0 + description: '' + freq_control: true + frequency: 500.0 + function: Task_Task8 + name: Task8 + stack: 256 diff --git a/User/task/gimbal.c b/User/task/gimbal.c index f54ccd0..21750d0 100644 --- a/User/task/gimbal.c +++ b/User/task/gimbal.c @@ -48,6 +48,8 @@ Gimbal_UpdateFeedback(&gimbal); osMessageQueueReset(task_runtime.msgq.gimbal.yaw6020); osMessageQueuePut(task_runtime.msgq.gimbal.yaw6020, &gimbal.feedback.motor.yaw_4310_motor_feedback, 0, 0); +osMessageQueueReset(task_runtime.msgq.gimbal.ai.feedback); +osMessageQueuePut(task_runtime.msgq.gimbal.ai.feedback, &gimbal.feedback, 0, 0); Gimbal_Control(&gimbal, &cmd_gimbal); diff --git a/User/task/init.c b/User/task/init.c index d9bbad0..b702be9 100644 --- a/User/task/init.c +++ b/User/task/init.c @@ -36,11 +36,13 @@ void Task_Init(void *argument) { task_runtime.thread.chassis = osThreadNew(Task_chassis, NULL, &attr_chassis); task_runtime.thread.cmd = osThreadNew(Task_cmd, NULL, &attr_cmd); task_runtime.thread.gimbal = osThreadNew(Task_gimbal, NULL, &attr_gimbal); - // task_runtime.thread.shoot = osThreadNew(Task_shoot, NULL, &attr_shoot); + task_runtime.thread.shoot = osThreadNew(Task_shoot, NULL, &attr_shoot); + task_runtime.thread.ai = osThreadNew(Task_ai, NULL, &attr_ai); + task_runtime.thread.Task8 = osThreadNew(Task_Task8, NULL, &attr_Task8); // 创建消息队列 /* USER MESSAGE BEGIN */ - task_runtime.msgq.user_msg= osMessageQueueNew(2u, 10, NULL); + task_runtime.msgq.user_msg= osMessageQueueNew(2u, 15, NULL); task_runtime.msgq.cmd.raw.rc = osMessageQueueNew(2u, sizeof(CMD_RC_t), NULL); task_runtime.msgq.chassis.cmd = osMessageQueueNew(2u, sizeof(Chassis_CMD_t), NULL); task_runtime.msgq.imu.eulr = osMessageQueueNew(2u, sizeof(AHRS_Eulr_t), NULL); @@ -50,7 +52,9 @@ void Task_Init(void *argument) { task_runtime.msgq.gimbal.cmd = osMessageQueueNew(2u, sizeof(Gimbal_CMD_t), NULL); task_runtime.msgq.gimbal.yaw6020 = osMessageQueueNew(2u, sizeof(MOTOR_Feedback_t), NULL); task_runtime.msgq.shoot.cmd = osMessageQueueNew(2u, sizeof(Shoot_CMD_t),NULL); - task_runtime.msgq.gimbal.ai = osMessageQueueNew(2u, sizeof(AI_t),NULL); + task_runtime.msgq.gimbal.ai.feedback = osMessageQueueNew(2u, sizeof(Gimbal_feedback_t),NULL); + task_runtime.msgq.gimbal.ai.g_cmd = osMessageQueueNew(2u, sizeof(AI_cmd_t),NULL); + /* USER MESSAGE END */ osKernelUnlock(); // 解锁内核 diff --git a/User/task/shoot.c b/User/task/shoot.c index 3c65096..3565cb0 100644 --- a/User/task/shoot.c +++ b/User/task/shoot.c @@ -1,4 +1,3 @@ - /* shoot Task @@ -26,7 +25,7 @@ Shoot_CMD_t shoot_cmd; void Task_shoot(void *argument) { (void)argument; /* 未使用argument,消除警告 */ - + /* 计算任务运行到指定频率需要等待的tick数 */ const uint32_t delay_tick = osKernelGetTickFreq() / SHOOT_FREQ; @@ -35,7 +34,7 @@ void Task_shoot(void *argument) { uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */ /* USER CODE INIT BEGIN */ Shoot_Init(&shoot,&Config_GetRobotParam()->shoot,SHOOT_FREQ); - +Shoot_SetMode(&shoot,SHOOT_MODE_SINGLE); /* USER CODE INIT END */ @@ -43,9 +42,12 @@ Shoot_Init(&shoot,&Config_GetRobotParam()->shoot,SHOOT_FREQ); tick += delay_tick; /* 计算下一个唤醒时刻 */ /* USER CODE BEGIN */ osMessageQueueGet(task_runtime.msgq.shoot.cmd, &shoot_cmd, NULL, 0); -// Shoot_UpdateFeedback(&shoot); -// Shoot_SetMode(&shoot,shoot_cmd.mode); -// Shoot_Control(&shoot,&shoot_cmd); + + + + Shoot_UpdateFeedback(&shoot); + Shoot_SetMode(&shoot,shoot_cmd.mode); + Shoot_Control(&shoot,&shoot_cmd); /* USER CODE END */ osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */ diff --git a/User/task/tempCodeRunnerFile.c b/User/task/tempCodeRunnerFile.c new file mode 100644 index 0000000..6c678fc --- /dev/null +++ b/User/task/tempCodeRunnerFile.c @@ -0,0 +1 @@ +feedback \ No newline at end of file diff --git a/User/task/user_task.c b/User/task/user_task.c index 7e27c9a..d2952cf 100644 --- a/User/task/user_task.c +++ b/User/task/user_task.c @@ -17,17 +17,17 @@ const osThreadAttr_t attr_atti_esti = { const osThreadAttr_t attr_rc = { .name = "rc", .priority = osPriorityNormal, - .stack_size = 512 * 4, + .stack_size = 256 * 4, }; const osThreadAttr_t attr_chassis = { .name = "chassis", .priority = osPriorityNormal, - .stack_size = 512 * 4, + .stack_size = 256 * 4, }; const osThreadAttr_t attr_cmd = { .name = "cmd", .priority = osPriorityNormal, - .stack_size = 512 * 4, + .stack_size = 256 * 4, }; const osThreadAttr_t attr_gimbal = { .name = "gimbal", @@ -38,4 +38,14 @@ const osThreadAttr_t attr_shoot = { .name = "shoot", .priority = osPriorityNormal, .stack_size = 256 * 4, +}; +const osThreadAttr_t attr_ai = { + .name = "ai", + .priority = osPriorityNormal, + .stack_size = 256 * 4, +}; +const osThreadAttr_t attr_Task8 = { + .name = "Task8", + .priority = osPriorityNormal, + .stack_size = 256 * 4, }; \ No newline at end of file diff --git a/User/task/user_task.h b/User/task/user_task.h index 6f5309c..3e33264 100644 --- a/User/task/user_task.h +++ b/User/task/user_task.h @@ -1,8 +1,7 @@ #pragma once #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /* Includes ----------------------------------------------------------------- */ #include @@ -20,6 +19,8 @@ extern "C" #define CMD_FREQ (500.0) #define GIMBAL_FREQ (500.0) #define SHOOT_FREQ (500.0) +#define AI_FREQ (250.0) +#define TASK8_FREQ (500.0) /* 任务初始化延时ms */ #define TASK_INIT_DELAY (100u) @@ -29,26 +30,28 @@ extern "C" #define CMD_INIT_DELAY (0) #define GIMBAL_INIT_DELAY (0) #define SHOOT_INIT_DELAY (0) +#define AI_INIT_DELAY (0) +#define TASK8_INIT_DELAY (0) - /* Exported defines --------------------------------------------------------- */ - /* Exported macro ----------------------------------------------------------- */ - /* Exported types ----------------------------------------------------------- */ +/* Exported defines --------------------------------------------------------- */ +/* Exported macro ----------------------------------------------------------- */ +/* Exported types ----------------------------------------------------------- */ - /* 任务运行时结构体 */ - typedef struct - { - /* 各任务,也可以叫做线程 */ - struct - { - osThreadId_t atti_esti; - osThreadId_t rc; - osThreadId_t chassis; - osThreadId_t cmd; - osThreadId_t gimbal; - osThreadId_t shoot; - } thread; +/* 任务运行时结构体 */ +typedef struct { + /* 各任务,也可以叫做线程 */ + struct { + osThreadId_t atti_esti; + osThreadId_t rc; + osThreadId_t chassis; + osThreadId_t cmd; + osThreadId_t gimbal; + osThreadId_t shoot; + osThreadId_t ai; + osThreadId_t Task8; + } thread; - /* USER MESSAGE BEGIN */ + /* USER MESSAGE BEGIN */ struct { osMessageQueueId_t user_msg; /* 用户自定义任务消息队列 */ @@ -84,7 +87,12 @@ extern "C" osMessageQueueId_t imu; osMessageQueueId_t cmd; osMessageQueueId_t yaw6020; /* 新增的 yaw_6020 消息队列 主要是给底盘传6020位置的反馈*/ - osMessageQueueId_t ai; /* 新增的 ai 消息队列 主要是给自瞄*/ + struct{ + osMessageQueueId_t quat; + osMessageQueueId_t feedback; + osMessageQueueId_t g_cmd; + }ai; + /* 新增的 ai 消息队列 主要是给自瞄*/ } gimbal; struct @@ -95,72 +103,79 @@ extern "C" } msgq; /* USER MESSAGE END */ - /* 机器人状态 */ - struct - { - float battery; /* 电池电量百分比 */ - float vbat; /* 电池电压 */ - float cpu_temp; /* CPU温度 */ - } status; + /* 机器人状态 */ + struct { + float battery; /* 电池电量百分比 */ + float vbat; /* 电池电压 */ + float cpu_temp; /* CPU温度 */ + } status; - /* USER CONFIG BEGIN */ + /* USER CONFIG BEGIN */ Config_t config; /* USER CONFIG END */ - /* 各任务的stack使用 */ - struct - { - UBaseType_t atti_esti; - UBaseType_t rc; - UBaseType_t chassis; - UBaseType_t cmd; - UBaseType_t gimbal; - UBaseType_t shoot; - } stack_water_mark; + /* 各任务的stack使用 */ + struct { + UBaseType_t atti_esti; + UBaseType_t rc; + UBaseType_t chassis; + UBaseType_t cmd; + UBaseType_t gimbal; + UBaseType_t shoot; + UBaseType_t ai; + UBaseType_t Task8; + } stack_water_mark; - /* 各任务运行频率 */ - struct - { - float atti_esti; - float rc; - float chassis; - float cmd; - float gimbal; - float shoot; - } freq; + /* 各任务运行频率 */ + struct { + float atti_esti; + float rc; + float chassis; + float cmd; + float gimbal; + float shoot; + float ai; + float Task8; + } freq; - /* 任务最近运行时间 */ - struct - { - float atti_esti; - float rc; - float chassis; - float cmd; - float gimbal; - float shoot; - } last_up_time; - } Task_Runtime_t; + /* 任务最近运行时间 */ + struct { + float atti_esti; + float rc; + float chassis; + float cmd; + float gimbal; + float shoot; + float ai; + float Task8; + } last_up_time; - /* 任务运行时结构体 */ - extern Task_Runtime_t task_runtime; +} Task_Runtime_t; - /* 初始化任务句柄 */ - extern const osThreadAttr_t attr_init; - extern const osThreadAttr_t attr_atti_esti; - extern const osThreadAttr_t attr_rc; - extern const osThreadAttr_t attr_chassis; - extern const osThreadAttr_t attr_cmd; - extern const osThreadAttr_t attr_gimbal; - extern const osThreadAttr_t attr_shoot; +/* 任务运行时结构体 */ +extern Task_Runtime_t task_runtime; - /* 任务函数声明 */ - void Task_Init(void *argument); - void Task_atti_esti(void *argument); - void Task_rc(void *argument); - void Task_chassis(void *argument); - void Task_cmd(void *argument); - void Task_gimbal(void *argument); - void Task_shoot(void *argument); +/* 初始化任务句柄 */ +extern const osThreadAttr_t attr_init; +extern const osThreadAttr_t attr_atti_esti; +extern const osThreadAttr_t attr_rc; +extern const osThreadAttr_t attr_chassis; +extern const osThreadAttr_t attr_cmd; +extern const osThreadAttr_t attr_gimbal; +extern const osThreadAttr_t attr_shoot; +extern const osThreadAttr_t attr_ai; +extern const osThreadAttr_t attr_Task8; + +/* 任务函数声明 */ +void Task_Init(void *argument); +void Task_atti_esti(void *argument); +void Task_rc(void *argument); +void Task_chassis(void *argument); +void Task_cmd(void *argument); +void Task_gimbal(void *argument); +void Task_shoot(void *argument); +void Task_ai(void *argument); +void Task_Task8(void *argument); #ifdef __cplusplus }