写入了发弹检测模块,并为电流环控制
This commit is contained in:
@@ -6,9 +6,9 @@
|
||||
* (无 legacy 的 +-1 圈限制,底盘小陀螺时 Yaw 可连续旋转),
|
||||
* 记录 last_online_tick 供掉线检测
|
||||
* 控制路径(任务上下文):
|
||||
* dji_motor_send_current_low/high() 0x200 / 0x1FF 电流帧(+/-16384 = 20A/10A)
|
||||
* dji_motor_send_voltage_high() 0x2FF 电压帧(GM6020 ID5~7)
|
||||
* 注意 0x1FF 帧为 M3508/M2006 高位电流与 GM6020 低位电压共用,按槽位区分
|
||||
* dji_motor_send_current_low/high() 0x200 / 0x1FF 电流帧(+/-16384 = 20A/10A)
|
||||
* dji_motor_send_gm6020_current_low/high() 0x1FE / 0x2FE 电流帧(GM6020 +/-16384 = 3A)
|
||||
* dji_motor_send_voltage_high() 0x2FF 电压帧(GM6020 旧协议)
|
||||
* ========================================================================== */
|
||||
#include "dji_motor.h"
|
||||
|
||||
@@ -53,7 +53,7 @@ static void dji_motor_parse(dji_motor_t * motor, const uint8_t data[8])
|
||||
fdb->torque_current = fdb->raw_torque * 0.001f; // /10000*10
|
||||
break;
|
||||
case DJI_MOTOR_6020:
|
||||
fdb->torque_current = fdb->raw_torque * -3.0f; // 实际转矩电流,±3A 量程
|
||||
fdb->torque_current = (float)fdb->raw_torque * (3.0f / 16384.0f); // 实际转矩电流,±3A 量程
|
||||
break;
|
||||
}
|
||||
fdb->last_online_tick = HAL_GetTick();
|
||||
@@ -107,6 +107,13 @@ void dji_motor_send_int16x4(hcan_t * hcan, uint32_t std_id, const int16_t val[4]
|
||||
CAN_SendTxMessage(&msg);
|
||||
}
|
||||
|
||||
static inline int16_t dji_motor_clamp16(int16_t val, int16_t min_val, int16_t max_val)
|
||||
{
|
||||
if (val > max_val) return max_val;
|
||||
if (val < min_val) return min_val;
|
||||
return val;
|
||||
}
|
||||
|
||||
void dji_motor_send_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4)
|
||||
{
|
||||
const int16_t v[4] = {i1, i2, i3, i4};
|
||||
@@ -119,8 +126,31 @@ void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t
|
||||
dji_motor_send_int16x4(hcan, 0x1FF, v);
|
||||
}
|
||||
|
||||
void dji_motor_send_gm6020_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4)
|
||||
{
|
||||
const int16_t v[4] = {
|
||||
dji_motor_clamp16(i1, -16384, 16384),
|
||||
dji_motor_clamp16(i2, -16384, 16384),
|
||||
dji_motor_clamp16(i3, -16384, 16384),
|
||||
dji_motor_clamp16(i4, -16384, 16384)
|
||||
};
|
||||
dji_motor_send_int16x4(hcan, 0x1FE, v);
|
||||
}
|
||||
|
||||
void dji_motor_send_gm6020_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7)
|
||||
{
|
||||
const int16_t v[4] = {
|
||||
dji_motor_clamp16(i5, -16384, 16384),
|
||||
dji_motor_clamp16(i6, -16384, 16384),
|
||||
dji_motor_clamp16(i7, -16384, 16384),
|
||||
0
|
||||
};
|
||||
dji_motor_send_int16x4(hcan, 0x2FE, v);
|
||||
}
|
||||
|
||||
void dji_motor_send_voltage_high(hcan_t * hcan, int16_t v5, int16_t v6, int16_t v7)
|
||||
{
|
||||
const int16_t v[4] = {v5, v6, v7, 0};
|
||||
dji_motor_send_int16x4(hcan, 0x2FF, v);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user