Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added 2.0.ver
Empty file.
9 changes: 8 additions & 1 deletion driver/inc/Driver_Motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef struct {
int16_t speed; // 转子转速值, RPM
float actualCurrent; //电流
int16_t temperature; //温度
uint16_t updatedAt; // 更新电机数据时的tickCount
uint32_t updatedAt; // 更新电机数据时的tickCount
uint8_t online; // 电机是否离线

int8_t angleEnabled; // 连续角度启用
Expand Down Expand Up @@ -67,4 +67,11 @@ void Motor_Update(Motor_Type *motor, uint8_t data[8]);
*/
void Motor_Set_Angle_Bias(Motor_Type *motor, float angleBias);

/**
* @brief 校准连续角度为输入量
*
* @param calibratedAngle 校准角度
*/
void Motor_Calibrate(Motor_Type *motor, float calibratedAngle);

#endif
4 changes: 2 additions & 2 deletions driver/inc/Driver_Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ typedef struct {
// 接收相关
uint16_t receive; // 是否接收并解包该协议
uint16_t receiveCount; // 接收计数
uint16_t receiveSeq; // 接收包序号
uint16_t lastReceiveSeq; // (仅供用户使用)上次接收序号
int16_t receiveSeq; // 接收包序号
int16_t lastReceiveSeq; // (仅供用户使用)上次接收序号
TickType_t receiveTime; // 接收时间
// 发送相关
void * node; // 发送节点
Expand Down
17 changes: 14 additions & 3 deletions driver/src/Driver_Motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ void Motor_Init(Motor_Type *motor, float reductionRate, int8_t angleEnabled, int
motor->positionBias = -1; // -1为未赋值状态
motor->angleBias = -1; // -1为未赋值状态
motor->lastPosition = -1; // -1为未赋值状态
motor->online = 1;
motor->reductionRate = reductionRate;
motor->angleEnabled = angleEnabled;
motor->inputEnabled = inputEnabled;
Expand All @@ -18,8 +19,12 @@ void Motor_Update(Motor_Type *motor, uint8_t data[8]) {
int16_t actualCurrent = data[4] << 8 | data[5];
int16_t temperature = data[6];
float angle = 0;
motor->updatedAt = xTaskGetTickCount();
motor->online = 1;
if (motor->online) {
motor->updatedAt = xTaskGetTickCount();
} else if (xTaskGetTickCount() - motor->updatedAt >= 6000) {
motor->updatedAt = xTaskGetTickCount();
motor->online = 1;
}

// 更新转子信息
motor->position = position;
Expand Down Expand Up @@ -47,7 +52,7 @@ void Motor_Update(Motor_Type *motor, uint8_t data[8]) {
if (motor->positionBias != -1) {
motor->angleBias = motor->positionBias / 8192.0f * 360; // 向下兼容
} else {
motor->angleBias = angle; // 将当前位置设为
motor->angleBias = angle; // 将当前位置设为零点
}
motor->angleBiasInit = 1;
}
Expand All @@ -63,3 +68,9 @@ void Motor_Set_Angle_Bias(Motor_Type *motor, float angleBias) {
motor->angleBiasInit = 1;
motor->lastPosition = -1;
}

void Motor_Calibrate(Motor_Type *motor, float calibratedAngle) {
motor->angleBias = motor->angle + motor->angleBias - calibratedAngle;
motor->angle = calibratedAngle;
motor->angleBiasInit = 1;
}
Loading