增加调试功能,以及yaw补偿

This commit is contained in:
lyf committed 2026-11-18 16:05:46 +08:00
1 parent 267a659242
commit 957c535bda
257 files changed
+239436 -692

No files matched your search

@@ -0,0 +1,40 @@
/* =============================================================================
* app_tasks.h - module_test 任务公共声明(精简版)
*
* 本工程只做"单电机台架测试 + 算法验证":
* 已移除:板间通讯(CToC)、裁判系统、云台/发射/底盘整车任务、IMU/姿态解算。
* 保留:CAN 电机驱动、DT7 遥控、PID/前馈、功率估计模型、USB CDC FireWater。
*
* 任务清单:
* CAN_Task 硬件初始化(CAN/USB/串口/被测电机注册)
* module_test_task 2ms 单电机测试主循环(读遥控/算电流/下发)
* debug_task 200Hz USB CDC FireWater 4 通道输出
* LED_Task 任务心跳 + IWDG 看门狗 + LED/蜂鸣报警
* ========================================================================== */
#ifndef APP_TASKS_H
#define APP_TASKS_H
#include <stdint.h>
/* 任务心跳编号(monitor_task 检查各任务存活) */
typedef enum
{
HB_TEST = 0, /* 单电机测试主循环(2ms) */
HB_DEBUG, /* FireWater 输出(200Hz) */
HB_COUNT,
} heartbeat_id_e;
extern volatile uint8_t app_ready; /* CAN_Task 完成硬件初始化后置 1 */
/* 各任务在循环内调用,向监控任务报活 */
extern void monitor_heartbeat(heartbeat_id_e id);
/* freertos.c 弱函数的强定义 */
extern void CAN_Task(void const * argument);
extern void LED_Task(void const * argument);
/* 新建任务 */
extern void module_test_task(void const * argument); /* 2ms:单电机测试主循环 */
extern void debug_task(void const * argument); /* USB CDC:FireWater 输出 */
#endif
@@ -0,0 +1,10 @@
/* debug_task.h - USB 虚拟串口(CDC)FireWater 输出任务声明 */
#ifndef DEBUG_TASK_H
#define DEBUG_TASK_H
/* debug_task:200Hz 输出 4 通道 CSV(VOFA FireWater 协议)
* mt_power_est, mt_target_out, 实测速度(m/s 或 RPM), mt_current_cnt(反馈电流编码值)
* 详见 debug_task.c 文件头 */
extern void debug_task(void const * argument);
#endif
@@ -0,0 +1,44 @@
/* =============================================================================
* can_task.c - CAN_Task:全部硬件层初始化(精简版)
*
* 顺序:led_init -> buzzer_init -> MX_USB_DEVICE_Init -> can_start
* -> module_test_init(注册被测电机) -> usart3_init(DR16)
* -> app_ready=1(其余任务在此之前的 while 等待)
*
* 已移除:板间通讯(c_comm)、裁判系统(USART6)、视觉串口(USART1)、
* 云台/发射/底盘电机初始化。
* ========================================================================== */
#include "app_tasks.h"
#include "cmsis_os.h"
#include "bsp_can.h"
#include "bsp_usart.h"
#include "usb_device.h"
#include "led.h"
#include "buzzer.h"
#include "dr16.h"
#include "module_test.h"
volatile uint8_t app_ready = 0;
static uint8_t dr16_rx_buf[36]; /* DR16 单帧 18 字节,缓冲放大一倍防止帧粘连 */
void CAN_Task(void const * argument)
{
(void)argument;
led_init();
buzzer_init();
led_set_blue(1); /* 初始化期间蓝灯常亮 */
MX_USB_DEVICE_Init();
can_start(); /* CAN 过滤器/启动/中断 */
module_test_init(); /* 只注册被测电机(3508/2006/6020 任选) */
usart3_init(dr16_rx_buf, 36, dr16_frame_callback); /* DT7 遥控器 */
app_ready = 1;
for (;;)
osDelay(1000);
}
@@ -0,0 +1,57 @@
/* =============================================================================
* debug_task.c - USB 虚拟串口(CDC)FireWater 输出(精简版)
*
* 200Hz 输出 4 通道 CSV(逗号分隔 + 换行,VOFA+ 选 FireWater 协议):
* 1) mt_power_est 功率模型估计输入功率 (W,带符号;回馈时为负)
* 2) mt_target_out 目标值(正弦/速度模式=线速度 m/s;电流模式=目标电流 A;
* 拨弹/摩擦轮模式=目标转速 RPM)
* 3) 实测速度 默认线速度 m/s(MT_SPEED_OUT_MPS=0 时为转子转速 RPM;
* 摩擦轮模式固定为转子转速 RPM)
* 4) 电机反馈转矩电流编码值(counts,±16384 ↔ 满量程;反馈值,未滤波)
*
* 其余诊断量不占通道,用调试器 Watch:
* mt_current_a / mt_power_mech / mt_power_loss
* mt_pid_out / mt_ff_cmd / mt_cmd_limited / mt_ref_alpha
* mt_state(0=IDLE 1=RUN 2=PROTECT) / mt_fault(0无 1电流硬限 2堵转 3过温 4遥控离线)
*
* MT_POWER_OUT=0 时退回旧的 4 通道(实测电流/实测转速/下发指令/温度)。
* 已移除:姿态/IMU/控制量汇总等整车遥测。
* ========================================================================== */
#include "app_tasks.h"
#include "cmsis_os.h"
#include "usbd_cdc_if.h"
#include "module_test.h"
#include <stdio.h>
void debug_task(void const * argument)
{
char line[96];
(void)argument;
while (!app_ready)
osDelay(10);
for (;;)
{
#if MT_POWER_OUT
/* 通道3 实测速度:默认 m/s(与 MT_TARGET_MPS_OUT 同口径),可切换为转子 RPM;
* 摩擦轮模式固定 RPM(摩擦轮不是麦轮,m/s 换算无意义,与通道2 同口径) */
#if (MT_MODE == MT_MODE_FRICTION)
const float speed_out = mt_speed_rpm;
#else
const float speed_out = MT_SPEED_OUT_MPS ? mt_speed_mps : mt_speed_rpm;
#endif
int len = snprintf(line, sizeof(line), "%.2f,%.3f,%.2f,%d\n",
mt_power_est, mt_target_out, speed_out, (int)mt_current_cnt);
#else
int len = snprintf(line, sizeof(line), "%.3f,%.1f,%.1f,%.1f\n",
mt_current_a, mt_speed_rpm, mt_out_cmd, mt_temperature);
#endif
if (len > 0)
CDC_Transmit_FS((uint8_t *)line, (uint16_t)len);
monitor_heartbeat(HB_DEBUG);
osDelay(MT_DEBUG_PERIOD_MS);
}
}
@@ -0,0 +1,33 @@
/* =============================================================================
* module_test_task.c - 单电机测试主循环(2ms)
*
* 只做三件事:
* 1) module_test_step():读 DT7、算目标/前馈/PID/限幅/保护、正算功率;
* 2) module_test_send():按原工程报文格式下发电流帧(只占用被测电机槽位);
* 3) 报活给监控任务。
*
* 控制周期 2ms 与 PID/前馈/功率预算的 dt 假设严格对应,勿单独改周期。
* ========================================================================== */
#include "app_tasks.h"
#include "cmsis_os.h"
#include "FreeRTOS.h"
#include "task.h"
#include "module_test.h"
void module_test_task(void const * argument)
{
TickType_t last_wake = xTaskGetTickCount();
(void)argument;
while (!app_ready)
osDelay(2);
for (;;)
{
module_test_step();
module_test_send();
monitor_heartbeat(HB_TEST);
vTaskDelayUntil(&last_wake, pdMS_TO_TICKS(2));
}
}
@@ -0,0 +1,121 @@
/* =============================================================================
* monitor_task.c - LED_Task 强定义:任务心跳 + LED/蜂鸣报警 + IWDG 看门狗
*
* 精简版(原车载监控已移除 CToC/裁判/IMU/云台检查):
* - 只检查两个任务心跳:HB_TEST(2ms 测试循环)、HB_DEBUG(FireWater 输出);
* - 报警源只有两个:被测电机掉线、DT7 遥控掉线;
* - IWDG 约 2.5s:上电 5s 宽限期无条件喂狗,之后仅心跳全正常才喂。
*
* 灯语:
* 蓝灯每 2s 短闪 = 系统健康
* 红灯常亮 + 每 2s 响 1 声 = 被测电机掉线(查 CAN 线/电调 ID/波特率)
* 红灯 1s 双闪 = DT7 遥控掉线
* ========================================================================== */
#include "app_tasks.h"
#include "cmsis_os.h"
#include "stm32f4xx_hal.h"
#include "led.h"
#include "buzzer.h"
#include "dr16.h"
#include "module_test.h"
#define HEARTBEAT_TIMEOUT_MS 500
static volatile uint32_t heartbeat_tick[HB_COUNT];
void monitor_heartbeat(heartbeat_id_e id)
{
if ((uint32_t)id < (uint32_t)HB_COUNT)
heartbeat_tick[id] = HAL_GetTick();
}
static uint8_t all_heartbeats_alive(void)
{
static const heartbeat_id_e expected[] = {HB_TEST, HB_DEBUG};
uint32_t now = HAL_GetTick();
for (uint32_t i = 0; i < sizeof(expected) / sizeof(expected[0]); i++)
{
if (heartbeat_tick[expected[i]] == 0 ||
now - heartbeat_tick[expected[i]] > HEARTBEAT_TIMEOUT_MS)
return 0;
}
return 1;
}
/* IWDG:直接写寄存器(HAL IWDG 模块未在 CubeMX 中启用)
* PR=4 -> LSI 32kHz / 64 分频 = 500Hz,重装载 1250 -> 约 2.5s 溢出 */
static void iwdg_init(void)
{
IWDG->KR = 0x5555; /* 解除写保护 */
IWDG->PR = 4;
IWDG->RLR = 1250;
IWDG->KR = 0xAAAA; /* 重装载 */
IWDG->KR = 0xCCCC; /* 启动 */
}
void LED_Task(void const * argument)
{
uint8_t tick_10ms = 0;
uint8_t first_ready = 1;
(void)argument;
iwdg_init();
/* 等待硬件初始化完成(CAN_Task 的蓝灯常亮即初始化中) */
while (!app_ready)
{
IWDG->KR = 0xAAAA;
osDelay(10);
}
for (;;)
{
const uint8_t motor_offline = (mt_motor_online() == 0);
const uint8_t rc_offline = (dr16_status == 0) || dr16_offline();
if (first_ready)
{
first_ready = 0;
led_set_all_off();
}
tick_10ms = (tick_10ms >= 199) ? 0 : (uint8_t)(tick_10ms + 1);
if (motor_offline)
{
/* 被测电机掉线:红灯常亮 + 2s 响 1 声 */
led_set_blue(0);
led_set_green(0);
led_set_red(1);
if (tick_10ms == 0)
buzzer_on(BUZZER_H3);
else if (tick_10ms == 5)
buzzer_off();
}
else if (rc_offline)
{
/* 遥控掉线:红灯 1s 双闪 */
led_set_blue(0);
led_set_green(0);
led_set_red((uint8_t)((tick_10ms % 50) < 10));
buzzer_off();
}
else
{
/* 健康:蓝灯每 2s 短闪 30ms */
led_set_red(0);
led_set_green(0);
led_set_blue((uint8_t)(tick_10ms < 3));
if (tick_10ms == 3)
buzzer_off();
}
/* 喂狗:上电 5s 宽限;之后必须心跳正常 */
if (HAL_GetTick() < 5000U || all_heartbeats_alive())
IWDG->KR = 0xAAAA;
osDelay(10);
}
}
+26
View File
@@ -0,0 +1,26 @@
/* =============================================================================
* robot_param.h - module_test 参数汇总入口
*
* module_test 同时验证底盘(3508)与云台/拨弹(2006/6020)相关算法,因此这里把
* 两块板各自的 robot_param.h 汇总进来:
*
* ../refs/chassis/Application/robot_param.h 底盘专属(MECANUM/CHASSIS/功率 + 公共段)
* ../refs/gimbal/Application/robot_param.h 云台专属(GIMBAL/PITCH/YAW/拨弹 + 公共段)
*
* refs/chassis、refs/gimbal 是 module_test 内部的 ASCII junction(见
* tools/link_algo.ps1),用来避开 µVision 对中文 include 路径支持不稳定的问题,
* 同时保持 Simba-OmniInfantry 根目录只有 底盘/云台/module_test 三个源码目录。
*
* 两份板级头都各自内联了"公共参数段"(CToC ID/掉线/IMU温控等,数值相同),
* 保证每块板单独编译时自包含;tools/check_param_common.py 用于检查两段是否一致。
*
* 台架自身的测试参数(模式、正弦、前馈、滤波等)不放在这里,
* 仍集中在 modules/test/module_test.h,避免污染整车参数。
* ========================================================================== */
#ifndef ROBOT_PARAM_H
#define ROBOT_PARAM_H
#include "../refs/chassis/Application/robot_param.h"
#include "../refs/gimbal/Application/robot_param.h"
#endif /* ROBOT_PARAM_H */