代码风格更新以及加入超电的对接
This commit is contained in:
1 parent
957c535bda
commit
9de485e4ef
117 files changed
+9046
-6457
No files matched your search
@@ -3,50 +3,38 @@
|
||||
|
||||
#include "bsp_can.h"
|
||||
|
||||
/* DJI 电机(M3508/M2006/GM6020)统一驱动
|
||||
* - 反馈:can_start() 后通过 can_rx_register 按 rx_id 注册,接收中断内解析(多圈累计)
|
||||
* - 控制:组装 0x200/0x1FF/0x1FE/0x2FE 控制帧,经 CAN_SendTxMessage 发送 */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DJI_MOTOR_3508, // 减速比 3591:187(≈19:1), 转矩常数 0.3N·m/A
|
||||
DJI_MOTOR_2006, // 减速比 36:1, 转矩常数 0.18N·m/A
|
||||
DJI_MOTOR_6020, // 直驱, 电流控制(ID1~4 为 0x1FE 帧, ±16384 对应 ±3A)
|
||||
} dji_motor_type_e;
|
||||
DJI_MOTOR_3508,//M3508电机,减速比3591:187(约19:1),转矩常数0.3N·m/A
|
||||
DJI_MOTOR_2006,//M2006电机,减速比36:1,转矩常数0.18N·m/A
|
||||
DJI_MOTOR_6020,//GM6020电机,直驱,电流控制(ID1~4为0x1FE帧,±16384对应±3A)
|
||||
} dji_motor_type_e;//大疆电机类型枚举
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t raw_angle; // 本次机械角度原始数据(0~8191 对应 0~360°)
|
||||
int64_t total_tick; // 累计角度位置原始数据(8192*圈数+raw,无 ±1 圈限制)
|
||||
float rotor_angle_deg; // 累计转子机械角(°)
|
||||
int16_t rotor_speed; // 转子转速(RPM)
|
||||
int16_t raw_torque; // 转矩电流原始数据
|
||||
float torque_current; // 转矩电流(A)
|
||||
uint8_t temperature; // 电机温度(℃)
|
||||
uint32_t last_online_tick; // 最近一次收到反馈的 tick(HAL_GetTick)
|
||||
} dji_motor_feedback_t;
|
||||
uint16_t raw_angle;//本次机械角度原始值(0~8191对应0~360°)
|
||||
int64_t total_tick;//累计多圈机械位置原始值(8192*圈数+raw,无±1圈限制)
|
||||
float rotor_angle_deg;//累计转子机械角度(°)
|
||||
int16_t rotor_speed;//转子转速(RPM)
|
||||
int16_t raw_torque;//转矩电流原始编码值
|
||||
float torque_current;//换算后转矩电流(A)
|
||||
uint8_t temperature;//电机温度(℃)
|
||||
uint32_t last_online_tick;//最近一次收到反馈的系统tick(HAL_GetTick)
|
||||
} dji_motor_feedback_t;//大疆电机反馈数据结构体
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dji_motor_type_e type;
|
||||
hcan_t * hcan;
|
||||
uint16_t rx_id; // 反馈 ID:M3508/M2006 0x201~0x208,GM6020 0x205~0x20B
|
||||
dji_motor_feedback_t fdb;
|
||||
} dji_motor_t;
|
||||
dji_motor_type_e type;//电机类型
|
||||
hcan_t * hcan;//所属CAN总线句柄(&hcan1/&hcan2)
|
||||
uint16_t rx_id;//反馈报文标准ID(3508/2006:0x201~0x208,6020:0x205~0x20B)
|
||||
dji_motor_feedback_t fdb;//电机反馈数据
|
||||
} dji_motor_t;//大疆电机实例结构体
|
||||
|
||||
/* 初始化并注册 CAN 接收回调(can_start() 之后调用) */
|
||||
extern void dji_motor_init(dji_motor_t * motor, hcan_t * hcan, uint16_t rx_id, dji_motor_type_e type);
|
||||
|
||||
/* ---- 控制帧发送 ----
|
||||
* M3508/M2006 ID1~4:0x200 电流帧(±16384 对应 ±20A/±10A)
|
||||
* M3508/M2006 ID5~8:0x1FF 电流帧(±16384)
|
||||
* GM6020 电流控制:ID1~4 为 0x1FE 电流帧(±16384 对应 ±3A),ID5~8 为 0x2FE 电流帧(±16384) */
|
||||
extern void dji_motor_send_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
||||
extern void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
||||
extern void dji_motor_send_gm6020_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);
|
||||
extern void dji_motor_send_gm6020_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);
|
||||
|
||||
/* 通用 int16x4 发送(板间通讯等复用) */
|
||||
extern void dji_motor_send_int16x4(hcan_t * hcan, uint32_t std_id, const int16_t val[4]);
|
||||
void dji_motor_init(dji_motor_t * motor, hcan_t * hcan, uint16_t rx_id, dji_motor_type_e type);//初始化电机实例并注册CAN接收回调
|
||||
void dji_motor_send_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);//发送3508/2006 ID1~4电流帧(0x200)
|
||||
void dji_motor_send_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);//发送3508/2006 ID5~8电流帧(0x1FF)
|
||||
void dji_motor_send_gm6020_current_low(hcan_t * hcan, int16_t i1, int16_t i2, int16_t i3, int16_t i4);//发送GM6020 ID1~4电流帧(0x1FE)
|
||||
void dji_motor_send_gm6020_current_high(hcan_t * hcan, int16_t i5, int16_t i6, int16_t i7, int16_t i8);//发送GM6020 ID5~8电流帧(0x2FE)
|
||||
void dji_motor_send_int16x4(hcan_t * hcan, uint32_t std_id, const int16_t val[4]);//通用4路int16大端打包CAN发送函数
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user