refactor: 哨兵分支整理目录结构,按功能归类(只搬家,程序不变)
基于战队 main 9de485e。两块板统一改为三层目录,Keil 工程分组与文件夹一一对应:
- App/ 本板业务,按功能分文件夹(system/ cmd/ comm/ referee/,
云台另有 gimbal/ shoot/ vision/,底盘另有 chassis/,含 hlj_pc、supercap)
- Lib/ 与业务无关的通用模块(algorithm/ motor/ imu/ sensor/ dev/),两板逐字节相同
- Bsp/ bsp_can、bsp_usart,不再分 Inc/Src
具体改动:
- 107 个文件全部 git mv(纯重命名,内容不变),文件名不变,#include 不用改
- .uvprojx:Application/Task、Modules、BSP 三个分组换成新分组,登记文件集合不变;
头文件路径换成新目录,CubeMX/第三方目录不动
- .uvoptx 分组同步,文件序号重新连续编号
- 根 README 和两块板 README 的路径、代码地图、模块清单同步更新(补 hlj_pc、supercap)
- 新增 doc/目录整理说明.md(新旧路径对照、验证方法、以后如何跟进步兵更新)
验证(整理前后同一编译器):
- 两块板 Program Size 完全相同
底盘 Code=111184 RO=1956 RW=432 ZI=62720
云台 Code=109876 RO=1960 RW=420 ZI=62764
- .map 符号表(名字/类型/大小/所在 .o)底盘 1155 个、云台 1156 个,逐条一致
未改动:Core/、Drivers/、Middlewares/、USB_DEVICE/、CubeMX 分组名与任务名、module_test/
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9de485e4ef
commit
4b75e4ec6e
115 files changed
+1200
-818
No files matched your search
@@ -0,0 +1,37 @@
|
||||
#ifndef APP_TASKS_H
|
||||
#define APP_TASKS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HB_IMU = 0,//IMU姿态解算任务心跳
|
||||
HB_CMD,//遥控指令综合任务心跳
|
||||
HB_GIMBAL,//云台控制任务心跳
|
||||
HB_SHOOT,//发射机构控制任务心跳
|
||||
HB_CHASSIS,//底盘控制任务心跳
|
||||
HB_CCOMM,//板间通讯发送任务心跳
|
||||
HB_REFEREE,//裁判系统解析任务心跳
|
||||
HB_COUNT,//心跳枚举总数
|
||||
} heartbeat_id_e;//任务心跳编号枚举
|
||||
|
||||
extern volatile uint8_t app_ready;//CAN_Task完成硬件初始化后置1
|
||||
|
||||
void monitor_heartbeat(heartbeat_id_e id);//各任务周期调用向监控任务报活
|
||||
|
||||
void dr16_frame_callback(const uint8_t * frame, uint16_t len);//USART3整帧接收回调(云台板生效)
|
||||
void referee_frame_callback(const uint8_t * frame, uint16_t len);//USART6整帧接收回调
|
||||
|
||||
void CAN_Task(void const * argument);//硬件初始化任务(freertos弱函数强定义)
|
||||
void LED_Task(void const * argument);//心跳监控与看门狗任务(freertos弱函数强定义)
|
||||
void IMU_Task(void const * argument);//姿态解算任务(freertos弱函数强定义)
|
||||
|
||||
void robot_cmd_task(void const * argument);//遥控与键鼠指令综合任务
|
||||
void gimbal_task(void const * argument);//云台双轴控制任务(仅云台板)
|
||||
void shoot_task(void const * argument);//发射机构控制任务(仅云台板)
|
||||
void chassis_task(void const * argument);//底盘运动控制任务(仅底盘板)
|
||||
void c_comm_task(void const * argument);//板间CAN通讯发送任务
|
||||
void referee_task(void const * argument);//裁判系统解析与UI任务
|
||||
void debug_task(void const * argument);//USB CDC串口诊断输出任务
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "app_tasks.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "bsp_can.h"
|
||||
#include "bsp_usart.h"
|
||||
#include "usb_device.h"
|
||||
#include "c_comm.h"
|
||||
#include "led.h"
|
||||
#include "buzzer.h"
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
#include "gimbal.h"
|
||||
#include "shoot.h"
|
||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||
#include "chassis.h"
|
||||
#include "supercap.h"
|
||||
#include "hlj_pc.h"
|
||||
#endif
|
||||
|
||||
volatile uint8_t app_ready = 0;//全部硬件初始化完成标志
|
||||
volatile uint32_t dbg_can_loop = 0;//CAN_Task循环计数(诊断用)
|
||||
|
||||
static uint8_t dr16_rx_buf[36];//DR16单帧18字节,双倍缓冲防粘连
|
||||
static uint8_t referee_rx_buf[128];//裁判系统变长帧接收缓冲
|
||||
|
||||
/*
|
||||
*函数简介:硬件层统一初始化任务
|
||||
*参数说明:FreeRTOS任务参数(未使用)
|
||||
*返回类型:无
|
||||
*备注:依次初始化LED/蜂鸣器/USB/CAN/电机/板间通讯/串口,完成后置app_ready=1
|
||||
*/
|
||||
void CAN_Task(void const * argument)
|
||||
{
|
||||
(void)argument;
|
||||
|
||||
led_init();
|
||||
buzzer_init();
|
||||
led_set_blue(1);//初始化期间蓝灯常亮
|
||||
|
||||
MX_USB_DEVICE_Init();
|
||||
can_start();//CAN过滤器/启动/中断
|
||||
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
gimbal_motor_init();
|
||||
shoot_init();
|
||||
c_comm_init();
|
||||
|
||||
usart3_init(dr16_rx_buf, 36, dr16_frame_callback);//DR16遥控器
|
||||
usart6_init(referee_rx_buf, 128, referee_frame_callback);//图传链路(0x0304)
|
||||
usart1_tx_dma_init();
|
||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||
chassis_motor_init();
|
||||
supercap_init();
|
||||
hlj_pc_init();
|
||||
c_comm_init();
|
||||
|
||||
usart6_init(referee_rx_buf, 128, referee_frame_callback);//裁判系统(0x0201/0x0202)
|
||||
#endif
|
||||
|
||||
app_ready = 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
dbg_can_loop++;
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
*文件名称:debug_task.c
|
||||
*功能描述:USB虚拟串口(CDC)姿态与控制量遥测输出任务(底盘板)
|
||||
*备注:每DEBUG_OUT_PERIOD_MS输出一行欧拉角、姿态健康诊断与底盘控制模式
|
||||
*/
|
||||
#include "debug_task.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "attitude.h"
|
||||
#include "ins.h"
|
||||
#include "bmi088.h"
|
||||
#include "robot_typedef.h"
|
||||
#include "c_comm.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#define DEBUG_ATT_HEALTH 1 //1=输出健康位(cvg/rdy/imu/an/gn),0=仅欧拉角
|
||||
#define DEBUG_ATT_DIAG 1 //1=附加原始陀螺/零偏/采样计数,0=关闭
|
||||
#define DEBUG_CMD_OUT 1 //1=追加底盘控制量/模式,0=不追加
|
||||
#define DEBUG_OUT_PERIOD_MS 100//遥测输出周期(ms)
|
||||
|
||||
#if DEBUG_CMD_OUT
|
||||
/*
|
||||
*函数简介:将底盘控制模式枚举转换为可读字符串
|
||||
*参数说明:m:底盘控制模式枚举
|
||||
*返回类型:const char *:模式名称字符串
|
||||
*备注:仅用于遥测日志格式化
|
||||
*/
|
||||
static const char * cmd_mode_name(chassis_mode_e m)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
case CHASSIS_MODE_OFF: return "OFF";
|
||||
case CHASSIS_MODE_MANUAL: return "MANUAL";
|
||||
case CHASSIS_MODE_FOLLOW: return "FOLLOW";
|
||||
case CHASSIS_MODE_SPIN_SLOW: return "SPIN_SLOW";
|
||||
case CHASSIS_MODE_SPIN_FAST: return "SPIN_FAST";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
*函数简介:USB虚拟串口遥测输出任务
|
||||
*参数说明:argument:FreeRTOS任务参数(未使用)
|
||||
*返回类型:无
|
||||
*备注:无
|
||||
*/
|
||||
void debug_task(void const * argument)
|
||||
{
|
||||
(void)argument;
|
||||
|
||||
char line[448];
|
||||
char tail[112];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const float an = sqrtf(bmi088_accel[0] * bmi088_accel[0] +
|
||||
bmi088_accel[1] * bmi088_accel[1] +
|
||||
bmi088_accel[2] * bmi088_accel[2]);
|
||||
const float gn = sqrtf(bmi088_gyro[0] * bmi088_gyro[0] +
|
||||
bmi088_gyro[1] * bmi088_gyro[1] +
|
||||
bmi088_gyro[2] * bmi088_gyro[2]);
|
||||
|
||||
tail[0] = '\0';
|
||||
#if DEBUG_ATT_HEALTH && DEBUG_ATT_DIAG
|
||||
snprintf(tail, sizeof(tail),
|
||||
" gx=%.4f gy=%.4f gz=%.4f zo=%.4f ck=%u ca=%lu cg=%lu se=%lu st=%u",
|
||||
bmi088_gyro[0], bmi088_gyro[1], bmi088_gyro[2],
|
||||
ins_gyro_z_offset, (unsigned)ins_z_cal_ok,
|
||||
(unsigned long)bmi088_accel_cnt, (unsigned long)bmi088_gyro_cnt,
|
||||
(unsigned long)bmi088_spi_errors, (unsigned)bmi088_spi_state());
|
||||
#endif
|
||||
|
||||
#if DEBUG_CMD_OUT
|
||||
char ctl[192];
|
||||
snprintf(ctl, sizeof(ctl),
|
||||
" mode=%s online=%u vx=%.3f vy=%.3f wz=%.3f spin=%u s2=%u reset=%u",
|
||||
cmd_mode_name(cmd_robot.chassis_mode),
|
||||
(unsigned)cmd_robot.online,
|
||||
cmd_robot.vx, cmd_robot.vy, cmd_robot.wz_manual,
|
||||
(unsigned)ctoc_remote.spin_flag,
|
||||
(unsigned)ctoc_remote.s2,
|
||||
(unsigned)cmd_robot.gimbal_reset);
|
||||
#else
|
||||
const char * ctl = "";
|
||||
#endif
|
||||
|
||||
#if DEBUG_ATT_HEALTH
|
||||
int len = snprintf(line, sizeof(line),
|
||||
"yaw=%.2f pitch=%.2f roll=%.2f cvg=%u rdy=%u imu=%u an=%.2f gn=%.3f%s%s\r\n",
|
||||
att_deg_yaw, att_deg_pitch, att_deg_roll,
|
||||
(unsigned)INS.ConvergeFlag, (unsigned)att_ready,
|
||||
(unsigned)bmi088_online, an, gn, tail, ctl);
|
||||
#else
|
||||
int len = snprintf(line, sizeof(line), "yaw=%.2f pitch=%.2f roll=%.2f%s\r\n",
|
||||
att_deg_yaw, att_deg_pitch, att_deg_roll, ctl);
|
||||
#endif
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
uint16_t tx_len = (len < (int)sizeof(line)) ? (uint16_t)len : (uint16_t)(sizeof(line) - 1U);
|
||||
CDC_Transmit_FS((uint8_t *)line, tx_len);
|
||||
}
|
||||
|
||||
osDelay(DEBUG_OUT_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef DEBUG_TASK_H
|
||||
#define DEBUG_TASK_H
|
||||
|
||||
/*
|
||||
*函数简介:USB虚拟串口(CDC)姿态与控制量遥测输出任务
|
||||
*参数说明:argument:FreeRTOS任务参数(未使用)
|
||||
*返回类型:无
|
||||
*备注:具体输出字段与开关配置见debug_task.c
|
||||
*/
|
||||
extern void debug_task(void const * argument);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
*文件名称:imu_task.c
|
||||
*功能描述:IMU姿态解算与恒温控制任务(两板通用,1kHz,最高优先级)
|
||||
*备注:包含TIM10_CH1加热PWM与PID恒温控制,过温或BMI088离线时强制关闭加热
|
||||
*/
|
||||
#include "app_tasks.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "attitude.h"
|
||||
#include "bmi088.h"
|
||||
#include "ist8310.h"
|
||||
#include "pid.h"
|
||||
#include "tim.h"
|
||||
#include "robot_param.h"
|
||||
|
||||
extern TIM_HandleTypeDef htim10;//TIM10句柄(加热PWM)
|
||||
|
||||
volatile uint32_t dbg_imu_loop = 0;//诊断:IMU任务循环计数
|
||||
|
||||
static PID_PositionTypeDef imu_temp_pid;//IMU恒温位置式PID实例
|
||||
|
||||
/*
|
||||
*函数简介:初始化IMU恒温PID与TIM10_CH1加热PWM(1kHz/千分位)
|
||||
*参数说明:无
|
||||
*返回类型:无
|
||||
*备注:内部函数,由IMU_Task启动阶段调用
|
||||
*/
|
||||
static void imu_temp_ctrl_init(void)
|
||||
{
|
||||
PID_PositionStructureInit(&imu_temp_pid, IMU_TEMPERATURE_TARGET);
|
||||
PID_PositionSetParameter(&imu_temp_pid, IMU_TEMP_KP, IMU_TEMP_KI, IMU_TEMP_KD);
|
||||
PID_PositionSetEkRange(&imu_temp_pid, -1, 1);
|
||||
PID_PositionSetOUTRange(&imu_temp_pid, 0, 100);
|
||||
|
||||
__HAL_TIM_SET_PRESCALER(&htim10, 168 - 1);
|
||||
__HAL_TIM_SET_AUTORELOAD(&htim10, 1000 - 1);
|
||||
__HAL_TIM_SET_COMPARE(&htim10, TIM_CHANNEL_1, 0);
|
||||
HAL_TIM_PWM_Start(&htim10, TIM_CHANNEL_1);
|
||||
}
|
||||
|
||||
/*
|
||||
*函数简介:IMU姿态解算与恒温控制任务(1kHz)
|
||||
*参数说明:argument:FreeRTOS任务参数(未使用)
|
||||
*返回类型:无
|
||||
*备注:任务入口先上报一次心跳,防止传感器初始化校准期间看门狗误判
|
||||
*/
|
||||
void IMU_Task(void const * argument)
|
||||
{
|
||||
(void)argument;
|
||||
|
||||
monitor_heartbeat(HB_IMU);//初始化期间先行报活
|
||||
imu_temp_ctrl_init();
|
||||
attitude_init();//含阻塞式传感器初始化与零偏校准
|
||||
|
||||
TickType_t last_wake = xTaskGetTickCount();//绝对延时基准
|
||||
for (;;)
|
||||
{
|
||||
attitude_update();
|
||||
ist8310_poll();//磁力计200Hz轮询(硬件I2C3,内部5ms分频)
|
||||
|
||||
/* 恒温控制:BMI088离线或过温时禁止加热,防止全功率失控 */
|
||||
if (bmi088_online && bmi088_temperature <= IMU_TEMPERATURE_LIMIT)
|
||||
{
|
||||
PID_PositionCalc(&imu_temp_pid, bmi088_temperature);
|
||||
__HAL_TIM_SET_COMPARE(&htim10, TIM_CHANNEL_1, (uint32_t)(imu_temp_pid.OUT * 10.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
imu_heater_off();
|
||||
}
|
||||
|
||||
monitor_heartbeat(HB_IMU);
|
||||
dbg_imu_loop++;
|
||||
vTaskDelayUntil(&last_wake, pdMS_TO_TICKS(1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
*文件名称:monitor_task.c
|
||||
*功能描述:系统监控任务(LED_Task强定义),负责任务心跳检测、LED/蜂鸣器报警与IWDG看门狗
|
||||
*备注:上电前5s宽限期无条件喂狗,之后仅当全部任务心跳正常时喂狗
|
||||
*/
|
||||
#include "app_tasks.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include "led.h"
|
||||
#include "buzzer.h"
|
||||
#include "dr16.h"
|
||||
#include "referee.h"
|
||||
#include "c_comm.h"
|
||||
#include "robot_param.h"
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
#include "gimbal.h"
|
||||
#include "bmi088.h"
|
||||
#include "ist8310.h"
|
||||
#include "attitude.h"
|
||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||
#include "chassis.h"
|
||||
#endif
|
||||
|
||||
static volatile uint32_t heartbeat_tick[HB_COUNT];//各任务最近一次心跳时间戳(ms)
|
||||
|
||||
/*
|
||||
*函数简介:上报指定任务的心跳时间戳
|
||||
*参数说明:id:任务心跳枚举ID
|
||||
*返回类型:无
|
||||
*备注:由各周期任务在每次循环末尾调用
|
||||
*/
|
||||
void monitor_heartbeat(heartbeat_id_e id)
|
||||
{
|
||||
if ((uint32_t)id < (uint32_t)HB_COUNT)
|
||||
heartbeat_tick[id] = HAL_GetTick();
|
||||
}
|
||||
|
||||
/*
|
||||
*函数简介:检查本板所有受监控任务的心跳是否均在500ms内活跃
|
||||
*参数说明:无
|
||||
*返回类型:uint8_t:1=全部正常,0=存在超时或未启动任务
|
||||
*备注:无
|
||||
*/
|
||||
static uint8_t all_heartbeats_alive(void)
|
||||
{
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
static const heartbeat_id_e expected[] = {HB_IMU, HB_CMD, HB_GIMBAL, HB_SHOOT, HB_CCOMM, HB_REFEREE};
|
||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||
static const heartbeat_id_e expected[] = {HB_IMU, HB_CMD, HB_CHASSIS, HB_CCOMM, HB_REFEREE};
|
||||
#endif
|
||||
uint32_t now = HAL_GetTick();
|
||||
|
||||
for (uint8_t i = 0U; i < (uint8_t)(sizeof(expected) / sizeof(expected[0])); i++)
|
||||
{
|
||||
if (heartbeat_tick[expected[i]] == 0U || (now - heartbeat_tick[expected[i]] > 500U))
|
||||
return 0U;
|
||||
}
|
||||
return 1U;
|
||||
}
|
||||
|
||||
/*
|
||||
*函数简介:判断当前是否满足IWDG喂狗条件
|
||||
*参数说明:无
|
||||
*返回类型:uint8_t:1=允许喂狗,0=禁止喂狗
|
||||
*备注:启动后5s宽限期内无条件喂狗,之后要求全部任务心跳正常
|
||||
*/
|
||||
static uint8_t iwdg_should_feed(void)
|
||||
{
|
||||
if (HAL_GetTick() < 5000U)
|
||||
return 1U;
|
||||
return all_heartbeats_alive();
|
||||
}
|
||||
|
||||
#define LINK_OFFLINE(tick) ((tick) == 0U || (now - (tick) > DEVICE_OFFLINE_TIME_MS))
|
||||
/*
|
||||
*函数简介:查找首个掉线CAN设备的序号
|
||||
*参数说明:无
|
||||
*返回类型:int8_t:设备序号(0起),全部在线返回-1
|
||||
*备注:序号+1对应蜂鸣器报警响声次数
|
||||
*/
|
||||
static int8_t linkcheck_first_offline(void)
|
||||
{
|
||||
uint32_t now = HAL_GetTick();
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
if (LINK_OFFLINE(motor_friction_l.fdb.last_online_tick))
|
||||
return 0;
|
||||
if (LINK_OFFLINE(motor_friction_r.fdb.last_online_tick))
|
||||
return 1;
|
||||
if (LINK_OFFLINE(motor_pitch_gimbal.fdb.last_online_tick))
|
||||
return 2;
|
||||
if (LINK_OFFLINE(motor_yaw_gimbal.fdb.last_online_tick))
|
||||
return 3;
|
||||
#if GIMBAL_RAMMER_INSTALLED
|
||||
if (LINK_OFFLINE(motor_rammer.fdb.last_online_tick))
|
||||
return 4;
|
||||
#endif
|
||||
if (LINK_OFFLINE(ctoc_reply_last_tick))
|
||||
return 5;
|
||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||
if (LINK_OFFLINE(motor_wheel_rf.fdb.last_online_tick))
|
||||
return 0;
|
||||
if (LINK_OFFLINE(motor_wheel_lf.fdb.last_online_tick))
|
||||
return 1;
|
||||
if (LINK_OFFLINE(motor_wheel_lr.fdb.last_online_tick))
|
||||
return 2;
|
||||
if (LINK_OFFLINE(motor_wheel_rr.fdb.last_online_tick))
|
||||
return 3;
|
||||
if (ctoc_remote.last_tick == 0U || (now - ctoc_remote.last_tick > CTOC_OFFLINE_TIME_MS))
|
||||
return 4;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
#undef LINK_OFFLINE
|
||||
|
||||
/*
|
||||
*函数简介:直接写寄存器启动独立看门狗IWDG(约2.5s溢出)
|
||||
*参数说明:无
|
||||
*返回类型:无
|
||||
*备注:PR=4对应64分频(500Hz),RLR=1250对应约2.5s
|
||||
*/
|
||||
static void iwdg_init(void)
|
||||
{
|
||||
IWDG->KR = 0x5555U;//解除写保护
|
||||
IWDG->PR = 4U; //64分频
|
||||
IWDG->RLR = 1250U; //重装载值
|
||||
IWDG->KR = 0xAAAAU;//重装载
|
||||
IWDG->KR = 0xCCCCU;//启动看门狗
|
||||
}
|
||||
|
||||
/*
|
||||
*函数简介:更新CAN掉线报警与遥控器上线提示音
|
||||
*参数说明:can_alarm:CAN设备掉线标志(1=存在掉线)
|
||||
*参数说明:counter:100ms节拍计数器(1~100)
|
||||
*返回类型:无
|
||||
*备注:内部函数,由LED_Task周期调用
|
||||
*/
|
||||
static void monitor_update_can_alarm(uint8_t can_alarm, uint8_t counter)
|
||||
{
|
||||
if (can_alarm)
|
||||
{
|
||||
led_set_red(1);
|
||||
int8_t first_offline = linkcheck_first_offline();
|
||||
|
||||
#if DEBUG_BUZZER_MELODY
|
||||
static uint16_t melody_step = 0U;
|
||||
(void)first_offline;
|
||||
buzzer_play_melody(melody_step++);
|
||||
#else
|
||||
if (first_offline >= 0)
|
||||
{
|
||||
uint8_t n = (uint8_t)(first_offline + 1);
|
||||
uint8_t w = (uint8_t)(counter % 20U);//2s周期窗口
|
||||
if ((w / 2U) < n && (w % 2U) == 0U)
|
||||
buzzer_on(BUZZER_L1);
|
||||
else
|
||||
buzzer_off();
|
||||
}
|
||||
else
|
||||
{
|
||||
buzzer_off();
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
static uint8_t prev_remote_online = 0U;
|
||||
static uint8_t chime_step = 0U;
|
||||
uint8_t remote_online = (uint8_t)!dr16_offline();
|
||||
|
||||
if (remote_online && !prev_remote_online)
|
||||
chime_step = 4U;//遥控器上线瞬间触发两声上扬提示音
|
||||
prev_remote_online = remote_online;
|
||||
|
||||
if (chime_step > 0U)
|
||||
{
|
||||
if (chime_step == 4U)
|
||||
buzzer_on(BUZZER_M3);
|
||||
else if (chime_step == 2U)
|
||||
buzzer_on(BUZZER_H3);
|
||||
else
|
||||
buzzer_off();
|
||||
chime_step--;
|
||||
}
|
||||
else
|
||||
{
|
||||
buzzer_off();
|
||||
}
|
||||
#else
|
||||
(void)counter;
|
||||
buzzer_off();
|
||||
led_set_red(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
/*
|
||||
*函数简介:更新云台板红绿报警灯语(遥控器掉线/图传超时/IMU过温与传感器故障)
|
||||
*参数说明:counter:100ms节拍计数器(1~100)
|
||||
*参数说明:can_alarm:CAN设备掉线标志
|
||||
*参数说明:imu_overheat:IMU过温锁存标志指针
|
||||
*返回类型:无
|
||||
*备注:内部函数,仅云台板编译
|
||||
*/
|
||||
static void monitor_update_gimbal_leds(uint8_t counter, uint8_t can_alarm, uint8_t * imu_overheat)
|
||||
{
|
||||
uint8_t phase = (uint8_t)(counter % 20U);
|
||||
|
||||
/* 遥控器掉线:1s内红灯连闪两下 */
|
||||
if (dr16_offline())
|
||||
{
|
||||
if (phase == 1U || phase == 13U)
|
||||
led_set_red(1);
|
||||
else if (phase == 5U || phase == 17U)
|
||||
led_set_red(0);
|
||||
}
|
||||
else if (!can_alarm)
|
||||
{
|
||||
led_set_red(0);
|
||||
}
|
||||
|
||||
/* 图传链路超时:绿灯1s周期闪烁 */
|
||||
if (referee.link_status &&
|
||||
(HAL_GetTick() - referee.last_update_tick > DEVICE_OFFLINE_TIME_MS * 10U))
|
||||
{
|
||||
led_set_green(phase < 10U ? 1U : 0U);
|
||||
}
|
||||
|
||||
/* IMU过温:绿灯常亮并关闭加热 */
|
||||
if (bmi088_temperature > IMU_TEMPERATURE_LIMIT)
|
||||
{
|
||||
if (imu_overheat != NULL)
|
||||
*imu_overheat = 1U;
|
||||
imu_heater_off();
|
||||
}
|
||||
if (imu_overheat != NULL && *imu_overheat)
|
||||
led_set_green(1);
|
||||
|
||||
/* 传感器检测失败灯语 */
|
||||
if (!bmi088_online && !ist8310_online)
|
||||
{
|
||||
led_set_green(1);
|
||||
}
|
||||
else if (!bmi088_online)
|
||||
{
|
||||
if (phase == 1U || phase == 13U)
|
||||
led_set_green(1);
|
||||
else if (phase == 5U || phase == 17U)
|
||||
led_set_green(0);
|
||||
}
|
||||
else if (!ist8310_online)
|
||||
{
|
||||
led_set_green(phase < 10U ? 1U : 0U);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
*函数简介:系统监控任务(100ms,LED_Task强定义)
|
||||
*参数说明:argument:FreeRTOS任务参数(未使用)
|
||||
*返回类型:无
|
||||
*备注:负责看门狗喂狗、设备掉线报警与健康心跳灯语
|
||||
*/
|
||||
void LED_Task(void const * argument)
|
||||
{
|
||||
(void)argument;
|
||||
|
||||
uint8_t counter = 0U;//100ms周期计数(1~100)
|
||||
uint8_t imu_overheat = 0U;//IMU过温锁存标志
|
||||
uint8_t can_alarm = 0U;//CAN掉线报警标志
|
||||
uint8_t first_ready = 1U;//初始化完成后首拍清灯标志
|
||||
|
||||
iwdg_init();//入口立即启动看门狗
|
||||
|
||||
while (!app_ready)
|
||||
{
|
||||
IWDG->KR = 0xAAAAU;//初始化阶段保持喂狗
|
||||
osDelay(10);
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
counter++;
|
||||
if (counter > 100U)
|
||||
counter = 1U;
|
||||
|
||||
if (first_ready)
|
||||
{
|
||||
first_ready = 0U;
|
||||
led_set_all_off();//熄灭初始化蓝灯,交由报警逻辑接管
|
||||
}
|
||||
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
can_alarm = gimbal_motor_offline();
|
||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||
can_alarm = chassis_motor_offline();
|
||||
#endif
|
||||
|
||||
monitor_update_can_alarm(can_alarm, counter);
|
||||
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
monitor_update_gimbal_leds(counter, can_alarm, &imu_overheat);
|
||||
#elif defined(ROBOT_TYPE_CHASSIS)
|
||||
led_set_green(0);
|
||||
#endif
|
||||
|
||||
/* 健康心跳:无报警时蓝灯每2s闪100ms */
|
||||
uint8_t healthy = (uint8_t)(!can_alarm && !imu_overheat);
|
||||
#if defined(ROBOT_TYPE_GIMBAL)
|
||||
healthy = (uint8_t)(healthy && bmi088_online && ist8310_online);
|
||||
#endif
|
||||
if (healthy)
|
||||
{
|
||||
if (counter % 20U == 10U)
|
||||
led_set_blue(1);
|
||||
else if (counter % 20U == 11U)
|
||||
led_set_blue(0);
|
||||
}
|
||||
|
||||
if (iwdg_should_feed())
|
||||
IWDG->KR = 0xAAAAU;
|
||||
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user