代码风格更新以及加入超电的对接
This commit is contained in:
1 parent
957c535bda
commit
9de485e4ef
117 files changed
+9046
-6457
No files matched your search
@@ -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 */
|
||||
Reference in new issue
Block a user