From f37d813bcdee30f0933814829b195146b7c33024 Mon Sep 17 00:00:00 2001 From: NeoZng Date: Mon, 2 Jan 2023 23:50:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=A2=9D=E5=A4=96?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chassis/chassis.h | 2 +- application/cmd/robot_cmd.c | 2 +- application/cmd/robot_cmd.h | 8 ++++++++ application/gimbal/gimbal.h | 2 +- application/robot.c | 1 + application/robot.h | 10 ++++++++++ application/robot_def.h | 5 +++-- application/shoot/shoot.c | 2 +- application/shoot/shoot.h | 2 +- bsp/bsp_init.c | 2 +- bsp/can/bsp_can.c | 18 +++++++++--------- 11 files changed, 37 insertions(+), 17 deletions(-) diff --git a/application/chassis/chassis.h b/application/chassis/chassis.h index ea8bd50..ea7c0b4 100644 --- a/application/chassis/chassis.h +++ b/application/chassis/chassis.h @@ -2,7 +2,7 @@ #define CHASSIS_H /** - * @brief 底盘应用初始化,请在开启rtos之前调用 + * @brief 底盘应用初始化,请在开启rtos之前调用(目前会被RobotInit()调用) * */ void ChassisInit(); diff --git a/application/cmd/robot_cmd.c b/application/cmd/robot_cmd.c index 6575688..e10d066 100644 --- a/application/cmd/robot_cmd.c +++ b/application/cmd/robot_cmd.c @@ -134,7 +134,7 @@ static void RemoteControlSet() ; // 弹舱舵机控制,待添加servo_motor模块,关闭 // 摩擦轮控制,拨轮向上打为负,向下为正 - if (rc_data[TEMP].rc.dial < -100) + if (rc_data[TEMP].rc.dial < -100) // 向上超过100,打开摩擦轮 shoot_cmd_send.friction_mode = FRICTION_ON; else shoot_cmd_send.friction_mode = FRICTION_OFF; diff --git a/application/cmd/robot_cmd.h b/application/cmd/robot_cmd.h index b63750f..7e787e8 100644 --- a/application/cmd/robot_cmd.h +++ b/application/cmd/robot_cmd.h @@ -1,8 +1,16 @@ #ifndef GIMBAL_CMD_H #define GIMBAL_CMD_H +/** + * @brief 机器人核心控制任务初始化,会被RobotInit()调用 + * + */ void RobotCMDInit(); +/** + * @brief 机器人核心控制任务,200Hz频率运行(必须高于视觉发送频率) + * + */ void RobotCMDTask(); #endif // !GIMBAL_CMD_H \ No newline at end of file diff --git a/application/gimbal/gimbal.h b/application/gimbal/gimbal.h index 4e872ee..0bcc37e 100644 --- a/application/gimbal/gimbal.h +++ b/application/gimbal/gimbal.h @@ -2,7 +2,7 @@ #define GIMBAL_H /** - * @brief 初始化云台 + * @brief 初始化云台,会被RobotInit()调用 * */ void GimbalInit(); diff --git a/application/robot.c b/application/robot.c index 4469f11..9020d70 100644 --- a/application/robot.c +++ b/application/robot.c @@ -5,6 +5,7 @@ #if defined(ONE_BOARD) || defined(CHASSIS_BOARD) #include "chassis.h" #endif + #if defined(ONE_BOARD) || defined(GIMBAL_BOARD) #include "gimbal.h" #include "shoot.h" diff --git a/application/robot.h b/application/robot.h index 07e78ea..36f9809 100644 --- a/application/robot.h +++ b/application/robot.h @@ -1,8 +1,18 @@ #ifndef ROBOT_H #define ROBOT_H +/* Robot利用robot_def.h中的宏对不同的机器人进行了大量的兼容,同时兼容了两个开发板(云台板和底盘板)的配置 */ + +/** + * @brief 机器人初始化,请在开启rtos之前调用.这也是唯一需要放入main函数的函数 + * + */ void RobotInit(); +/** + * @brief 机器人任务,放入实时系统以一定频率运行,内部会调用各个应用的任务 + * + */ void RobotTask(); #endif \ No newline at end of file diff --git a/application/robot_def.h b/application/robot_def.h index 06e1e8f..fd54a12 100644 --- a/application/robot_def.h +++ b/application/robot_def.h @@ -21,6 +21,7 @@ // #define CHASSIS_BOARD //底盘板 // #define GIMBAL_BOARD //云台板 +// @todo: 增加机器人类型定义,后续是否要兼容所有机器人?(只兼容步兵英雄哨兵似乎就够了) /* 机器人类型定义 */ // #define ROBOT_HERO 1 // 英雄机器人 // #define ROBOT_ENINEER 2 // 工程机器人 @@ -46,11 +47,11 @@ #define RADIUS_WHEEL 60 // 轮子半径 #define REDUCTION_RATIO_WHEEL 19.0f // 电机减速比,因为编码器量测的是转子的速度而不是输出轴的速度故需进行转换 -// 检查是否出现定义冲突 +// 检查是否出现定义冲突,只允许一个开发板定义存在,否则编译会自动报错 #if (defined(ONE_BOARD) && defined(CHASSIS_BOARD)) || \ (defined(ONE_BOARD) && defined(GIMBAL_BOARD)) || \ (defined(CHASSIS_BOARD) && defined(GIMBAL_BOARD)) -#error Conflict board definition! You can only define one type. +#error Conflict board definition! You can only define one board type. #endif #pragma pack(1) // 压缩结构体,取消字节对齐 diff --git a/application/shoot/shoot.c b/application/shoot/shoot.c index 218fe43..bea0812 100644 --- a/application/shoot/shoot.c +++ b/application/shoot/shoot.c @@ -205,7 +205,7 @@ void ShootTask() DJIMotorSetRef(friction_l, 0); DJIMotorSetRef(friction_r, 0); break; - default: // 当前为了调试设定的4000,因为还没有加入裁判系统无法读取弹速.后续修改为while(1);表明模式错误 + default: // 当前为了调试设定的默认值4000,因为还没有加入裁判系统无法读取弹速. DJIMotorSetRef(friction_l, 4000); DJIMotorSetRef(friction_r, 4000); break; diff --git a/application/shoot/shoot.h b/application/shoot/shoot.h index 4eef31c..45701c3 100644 --- a/application/shoot/shoot.h +++ b/application/shoot/shoot.h @@ -2,7 +2,7 @@ #define SHOOT_H /** - * @brief 发射初始化 + * @brief 发射初始化,会被RobotInit()调用 * */ void ShootInit(); diff --git a/bsp/bsp_init.c b/bsp/bsp_init.c index 4e60b89..134dbe4 100644 --- a/bsp/bsp_init.c +++ b/bsp/bsp_init.c @@ -11,7 +11,7 @@ void BSPInit() DWT_Init(168); BSPLogInit(); - // 下面都是待删除的,将在实现了module之后移动到app层 + // legacy support,待删除,将在实现了led/tempctrl/buzzer的module之后移动到app层 LEDInit(); IMUTempInit(); BuzzerInit(); diff --git a/bsp/can/bsp_can.c b/bsp/can/bsp_can.c index 68869d7..85a4f3a 100644 --- a/bsp/can/bsp_can.c +++ b/bsp/can/bsp_can.c @@ -26,16 +26,16 @@ static uint8_t idx; // 全局CAN实例索引,每次有新的模块注册会自 static void CANAddFilter(CANInstance *_instance) { CAN_FilterTypeDef can_filter_conf; - static uint8_t can1_filter_idx = 0, can2_filter_idx = 14; - - can_filter_conf.FilterMode = CAN_FILTERMODE_IDLIST; - can_filter_conf.FilterScale = CAN_FILTERSCALE_16BIT; - can_filter_conf.FilterFIFOAssignment = (_instance->tx_id & 1) ? CAN_RX_FIFO0 : CAN_RX_FIFO1; - can_filter_conf.SlaveStartFilterBank = 14; - can_filter_conf.FilterIdLow = _instance->rx_id << 5; - can_filter_conf.FilterBank = _instance->can_handle == &hcan1 ? (can1_filter_idx++) : (can2_filter_idx++); - can_filter_conf.FilterActivation = CAN_FILTER_ENABLE; + static uint8_t can1_filter_idx = 0, can2_filter_idx = 14; // 0-13给can1用,14-27给can2用 + can_filter_conf.FilterMode = CAN_FILTERMODE_IDLIST; //使用id list模式,即只有将rxid添加到过滤器中才会接收到,其他报文会被过滤 + can_filter_conf.FilterScale = CAN_FILTERSCALE_16BIT; //使用16位id模式,即只有低16位有效 + can_filter_conf.FilterFIFOAssignment = (_instance->tx_id & 1) ? CAN_RX_FIFO0 : CAN_RX_FIFO1; //奇数id的模块会被分配到FIFO0,偶数id的模块会被分配到FIFO1 + can_filter_conf.SlaveStartFilterBank = 14; // 从第14个过滤器开始配置从机过滤器(在STM32的BxCAN控制器中CAN2是CAN1的从机) + can_filter_conf.FilterIdLow = _instance->rx_id << 5; // 过滤器寄存器的低16位,因为使用STDID,所以只有低11位有效,高5位要填0 + can_filter_conf.FilterBank = _instance->can_handle == &hcan1 ? (can1_filter_idx++) : (can2_filter_idx++); // 根据can_handle判断是CAN1还是CAN2,然后自增 + can_filter_conf.FilterActivation = CAN_FILTER_ENABLE; // 启用过滤器 + HAL_CAN_ConfigFilter(_instance->can_handle, &can_filter_conf); }