111 lines
3.8 KiB
C
111 lines
3.8 KiB
C
/*
|
|
*文件名称: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);
|
|
}
|
|
}
|