45 lines
2.1 KiB
Markdown
45 lines
2.1 KiB
Markdown
|
- 在通过串口设置电机的时候,注意发送指令不要追加回车\n,否则电机端不响应。可以使用sscom,其会将你的按键直接当作ascii字符发送出去。
|
|||
|
|
|||
|
- **此电机的CAN线序和RoboMaster开发板相反,注意单独制作CAN线**
|
|||
|
|
|||
|
- 电机控制和反馈报文:
|
|||
|
![控制报文](%E6%8E%A7%E5%88%B6%E6%8A%A5%E6%96%87.png)
|
|||
|
|
|||
|
注意,我们的代码实现不使用其电调协议的位置PD算法;自行实现了三环,并在最后给出电流参考值,发送给电调。因此command packed structure中的**pos cmd & vel cmd & Kp & Kd均为零**。报文均为小端,**低位在前**。
|
|||
|
|
|||
|
请注意发送和反馈数据的**单位**。
|
|||
|
|
|||
|
> ~~HT的电机协议做的真不行,纯纯直接抄mit还抄不明白,之后全部换成LK!~~
|
|||
|
|
|||
|
另一种上电时校准编码器的方法:
|
|||
|
|
|||
|
```c
|
|||
|
static void HTMotorDecode(CANInstance *motor_can)
|
|||
|
{
|
|||
|
uint16_t tmp; // 用于暂存解析值,稍后转换成float数据,避免多次创建临时变量
|
|||
|
uint8_t *rxbuff = motor_can->rx_buff;
|
|||
|
HTMotor_Measure_t *measure = &((HTMotorInstance *)motor_can->id)->measure; // 将can实例中保存的id转换成电机实例的指针
|
|||
|
|
|||
|
measure->last_angle = measure->total_angle;
|
|||
|
tmp = (uint16_t)((rxbuff[1] << 8) | rxbuff[2]);
|
|||
|
measure->total_angle = uint_to_float(tmp, P_MIN, P_MAX, 16) - measure->angle_bias;
|
|||
|
|
|||
|
tmp = (uint16_t)(rxbuff[3] << 4) | (rxbuff[4] >> 4);
|
|||
|
measure->speed_rads = AverageFilter((uint_to_float(tmp, V_MIN, V_MAX, 12) - HT_SPEED_BIAS), measure->speed_buff, SPEED_BUFFER_SIZE);
|
|||
|
|
|||
|
tmp = (uint16_t)(((rxbuff[4] & 0x0f) << 8) | rxbuff[5]);
|
|||
|
measure->real_current = CURRENT_SMOOTH_COEF * uint_to_float(tmp, T_MIN, T_MAX, 12) +
|
|||
|
(1 - CURRENT_SMOOTH_COEF) * measure->real_current;
|
|||
|
|
|||
|
if (!measure->first_feedback_flag) // 初始化的时候设置偏置
|
|||
|
{
|
|||
|
measure->first_feedback_flag = 1;
|
|||
|
measure->angle_bias = measure->total_angle;
|
|||
|
measure->total_angle = 0;
|
|||
|
measure->speed_rads = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
```
|
|||
|
|
|||
|
第一次收到数据时默认电机处于限位处,将速度和角度都设置为零,记录当前的编码器数据,之后每次收到都减去该值.
|