代码风格更新以及加入超电的对接

This commit is contained in:
lyf committed 2026-11-25 17:24:46 +08:00
1 parent 957c535bda
commit 9de485e4ef
117 files changed
+9046 -6457

No files matched your search

+354 -31
View File
@@ -18,6 +18,7 @@
* -> 估计功率随工况变化,可与外接功率计/电源读数对照。
* ==========================================================================*/
#include "module_test.h"
#include "bsp_can.h"
#include "dji_motor.h"
#include "dr16.h"
#include "pid.h"
@@ -31,10 +32,6 @@
#define MT_SINE_TWO_PI 6.28318530718f
#define MT_SINE_STEP_S 0.002f
/* ---- 被测电机实例(独立于原工程,避免与 gimbal_motor_init 抢同 ID 回调) ---- */
static dji_motor_t mt_motor;
static PID_PositionTypeDef mt_speed_pid;
volatile float mt_current_a = 0.0f;
volatile float mt_speed_rpm = 0.0f;
volatile float mt_out_cmd = 0.0f;
@@ -53,6 +50,352 @@ volatile float mt_cmd_limited = 0.0f; /* 限幅后总指令(counts) */
volatile float mt_ref_alpha = 0.0f; /* 整形后参考加速度(rad/s^2) */
volatile uint8_t mt_state = 0;
volatile uint8_t mt_fault = 0;
volatile uint32_t mt_supercap_tx_cnt = 0;
volatile uint32_t mt_supercap_tx_err = 0;
volatile uint32_t mt_supercap_rx_cnt = 0;
volatile uint8_t mt_supercap_ready = 0;
volatile uint8_t mt_supercap_cap_state = 0;
volatile uint8_t mt_supercap_energy = 0;
volatile uint8_t mt_supercap_enable = 0;
volatile uint8_t mt_supercap_power_w = MT_SUPERCAP_BASE_POWER_W;
#if (MT_MODE == MT_MODE_SUPERCAP)
/* ---- 超级电容 CAN 通信测试(固定 CAN1,标准帧 0x001) ----
* 默认初始 -> DATA[0]=0 不使能,DATA[2]=MT_SUPERCAP_BASE_POWER_W (30W)
* S1 上(1) -> DATA[0]=1 使能;中(3)/下(2)/遥控离线 -> DATA[0]=0 不使能
* 左摇杆 rc_l_UD 上推(>1050)按比例直接映射加功率(1050..1684 -> 0..+20W),
* 总功率上限硬限幅不超过 MT_SUPERCAP_MAX_POWER_W (90W) */
static volatile uint32_t mt_supercap_last_tick = 0;
static uint32_t mt_supercap_tx_div = 0;
static hcan_t * mt_supercap_hcan(void)
{
return &hcan1; /* 超电固定走 CAN1 */
}
/* 按 DT7 S1(使能)与左摇杆 rc_l_UD(直接映射加功率)刷新下发值 */
static void mt_supercap_update_cmd(void)
{
uint32_t power_w = MT_SUPERCAP_BASE_POWER_W;
if (dr16_status == 0 || dr16_offline())
{
mt_supercap_enable = 0U;
mt_supercap_power_w = MT_SUPERCAP_BASE_POWER_W;
return;
}
mt_supercap_enable = (dr16.s1 == 1U) ? 1U : 0U;
if (dr16.rc_l_UD > 1050U)
{
float norm = ((float)dr16.rc_l_UD - 1050.0f) / 634.0f;
if (norm > 1.0f)
norm = 1.0f;
power_w += (uint32_t)(norm * (float)MT_SUPERCAP_STICK_DELTA_W + 0.5f);
}
if (power_w > MT_SUPERCAP_MAX_POWER_W)
power_w = MT_SUPERCAP_MAX_POWER_W;
mt_supercap_power_w = (uint8_t)power_w;
}
static void mt_supercap_rx_callback(uint32_t std_id, const uint8_t rx_data[8], uint32_t dlc)
{
(void)std_id;
mt_supercap_last_tick = HAL_GetTick();
mt_supercap_rx_cnt++;
if (dlc >= 3U)
{
mt_supercap_ready = rx_data[0];
mt_supercap_cap_state = rx_data[1];
mt_supercap_energy = rx_data[2];
}
}
void module_test_init(void)
{
mt_supercap_tx_cnt = 0;
mt_supercap_tx_err = 0;
mt_supercap_rx_cnt = 0;
mt_supercap_ready = 0;
mt_supercap_cap_state = 0;
mt_supercap_energy = 0;
mt_supercap_last_tick = 0;
mt_supercap_tx_div = 0;
mt_supercap_enable = 0;
mt_supercap_power_w = MT_SUPERCAP_BASE_POWER_W;
mt_state = 0;
mt_fault = 0;
/* 注册超电反馈帧 0x100,便于确认超电板在线响应 */
can_rx_register(mt_supercap_hcan(), MT_SUPERCAP_RX_ID, mt_supercap_rx_callback);
}
void module_test_step(void)
{
mt_supercap_update_cmd();
mt_state = mt_supercap_enable ? 1U : 0U;
if (dr16_status == 0 || dr16_offline())
mt_fault = 4U; /* 遥控离线 -> 已强制不使能 */
else if (mt_supercap_tx_err > 0U && mt_supercap_tx_cnt == 0U)
mt_fault = 5U; /* CAN 从未发送成功 */
else
mt_fault = 0U;
}
void module_test_send(void)
{
const uint32_t div_max =
(MT_SUPERCAP_TX_PERIOD_MS >= 2U) ? (MT_SUPERCAP_TX_PERIOD_MS / 2U) : 1U;
if (mt_supercap_tx_div == 0U)
{
CAN_TxHeaderTypeDef tx_header = {0};
uint8_t tx_data[8] = {0};
uint32_t tx_mailbox = 0;
hcan_t * hcan = mt_supercap_hcan();
/* 协议(超电/can.txt):DATA[0]=使能 DATA[1]=空 DATA[2]=功率上限(W) DATA[3]=空 */
tx_data[0] = mt_supercap_enable;
tx_data[2] = mt_supercap_power_w;
tx_header.StdId = MT_SUPERCAP_TX_ID;
tx_header.IDE = CAN_ID_STD;
tx_header.RTR = CAN_RTR_DATA;
tx_header.DLC = MT_SUPERCAP_DLC;
tx_header.TransmitGlobalTime = DISABLE;
if (HAL_CAN_GetTxMailboxesFreeLevel(hcan) > 0U &&
HAL_CAN_AddTxMessage(hcan, &tx_header, tx_data, &tx_mailbox) == HAL_OK)
{
mt_supercap_tx_cnt++;
}
else
{
mt_supercap_tx_err++;
}
}
mt_supercap_tx_div++;
if (mt_supercap_tx_div >= div_max)
mt_supercap_tx_div = 0U;
}
uint8_t mt_motor_online(void)
{
if (mt_supercap_last_tick == 0U)
return 0U;
return ((HAL_GetTick() - mt_supercap_last_tick) <= DEVICE_OFFLINE_TIME_MS) ? 1U : 0U;
}
#elif (MT_MODE == MT_MODE_FRICTION)
/* ---- 双摩擦轮同测(CAN1:0x201 左轮 / 0x202 右轮,一帧 0x200 槽1/槽2 同时下发) ----
* 控制律与 云台/modules/control/shoot.c 一致:
* 两路独立速度环,PID = GIMBAL_FRICTION_WHEEL_KP/KI/KD,误差死区 ±5,输出限幅 ±15000;
* 目标:左轮 -MT_FRICTION_SPEED_RPM,右轮 +MT_FRICTION_SPEED_RPM(左负右正,与整车同号);
* 反馈:转子转速 rotor_speed;下发:dji_motor_send_current_low(&hcan1, L, R, 0, 0)。
* 台架门控/保护:
* S1 上 = 两轮同时开;S1 中/下 = 两轮断流;遥控离线 = 断流;
* 任一轮 过温/反馈电流超 20A/堵转 -> 两轮一起断流锁存(成对机构,不单轮继续转),
* S1 离开"上"再回"上"解除;mt_fric_fault_wheel 记录是哪一轮(0=左 1=右)。 */
#define MT_FRIC_NUM 2
#define MT_FRIC_A_PER_CNT (20.0f / 16384.0f) /* C620:±16384 ↔ ±20A */
#define MT_FRIC_HARD_A 20.0f /* 反馈电流硬限(A) */
static dji_motor_t mt_fric_motor[MT_FRIC_NUM];
static PID_PositionTypeDef mt_fric_pid[MT_FRIC_NUM];
static int16_t mt_fric_out_raw[MT_FRIC_NUM];
static uint32_t mt_fric_stall_ms[MT_FRIC_NUM];
static uint8_t mt_fric_latched = 0;
static uint8_t mt_fric_gate_last = 0;
/* 用户方向目标(左负右正,与 shoot.c 的 friction_l/r Need_Value 同号) */
static const float mt_fric_target_user[MT_FRIC_NUM] = {
-MT_FRICTION_SPEED_RPM, /* 左 0x201 */
MT_FRICTION_SPEED_RPM, /* 右 0x202 */
};
volatile float mt_fric_target_rpm[MT_FRIC_NUM];
volatile float mt_fric_speed_rpm[MT_FRIC_NUM];
volatile float mt_fric_current_a[MT_FRIC_NUM];
volatile float mt_fric_temperature[MT_FRIC_NUM];
volatile float mt_fric_out_cmd[MT_FRIC_NUM];
volatile float mt_fric_power_est[MT_FRIC_NUM];
volatile uint8_t mt_fric_online_mask = 0; /* bit0=左 bit1=右 */
volatile uint8_t mt_fric_fault_wheel = 0xFF; /* 0=左 1=右 0xFF=无 */
static uint8_t mt_fric_online(uint8_t i)
{
const uint32_t t = mt_fric_motor[i].fdb.last_online_tick;
if (t == 0U)
return 0U;
return ((HAL_GetTick() - t) <= DEVICE_OFFLINE_TIME_MS) ? 1U : 0U;
}
/* 两轮断流(不清锁存) */
static void mt_fric_zero(uint8_t state)
{
for (uint8_t i = 0; i < MT_FRIC_NUM; i++)
{
mt_fric_out_raw[i] = 0;
mt_fric_stall_ms[i] = 0;
mt_fric_target_rpm[i] = 0.0f;
mt_fric_power_est[i] = 0.0f;
}
mt_state = state;
mt_power_est = mt_power_mech = mt_power_loss = 0.0f;
}
/* 任一轮触发保护:两轮一起断流锁存 */
static void mt_fric_trip(uint8_t fault, uint8_t wheel)
{
mt_fric_latched = 1;
mt_fault = fault;
mt_fric_fault_wheel = wheel;
mt_fric_zero(2);
}
void module_test_init(void)
{
dji_motor_init(&mt_fric_motor[0], &hcan1, 0x201, DJI_MOTOR_3508); /* 左 */
dji_motor_init(&mt_fric_motor[1], &hcan1, 0x202, DJI_MOTOR_3508); /* 右 */
for (uint8_t i = 0; i < MT_FRIC_NUM; i++)
{
/* 与 shoot_init() 中 friction_l/r_pid 完全一致 */
PID_PositionStructureInit(&mt_fric_pid[i], 0);
PID_PositionSetParameter(&mt_fric_pid[i], GIMBAL_FRICTION_WHEEL_KP,
GIMBAL_FRICTION_WHEEL_KI, GIMBAL_FRICTION_WHEEL_KD);
PID_PositionSetEkRange(&mt_fric_pid[i], -5, 5);
PID_PositionSetOUTRange(&mt_fric_pid[i], -15000, 15000);
mt_fric_out_raw[i] = 0;
mt_fric_stall_ms[i] = 0;
}
chassis_power_control_init();
}
void module_test_step(void)
{
const uint8_t gate = (dr16.s1 == 1); /* S1 上 = 两轮开(等价整车 friction_on) */
uint8_t mask = 0;
float p_sum = 0.0f;
/* 实测值 */
for (uint8_t i = 0; i < MT_FRIC_NUM; i++)
{
mt_fric_speed_rpm[i] = (float)mt_fric_motor[i].fdb.rotor_speed;
mt_fric_current_a[i] = (float)mt_fric_motor[i].fdb.raw_torque * MT_FRIC_A_PER_CNT;
mt_fric_temperature[i] = (float)mt_fric_motor[i].fdb.temperature;
if (mt_fric_online(i))
mask |= (uint8_t)(1U << i);
}
mt_fric_online_mask = mask;
/* 遥控器离线:立即断流 */
if (dr16_status == 0 || dr16_offline())
{
mt_fault = 4;
mt_fric_zero(0);
return;
}
/* S1 离开"上":解除锁存 */
if (!gate)
{
mt_fric_latched = 0;
mt_fric_gate_last = 0;
}
if (!gate || mt_fric_latched)
{
mt_fric_zero(mt_fric_latched ? 2 : 0);
return;
}
/* 使能上升沿:清两路 PID,干净起步 */
if (!mt_fric_gate_last)
{
for (uint8_t i = 0; i < MT_FRIC_NUM; i++)
{
PID_PositionClean(&mt_fric_pid[i]);
mt_fric_stall_ms[i] = 0;
}
mt_fric_fault_wheel = 0xFF;
}
mt_fric_gate_last = 1;
for (uint8_t i = 0; i < MT_FRIC_NUM; i++)
{
/* 保护:过温 */
if (mt_fric_motor[i].fdb.temperature > MT_TEMP_MAX_C)
{
mt_fric_trip(3, i);
return;
}
/* 速度环(与 shoot_control() 一致:Need_Value = 目标,反馈 = 转子转速) */
mt_fric_target_rpm[i] = mt_fric_target_user[i];
mt_fric_pid[i].Need_Value = mt_fric_target_user[i] * MT_DIR_SIGN;
PID_PositionCalc(&mt_fric_pid[i], mt_fric_speed_rpm[i]);
mt_fric_out_raw[i] = (int16_t)mt_fric_pid[i].OUT;
/* 保护:反馈电流硬限 */
if (fabsf(mt_fric_current_a[i]) > MT_FRIC_HARD_A)
{
mt_fric_trip(1, i);
return;
}
/* 保护:堵转(有给定但几乎不转) */
if (fabsf(mt_fric_speed_rpm[i]) < (float)MT_STALL_RPM)
{
if (mt_fric_stall_ms[i] < 5000u)
mt_fric_stall_ms[i] += 2u; /* 本任务 2ms 一拍 */
if (mt_fric_stall_ms[i] >= MT_STALL_MS)
{
mt_fric_trip(2, i);
return;
}
}
else
mt_fric_stall_ms[i] = 0;
/* 功率模型正算(实测转速 + 反馈转矩电流) */
mt_fric_power_est[i] = power_calc_single_motor(
mt_fric_speed_rpm[i], (float)mt_fric_motor[i].fdb.raw_torque, NULL, NULL);
p_sum += mt_fric_power_est[i];
}
mt_power_est = p_sum; /* 两轮合计估计功率(W) */
mt_fault = 0;
mt_state = 1;
}
void module_test_send(void)
{
/* 与 shoot_send_cmd() 一致:CAN1 0x200,槽1=左,槽2=右 */
dji_motor_send_current_low(&hcan1, mt_fric_out_raw[0], mt_fric_out_raw[1], 0, 0);
mt_fric_out_cmd[0] = (float)mt_fric_out_raw[0];
mt_fric_out_cmd[1] = (float)mt_fric_out_raw[1];
}
/* 两轮反馈都新鲜才算在线(任一轮掉线 monitor 报警) */
uint8_t mt_motor_online(void)
{
return (mt_fric_online(0) && mt_fric_online(1)) ? 1U : 0U;
}
#else /* 单电机通用模式 */
/* ---- 被测电机实例(独立于原工程,避免与 gimbal_motor_init 抢同 ID 回调) ---- */
static dji_motor_t mt_motor;
static PID_PositionTypeDef mt_speed_pid;
/* ---- 内部状态 ---- */
static int16_t mt_out_raw = 0; /* 实际下发电流(counts) */
@@ -152,13 +495,6 @@ void module_test_init(void)
PID_PositionSetParameter(&mt_speed_pid, GIMBAL_RAMMER_KP, GIMBAL_RAMMER_KI, GIMBAL_RAMMER_KD);
PID_PositionSetEkRange(&mt_speed_pid, -20, 20);
PID_PositionSetOUTRange(&mt_speed_pid, -10000, 10000);
#elif (MT_MODE == MT_MODE_FRICTION)
/* 与 云台/modules/control/shoot.c 的摩擦轮速度环完全一致:
* GIMBAL_FRICTION_WHEEL_* 参数、误差死区 ±5、输出限幅 ±15000。 */
PID_PositionSetParameter(&mt_speed_pid, GIMBAL_FRICTION_WHEEL_KP,
GIMBAL_FRICTION_WHEEL_KI, GIMBAL_FRICTION_WHEEL_KD);
PID_PositionSetEkRange(&mt_speed_pid, -5, 5);
PID_PositionSetOUTRange(&mt_speed_pid, -15000, 15000);
#else
PID_PositionSetParameter(&mt_speed_pid, MT_SPEED_KP, MT_SPEED_KI, MT_SPEED_KD);
PID_PositionSetEkRange(&mt_speed_pid, -50, 50);
@@ -267,7 +603,7 @@ void module_test_step(void)
{
float drive_norm = 0.0f;
float cmd_limited = 0.0f;
#if (MT_MODE == MT_MODE_CHASSIS) || (MT_MODE == MT_MODE_FRICTION)
#if (MT_MODE == MT_MODE_CHASSIS)
/* 整车 PID 输出上限 15000(≈18.3A),不做额外的指令硬限;
* 台架只保留 C620 满量程(20A)保护。 */
const float hard_limit_a = 20.0f;
@@ -296,8 +632,6 @@ void module_test_step(void)
const float i_limit = MECANUM_WHEEL_SPEED_OUT_LIMIT; /* 与整车 PID 输出限幅一致 */
#elif (MT_MODE == MT_MODE_SHOOT)
const float i_limit = 10000.0f; /* 与 云台 shoot.c 拨弹 PID 限幅一致 */
#elif (MT_MODE == MT_MODE_FRICTION)
const float i_limit = 15000.0f; /* 与 云台 shoot.c 摩擦轮 PID 限幅一致 */
#else
const float i_limit = MT_CUR_MAX_A / a_per_cnt;
#endif
@@ -365,19 +699,6 @@ void module_test_step(void)
? fabsf(target_rpm / GIMBAL_RAMMER_SPEED)
: 0.0f;
}
#elif (MT_MODE == MT_MODE_FRICTION)
/* 1e) 云台摩擦轮 3508:与 云台/modules/control/shoot.c 的 friction 环一致。
* 能走到这里说明 S1 已在"上"(=整车 friction_on);
* 左轮(CAN1 ID1)负向、右轮(CAN1 ID2)正向,与 shoot.c 的符号一一对应。
* 幅值用台架低速给定 MT_FRICTION_SPEED_RPM(验转向用,整车仍是 5500)。 */
{
#if (MT_ID == 1)
target_rpm = -MT_FRICTION_SPEED_RPM; /* 左摩擦轮 0x201 */
#else
target_rpm = MT_FRICTION_SPEED_RPM; /* 右摩擦轮 0x202 */
#endif
drive_norm = 1.0f;
}
#else
/* 1b) 速度模式参考加速度限幅(拨轮阶跃 -> 有界加速度) */
{
@@ -402,7 +723,7 @@ void module_test_step(void)
{
const float target_rpm_user = target_rpm;
mt_target = target_rpm_user;
#if (MT_MODE == MT_MODE_SHOOT) || (MT_MODE == MT_MODE_FRICTION)
#if (MT_MODE == MT_MODE_SHOOT)
mt_target_mps = 0.0f; /* 拨弹/摩擦轮模式:通道2 输出目标转速 RPM */
#else
mt_target_mps = mt_rpm_to_mps(target_rpm_user);
@@ -419,7 +740,7 @@ void module_test_step(void)
mt_ref_alpha += (alpha_raw - mt_ref_alpha) * (MT_SINE_STEP_S / (tau + MT_SINE_STEP_S));
mt_ref_last = target_rpm;
#if (MT_FF_ENABLE) && (MT_MODE != MT_MODE_CHASSIS) && (MT_MODE != MT_MODE_SHOOT) && (MT_MODE != MT_MODE_FRICTION)
#if (MT_FF_ENABLE) && (MT_MODE != MT_MODE_CHASSIS) && (MT_MODE != MT_MODE_SHOOT)
mt_ff_cmd = mt_ff_counts(mt_ref_alpha, omega_ref, a_per_cnt);
#else
(void)omega_ref;
@@ -427,7 +748,7 @@ void module_test_step(void)
#endif
}
#if (MT_MODE == MT_MODE_SHOOT) || (MT_MODE == MT_MODE_FRICTION)
#if (MT_MODE == MT_MODE_SHOOT)
mt_target_out = mt_target; /* 拨弹/摩擦轮模式:通道2 为目标转速 RPM */
#elif MT_TARGET_MPS_OUT
mt_target_out = mt_target_mps; /* 通道2:用户方向目标线速度(m/s) */
@@ -449,7 +770,7 @@ void module_test_step(void)
cmd_limited = -i_limit;
/* 5) 功率预算限幅:模型估计瞬时功率超预算时,逆解出允许电流并下压 */
#if (MT_POWER_BUDGET_ENABLE) && (MT_MODE != MT_MODE_CHASSIS) && (MT_MODE != MT_MODE_SHOOT) && (MT_MODE != MT_MODE_FRICTION)
#if (MT_POWER_BUDGET_ENABLE) && (MT_MODE != MT_MODE_CHASSIS) && (MT_MODE != MT_MODE_SHOOT)
{
const float p_est = power_calc_single_motor(mt_speed_rpm, cmd_limited, NULL, NULL);
if (p_est > MT_POWER_BUDGET_W)
@@ -568,3 +889,5 @@ uint8_t mt_motor_online(void)
return 0;
return (HAL_GetTick() - mt_motor.fdb.last_online_tick) <= DEVICE_OFFLINE_TIME_MS ? 1 : 0;
}
#endif /* MT_MODE */
+62 -14
View File
@@ -20,7 +20,7 @@
* 操作(DT7,USART3):
* S1 上(1) = 使能;S1 中/下 = 断流(不使能)
* S1 上且 MT_MODE_SINE = 自动正弦速度运动,拨轮不用
* S1 上且 MT_MODE_FRICTION = 摩擦轮按整车目标转速旋转(等价整车 friction_on),拨轮不用
* S1 上且 MT_MODE_FRICTION = 左右两颗摩擦轮同时按整车目标转速旋转(等价整车 friction_on),拨轮不用
* 拨轮 = SPEED/CURRENT:中位(1000~1050)为 0,向上(>1050)给正、向下(<1000)给负,
* 满偏 = 最大转速或最大电流;
* CHASSIS:按整车右摇杆映射给 vx;SHOOT:向下发射/向上退弹
@@ -64,11 +64,12 @@
#define MT_TYPE_M3508 0 /* 减速比 3591:187,电流 ±16384↔±20A */
#define MT_TYPE_M2006 1 /* 减速比 36:1, 电流 ±16384↔±10A */
#define MT_TYPE_GM6020 2 /* 直驱, 电流 ±16384↔±3A */
#define MT_TYPE_SUPERCAP 3 /* 超级电容控制板 Plus:仅 CAN 帧头通信测试 */
/* ---- 被测模块选择(改这三行即可换模块) ---- */
#define MT_TYPE MT_TYPE_M3508
#define MT_CAN 1 /* 1 = CAN1,2 = CAN2 */
#define MT_ID 2 /* 电调/电机 ID:3508/2006 为 1~8;6020 为 1~7 */
#define MT_TYPE MT_TYPE_SUPERCAP
#define MT_CAN 1 /* 1 = CAN1,2 = CAN2(SUPERCAP 固定 CAN1) */
#define MT_ID 1 /* 电调/电机 ID:3508/2006 为 1~8;6020 为 1~7(SUPERCAP 不用) */
/* ---- 被测电机方向调节(1/0) ----
* 1 = 与模块定义方向同向(默认)
@@ -91,7 +92,8 @@
#define MT_MODE_CHASSIS 3 /* 底盘 3508 单轮:与 底盘 chassis_control() 完全一致 */
#define MT_MODE_SHOOT 4 /* 云台拨弹 2006 速度环:与 云台 shoot.c 的 rammer 环完全一致 */
#define MT_MODE_FRICTION 5 /* 云台摩擦轮 3508 速度环:与 云台 shoot.c 的 friction 环完全一致 */
#define MT_MODE MT_MODE_FRICTION
#define MT_MODE_SUPERCAP 6 /* 超电 CAN1 测试:S1 上=使能,左摇杆上推=30~50W(上限90W) */
#define MT_MODE MT_MODE_SUPERCAP
/* ---- 底盘 3508 单轮验证模式(MT_MODE_CHASSIS)专用 ----
* 目标线速度按整车同一映射(与 底盘/robot_cmd_task.c 右摇杆 -> vx 一致):
@@ -117,9 +119,35 @@
#if (MT_MODE == MT_MODE_FRICTION) && (MT_TYPE != MT_TYPE_M3508)
#error "MT_MODE_FRICTION 只适用于 MT_TYPE_M3508"
#endif
#if (MT_MODE == MT_MODE_FRICTION) && ((MT_CAN != 1) || (MT_ID > 2))
#error "MT_MODE_FRICTION 只支持 CAN1 的 ID1(左摩擦轮)/ID2(右摩擦轮)"
#if (MT_MODE == MT_MODE_FRICTION) && (MT_CAN != 1)
#error "MT_MODE_FRICTION 双摩擦轮固定走 CAN1(0x201 左 / 0x202 右),请设 MT_CAN = 1"
#endif
#if (MT_MODE == MT_MODE_SUPERCAP) && (MT_TYPE != MT_TYPE_SUPERCAP)
#error "MT_MODE_SUPERCAP 只适用于 MT_TYPE_SUPERCAP"
#endif
#if (MT_TYPE == MT_TYPE_SUPERCAP) && (MT_MODE != MT_MODE_SUPERCAP)
#error "MT_TYPE_SUPERCAP 请配合 MT_MODE_SUPERCAP 使用"
#endif
#if (MT_MODE == MT_MODE_SUPERCAP) && (MT_CAN != 1)
#error "MT_MODE_SUPERCAP 固定走 CAN1,请设 MT_CAN = 1"
#endif
/* ---- 超级电容 CAN 通信测试参数(MT_MODE_SUPERCAP,见 超电/can.txt) ----
* 协议:
* - 发送:CAN1,标准数据帧 ID = 0x001,DLC = 8
* DATA[0]=使能(1/0) DATA[1]=空 DATA[2]=功率上限(W) DATA[3]=空
* - 发送频率:> 10 Hz(否则超电板判离线;超电板内部以 100 Hz 刷新接收数据)
* - 反馈帧 :标准帧 ID = 0x100(200 Hz,见 superelec_control CAN_SUPERCAP_TO_BUS_ID)
* DT7 控制:
* - 左上拨杆 S1 上(1) = 使能;中/下/遥控离线 = 不使能
* - 左侧摇杆上下(rc_l_UD)上推按比例直接映射增加功率(拨到底 +20W,默认 30W,总上限 90W) */
#define MT_SUPERCAP_TX_ID 0x001U /* C 板 -> 超电 TX 标准 ID */
#define MT_SUPERCAP_RX_ID 0x100U /* 超电 -> C 板 RX 标准 ID */
#define MT_SUPERCAP_DLC 8U /* 协议 8 字节 */
#define MT_SUPERCAP_TX_PERIOD_MS 10U /* 发送周期(ms),10ms=100Hz(>10Hz 要求) */
#define MT_SUPERCAP_BASE_POWER_W 30U /* 默认基础功率(W) */
#define MT_SUPERCAP_STICK_DELTA_W 20U /* 左摇杆推到底最高增加功率(W) */
#define MT_SUPERCAP_MAX_POWER_W 90U /* 功率硬上限(W) */
/* ---- 云台拨弹 2006 验证模式(MT_MODE_SHOOT) ----
* 与 云台/modules/control/shoot.c 的拨弹速度环一致:
@@ -130,22 +158,24 @@
* 参数直接来自 云台/Application/robot_param.h(module_test 通过 aggregator 引用),
* 不复制数值。 */
/* ---- 云台摩擦轮 3508 验证模式(MT_MODE_FRICTION) ----
/* ---- 云台双摩擦轮 3508 验证模式(MT_MODE_FRICTION,两颗同时测) ----
* 与 云台/modules/control/shoot.c 的摩擦轮速度环一致:
* PID: GIMBAL_FRICTION_WHEEL_KP/KI/KD,误差死区 ±5,输出限幅 ±15000
* 目标: S1 上 = 开(等价整车 friction_on=(s1==1);台架无裁判系统,
* PID: GIMBAL_FRICTION_WHEEL_KP/KI/KD,误差死区 ±5,输出限幅 ±15000(两路独立)
* 目标: S1 上 = 两轮同时开(等价整车 friction_on=(s1==1);台架无裁判系统,
* 相当于整车 DEBUG_SHOOT_WITHOUT_REFEREE 绕过上电门控),
* 左轮(CAN1 ID1/0x201) = -MT_FRICTION_SPEED_RPM,
* 右轮(CAN1 ID2/0x202) = +MT_FRICTION_SPEED_RPM;S1 中/下 = 0
* 右轮(CAN1 ID2/0x202) = +MT_FRICTION_SPEED_RPM;S1 中/下 = 两轮断流
* 下发: CAN1 0x200 一帧,槽1=左、槽2=右(与 shoot_send_cmd() 相同)
* 反馈: 转子转速 rotor_speed(与 shoot.c 相同)
* 测哪一颗由 MT_ID 决定(1=左,2=右),目标符号随之自动取,不另设开关。
* 保护: 任一轮过温/电流超 20A/堵转 -> 两轮一起断流锁存,mt_fric_fault_wheel 记哪一轮
* 该模式固定 CAN1,不使用 MT_ID。
* 验证转向时 MT_DIR_SEL 必须为 1,否则台架给定方向与整车不一致。
* PID/死区/限幅/符号直接来自 云台/Application/robot_param.h,不复制数值。 */
/* 台架验转向用的目标转速幅值(rpm,转子)。整车开启值是 GIMBAL_FRICTION_WHEEL_SPEED
* (5500),空载全速太危险;这里只降台架给定幅值,符号仍与整车一致(左负右正),
* 改这个值不影响整车。要复现整车全速就把它改成 GIMBAL_FRICTION_WHEEL_SPEED。 */
#define MT_FRICTION_SPEED_RPM 500.0f
#define MT_FRICTION_SPEED_RPM 1500.0f
/* ---- 正弦运动参数(MT_MODE_SINE) ----
* 速度统一用「轮面线速度 m/s」给定,内部按底盘工程同一换算换成 C620 转子 RPM:
@@ -241,6 +271,24 @@ extern volatile float mt_ff_cmd; /* 速度环前馈输出(counts) */
extern volatile float mt_cmd_limited; /* 限幅(电流/功率预算)后总指令(counts) */
extern volatile float mt_ref_alpha; /* 整形后参考加速度(rad/s²) */
extern volatile uint8_t mt_state; /* 0=IDLE 1=RUN 2=PROTECT */
extern volatile uint8_t mt_fault; /* 0=无 1=电流硬限 2=堵转 3=过温 4=遥控离线 */
extern volatile uint8_t mt_fault; /* 0=无 1=电流硬限 2=堵转 3=过温 4=遥控离线 5=CAN发送失败 */
extern volatile uint32_t mt_supercap_tx_cnt; /* 超电 CAN TX 成功帧计数 */
extern volatile uint32_t mt_supercap_tx_err; /* 超电 CAN TX 失败帧计数 */
extern volatile uint32_t mt_supercap_rx_cnt; /* 超电 0x100 RX 反馈计数 */
extern volatile uint8_t mt_supercap_ready; /* 超电反馈 DATA[0]:可用标志 */
extern volatile uint8_t mt_supercap_cap_state; /* 超电反馈 DATA[1]:运行状态 */
extern volatile uint8_t mt_supercap_energy; /* 超电反馈 DATA[2]:电容电量(0~100%) */
extern volatile uint8_t mt_supercap_enable; /* 当前下发 DATA[0]:使能(S1 上=1,其余=0) */
extern volatile uint8_t mt_supercap_power_w; /* 当前下发 DATA[2]:功率上限(W,默认30,最高90) */
/* ---- 双摩擦轮诊断量(MT_MODE_FRICTION,[0]=左 0x201,[1]=右 0x202) ---- */
extern volatile float mt_fric_target_rpm[2]; /* 目标转速(RPM,用户方向) */
extern volatile float mt_fric_speed_rpm[2]; /* 实测转子转速(RPM) */
extern volatile float mt_fric_current_a[2]; /* 反馈转矩电流(A) */
extern volatile float mt_fric_temperature[2]; /* 温度(℃) */
extern volatile float mt_fric_out_cmd[2]; /* 下发电流(counts) */
extern volatile float mt_fric_power_est[2]; /* 单轮估计功率(W),合计见 mt_power_est */
extern volatile uint8_t mt_fric_online_mask; /* bit0=左在线 bit1=右在线 */
extern volatile uint8_t mt_fric_fault_wheel; /* 触发保护的轮:0=左 1=右 0xFF=无 */
#endif