Compare commits
2 Commits
0792257ea1
...
8ccffa1b1a
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ccffa1b1a | |||
| a84fcaa0f0 |
@ -177,7 +177,7 @@ int8_t Shoot_CaluTargetRPM(Shoot_t *s, float target_speed)
|
|||||||
s->target_variable.fric_rpm=5000.0f;
|
s->target_variable.fric_rpm=5000.0f;
|
||||||
break;
|
break;
|
||||||
case SHOOT_PROJECTILE_42MM:
|
case SHOOT_PROJECTILE_42MM:
|
||||||
s->target_variable.fric_rpm=4000.0f;
|
s->target_variable.fric_rpm=6500.0f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return SHOOT_OK;
|
return SHOOT_OK;
|
||||||
|
|||||||
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
#include "task/user_task.h"
|
#include "task/user_task.h"
|
||||||
/* USER INCLUDE BEGIN */
|
/* USER INCLUDE BEGIN */
|
||||||
#include "module/vision_bridge.h"
|
// #include "module/vision_bridge.h"
|
||||||
#include "component/ahrs/ahrs.h"
|
// #include "component/ahrs/ahrs.h"
|
||||||
#include "module/gimbal.h"
|
// #include "module/gimbal.h"
|
||||||
#include "module/shoot.h"
|
// #include "module/shoot.h"
|
||||||
/* USER INCLUDE END */
|
/* USER INCLUDE END */
|
||||||
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
@ -18,12 +18,12 @@
|
|||||||
/* Private macro ------------------------------------------------------------ */
|
/* Private macro ------------------------------------------------------------ */
|
||||||
/* Private variables -------------------------------------------------------- */
|
/* Private variables -------------------------------------------------------- */
|
||||||
/* USER STRUCT BEGIN */
|
/* USER STRUCT BEGIN */
|
||||||
AI_t ai;
|
// AI_t ai;
|
||||||
AI_cmd_t aiToCmd;
|
// AI_cmd_t aiToCmd;
|
||||||
|
|
||||||
AI_RawData_t rawdata;
|
// AI_RawData_t rawdata;
|
||||||
AHRS_Quaternion_t quat_from_imu;
|
// AHRS_Quaternion_t quat_from_imu;
|
||||||
Gimbal_Feedback_t rawdata_from_gimbal;
|
// Gimbal_Feedback_t rawdata_from_gimbal;
|
||||||
/* USER STRUCT END */
|
/* USER STRUCT END */
|
||||||
|
|
||||||
/* Private function --------------------------------------------------------- */
|
/* Private function --------------------------------------------------------- */
|
||||||
@ -46,24 +46,24 @@ void Task_ai(void *argument) {
|
|||||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
/* USER CODE BEGIN */
|
/* USER CODE BEGIN */
|
||||||
|
|
||||||
osMessageQueueGet(task_runtime.msgq.ai.rawdata_FromGimbal, &rawdata_from_gimbal, NULL, 0);
|
// osMessageQueueGet(task_runtime.msgq.ai.rawdata_FromGimbal, &rawdata_from_gimbal, NULL, 0);
|
||||||
osMessageQueueGet(task_runtime.msgq.ai.rawdata_FromIMU, &quat_from_imu, NULL, 0);
|
// osMessageQueueGet(task_runtime.msgq.ai.rawdata_FromIMU, &quat_from_imu, NULL, 0);
|
||||||
rawdata.mode=1;
|
// rawdata.mode=1;
|
||||||
rawdata.pitch=rawdata_from_gimbal.motor.pit.rotor_abs_angle;
|
// rawdata.pitch=rawdata_from_gimbal.motor.pit.rotor_abs_angle;
|
||||||
rawdata.yaw=rawdata_from_gimbal.motor.yaw.rotor_abs_angle;
|
// rawdata.yaw=rawdata_from_gimbal.motor.yaw.rotor_abs_angle;
|
||||||
rawdata.pitch_vel=rawdata_from_gimbal.motor.pit.rotor_speed;
|
// rawdata.pitch_vel=rawdata_from_gimbal.motor.pit.rotor_speed;
|
||||||
rawdata.yaw_vel=rawdata_from_gimbal.motor.yaw.rotor_speed;
|
// rawdata.yaw_vel=rawdata_from_gimbal.motor.yaw.rotor_speed;
|
||||||
rawdata.q[0]=quat_from_imu.q0;
|
// rawdata.q[0]=quat_from_imu.q0;
|
||||||
rawdata.q[1]=quat_from_imu.q1;
|
// rawdata.q[1]=quat_from_imu.q1;
|
||||||
rawdata.q[2]=quat_from_imu.q2;
|
// rawdata.q[2]=quat_from_imu.q2;
|
||||||
rawdata.q[3]=quat_from_imu.q3;
|
// rawdata.q[3]=quat_from_imu.q3;
|
||||||
AI_ParseForHost(&ai,&rawdata);
|
// AI_ParseForHost(&ai,&rawdata);
|
||||||
AI_StartSend(&ai);
|
// AI_StartSend(&ai);
|
||||||
|
|
||||||
AI_StartReceiving(&ai);
|
// AI_StartReceiving(&ai);
|
||||||
AI_Get(&ai,&aiToCmd);
|
// AI_Get(&ai,&aiToCmd);
|
||||||
osMessageQueueReset(task_runtime.msgq.cmd.nuc);
|
// osMessageQueueReset(task_runtime.msgq.cmd.nuc);
|
||||||
osMessageQueuePut(task_runtime.msgq.cmd.nuc, &aiToCmd, 0, 0);
|
// osMessageQueuePut(task_runtime.msgq.cmd.nuc, &aiToCmd, 0, 0);
|
||||||
/* USER CODE END */
|
/* USER CODE END */
|
||||||
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
/* Private define ----------------------------------------------------------- */
|
/* Private define ----------------------------------------------------------- */
|
||||||
#define ATTI_EULR_CAN_ID (0x321u)
|
#define ATTI_EULR_CAN_ID (0x100u)
|
||||||
#define ATTI_EULR_SCALE (10000.0f) /* 0.0001 rad per LSB */
|
#define ATTI_EULR_SCALE (10000.0f) /* 0.0001 rad per LSB */
|
||||||
#define ATTI_EULR_CAN_DLC (6u)
|
#define ATTI_EULR_CAN_DLC (6u)
|
||||||
/* Private macro ------------------------------------------------------------ */
|
/* Private macro ------------------------------------------------------------ */
|
||||||
|
|||||||
@ -14,11 +14,15 @@
|
|||||||
#include "module/shoot.h"
|
#include "module/shoot.h"
|
||||||
#include "module/track.h"
|
#include "module/track.h"
|
||||||
#include "module/cmd/cmd.h"
|
#include "module/cmd/cmd.h"
|
||||||
|
#include "bsp/fdcan.h"
|
||||||
//#define DEAD_AREA 0.05f
|
//#define DEAD_AREA 0.05f
|
||||||
/* USER INCLUDE END */
|
/* USER INCLUDE END */
|
||||||
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
/* Private define ----------------------------------------------------------- */
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
#define AI_CMD_CAN_ID (0x101u)
|
||||||
|
#define AI_CMD_CAN_DLC (5u) /* 1字节mode + 2字节yaw + 2字节pit */
|
||||||
|
#define AI_CMD_ANGLE_SCALE (10000.0f) /* 0.0001 rad per LSB */
|
||||||
/* Private macro ------------------------------------------------------------ */
|
/* Private macro ------------------------------------------------------------ */
|
||||||
/* Private variables -------------------------------------------------------- */
|
/* Private variables -------------------------------------------------------- */
|
||||||
/* USER STRUCT BEGIN */
|
/* USER STRUCT BEGIN */
|
||||||
@ -37,6 +41,7 @@ static CMD_t cmd;
|
|||||||
/* USER STRUCT END */
|
/* USER STRUCT END */
|
||||||
|
|
||||||
/* Private function --------------------------------------------------------- */
|
/* Private function --------------------------------------------------------- */
|
||||||
|
static void AI_ParseCmdFromCan(const BSP_FDCAN_Message_t *msg, AI_cmd_t *cmd);
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
void Task_cmd(void *argument) {
|
void Task_cmd(void *argument) {
|
||||||
(void)argument; /* 未使用argument,消除警告 */
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
@ -50,6 +55,9 @@ void Task_cmd(void *argument) {
|
|||||||
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||||
/* USER CODE INIT BEGIN */
|
/* USER CODE INIT BEGIN */
|
||||||
CMD_Init(&cmd, &Config_GetRobotParam()->cmd_param);
|
CMD_Init(&cmd, &Config_GetRobotParam()->cmd_param);
|
||||||
|
|
||||||
|
/* 注册CAN接收ID */
|
||||||
|
BSP_FDCAN_RegisterId(BSP_FDCAN_2, AI_CMD_CAN_ID, BSP_FDCAN_DEFAULT_QUEUE_SIZE);
|
||||||
/* USER CODE INIT END */
|
/* USER CODE INIT END */
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -60,8 +68,13 @@ void Task_cmd(void *argument) {
|
|||||||
#elif CMD_RCTypeTable_Index == 1
|
#elif CMD_RCTypeTable_Index == 1
|
||||||
osMessageQueueGet(task_runtime.msgq.cmd.rc, &cmd_at9s, NULL, 0);
|
osMessageQueueGet(task_runtime.msgq.cmd.rc, &cmd_at9s, NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
osMessageQueueGet(task_runtime.msgq.cmd.nuc, &cmd_ai, NULL, 0);
|
|
||||||
|
|
||||||
|
/* 从CAN2接收AI命令 */
|
||||||
|
BSP_FDCAN_Message_t can_msg;
|
||||||
|
if (BSP_FDCAN_GetMessage(BSP_FDCAN_2, AI_CMD_CAN_ID, &can_msg, BSP_FDCAN_TIMEOUT_IMMEDIATE) == 0) {
|
||||||
|
AI_ParseCmdFromCan(&can_msg, &cmd_ai);
|
||||||
|
}
|
||||||
|
|
||||||
CMD_Update(&cmd);
|
CMD_Update(&cmd);
|
||||||
|
|
||||||
/* 获取命令发送到各模块 */
|
/* 获取命令发送到各模块 */
|
||||||
@ -81,4 +94,28 @@ void Task_cmd(void *argument) {
|
|||||||
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 从CAN消息解析AI命令 (mode + yaw + pit) */
|
||||||
|
static void AI_ParseCmdFromCan(const BSP_FDCAN_Message_t *msg, AI_cmd_t *cmd) {
|
||||||
|
if (msg == NULL || cmd == NULL || msg->dlc < AI_CMD_CAN_DLC) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 解析mode (1字节) */
|
||||||
|
cmd->mode = msg->data[0];
|
||||||
|
|
||||||
|
/* 解析yaw (2字节,高字节在前) */
|
||||||
|
int16_t yaw_raw = (int16_t)((msg->data[1] << 8) | msg->data[2]);
|
||||||
|
cmd->gimbal.setpoint.yaw = (float)yaw_raw / AI_CMD_ANGLE_SCALE;
|
||||||
|
|
||||||
|
/* 解析pit (2字节,高字节在前) */
|
||||||
|
int16_t pit_raw = (int16_t)((msg->data[3] << 8) | msg->data[4]);
|
||||||
|
cmd->gimbal.setpoint.pit = (float)pit_raw / AI_CMD_ANGLE_SCALE;
|
||||||
|
|
||||||
|
/* 其他字段根据需要可以初始化为0 */
|
||||||
|
cmd->gimbal.vel.yaw = 0.0f;
|
||||||
|
cmd->gimbal.vel.pit = 0.0f;
|
||||||
|
cmd->gimbal.accl.yaw = 0.0f;
|
||||||
|
cmd->gimbal.accl.pit = 0.0f;
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ void Task_Init(void *argument) {
|
|||||||
task_runtime.thread.ctrl_shoot = osThreadNew(Task_ctrl_shoot, NULL, &attr_ctrl_shoot);
|
task_runtime.thread.ctrl_shoot = osThreadNew(Task_ctrl_shoot, NULL, &attr_ctrl_shoot);
|
||||||
task_runtime.thread.cmd = osThreadNew(Task_cmd, NULL, &attr_cmd);
|
task_runtime.thread.cmd = osThreadNew(Task_cmd, NULL, &attr_cmd);
|
||||||
task_runtime.thread.supercap = osThreadNew(Task_supercap, NULL, &attr_supercap);
|
task_runtime.thread.supercap = osThreadNew(Task_supercap, NULL, &attr_supercap);
|
||||||
task_runtime.thread.ai = osThreadNew(Task_ai, NULL, &attr_ai);
|
// task_runtime.thread.ai = osThreadNew(Task_ai, NULL, &attr_ai);
|
||||||
|
|
||||||
// 创建消息队列
|
// 创建消息队列
|
||||||
/* USER MESSAGE BEGIN */
|
/* USER MESSAGE BEGIN */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user