|
|
@ -29,25 +29,14 @@ void ECLMotor::readTimerCallback(void *arg) { |
|
|
|
// 读取电机位置
|
|
|
|
void ECLMotor::readMotorPosition() { |
|
|
|
// 清除标志位
|
|
|
|
#if 0
|
|
|
|
if(isHoming()) { |
|
|
|
if(++home_count_ == max_home_count_) { |
|
|
|
// 强制清零
|
|
|
|
home_count_ = 0; |
|
|
|
homeState_ = STATE_INIT; |
|
|
|
ZLOGI(TAG, "【HOME STATE COUNT FORCE CLEAR】"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
TMC51X0 *motor = AppHardware::ins()->getPump(index_); |
|
|
|
if (motor == nullptr) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
bool is_reached = false; |
|
|
|
bool is_move_finished = false; |
|
|
|
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
bool last_is_move_finished = is_move_finished_; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
|
|
|
|
int32_t x_actual = 0; |
|
|
|
int32_t enc_val = 0; |
|
|
@ -58,76 +47,31 @@ void ECLMotor::readMotorPosition() { |
|
|
|
rt_speed = motor->getVACTUAL(); // 获取实时速度
|
|
|
|
|
|
|
|
TMC5130RampStat ramp_stat = motor->getRampStat(); |
|
|
|
is_reached = motor->isReachTarget(&ramp_stat); |
|
|
|
bool is_move_finished = motor->isReachTarget(&ramp_stat); |
|
|
|
|
|
|
|
int32_t postion = 0; |
|
|
|
int32_t distance = 0; |
|
|
|
if (0 == enc_val) { |
|
|
|
postion = x_actual; |
|
|
|
} else { |
|
|
|
postion = enc_val; |
|
|
|
} |
|
|
|
distance = abs(target_pos_ - postion); |
|
|
|
if (distance < 50 && is_reached) { |
|
|
|
is_move_finished = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (is_reached) { |
|
|
|
is_move_finished = true; |
|
|
|
} |
|
|
|
|
|
|
|
#if 1
|
|
|
|
#else
|
|
|
|
if(is_moving) |
|
|
|
{ |
|
|
|
if(0 == enc_val) { |
|
|
|
postion = x_actual; |
|
|
|
} |
|
|
|
else { |
|
|
|
postion = enc_val; |
|
|
|
} |
|
|
|
|
|
|
|
const bool is_forward = target_pos_ - postion > 0; |
|
|
|
distance = abs(target_pos_ - postion); |
|
|
|
|
|
|
|
// 检查目标距离与实际距离是否一致
|
|
|
|
if(distance < 20 || is_forward != isFoward_) { |
|
|
|
// 电机移动停止
|
|
|
|
motor->stop(); |
|
|
|
// 发送CAN 消息
|
|
|
|
is_moving = false; |
|
|
|
this->runStop(); |
|
|
|
ZLOGI(TAG, "MOTOR DETECT STOP!!! "); |
|
|
|
#if TIMER_IS_FINE
|
|
|
|
setReadRate(READ_RATE_LOW); |
|
|
|
#endif
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endif
|
|
|
|
bool is_moving = false; |
|
|
|
// 移动中
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
is_moving = is_moving_; |
|
|
|
if (is_move_finished) { |
|
|
|
is_moving_ = false; |
|
|
|
} |
|
|
|
is_move_finished_ = is_move_finished; |
|
|
|
x_actual_ = x_actual; |
|
|
|
enc_val_ = enc_val; |
|
|
|
rt_speed_ = rt_speed; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
|
|
|
|
if (is_moving && is_move_finished) { |
|
|
|
if (!last_is_move_finished && is_move_finished) { |
|
|
|
//处理移动结束的问题
|
|
|
|
#if 1
|
|
|
|
if (isHoming()) { |
|
|
|
ZLOGI(TAG, "【[TIMER] HOMING EVENT_MOTOR_MOVE_FINISHED】"); |
|
|
|
#if 1
|
|
|
|
if (!isHomeSuc()) { |
|
|
|
ZLOGI(TAG, "[TIMER] HOMING EVENT_MOTOR_MOVE_FINISHED"); |
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
home_event_.event_type = EVENT_MOTOR_MOVE_FINISHED; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
osMessageQueuePut(homeEventQueue, &home_event_, 0U, 0U); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
// 发送CAN 消息
|
|
|
|
{ |
|
|
|
#if CAN_MODULE_ENABLE
|
|
|
@ -140,25 +84,8 @@ void ECLMotor::readMotorPosition() { |
|
|
|
} |
|
|
|
|
|
|
|
// 设置读取速率
|
|
|
|
void ECLMotor::setReadRate(ReadRate rate) { |
|
|
|
readRate = rate; |
|
|
|
uint32_t period; |
|
|
|
switch (rate) { |
|
|
|
case READ_RATE_LOW: |
|
|
|
period = 500; // 1秒
|
|
|
|
break; |
|
|
|
case READ_RATE_MEDIUM: |
|
|
|
period = 100; // 500毫秒
|
|
|
|
break; |
|
|
|
case READ_RATE_HIGH: |
|
|
|
period = 50; // 50毫秒
|
|
|
|
break; |
|
|
|
default: |
|
|
|
period = 1000; |
|
|
|
break; |
|
|
|
} |
|
|
|
osTimerStop(readTimer); |
|
|
|
osTimerStart(readTimer, period); |
|
|
|
void ECLMotor::startReadTimer() { |
|
|
|
osTimerStart(readTimer, 50); // // 50毫秒
|
|
|
|
} |
|
|
|
|
|
|
|
ECLMotor::ECLMotor() { |
|
|
@ -173,16 +100,14 @@ ECLMotor::ECLMotor() { |
|
|
|
x_actual_ = 0; |
|
|
|
target_pos_ = 0; |
|
|
|
target_speed_ = 10; // 10 / 60 * 6s ==== 6 S 可以转一圈
|
|
|
|
is_moving_ = 0; |
|
|
|
is_move_finished_ = false; |
|
|
|
enc_val_ = 0; |
|
|
|
|
|
|
|
isHomed_ = false; |
|
|
|
homeState_ = STATE_INIT; |
|
|
|
is_home_init_ = false; |
|
|
|
is_home_suc_ = false; |
|
|
|
home_state_ = STATE_INIT; |
|
|
|
isRunHomingTask = true; |
|
|
|
|
|
|
|
// 初始读取速率
|
|
|
|
readRate = READ_RATE_HIGH; |
|
|
|
|
|
|
|
// 创建定时器
|
|
|
|
osTimerAttr_t timerAttr = { |
|
|
|
.name = "MotorReadTimer", |
|
|
@ -212,9 +137,8 @@ ECLMotor::ECLMotor() { |
|
|
|
ZLOGE(TAG, "THREAD INDEX %d Create Failed", index_); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 启动定时器
|
|
|
|
setReadRate(readRate); |
|
|
|
startReadTimer(); |
|
|
|
} |
|
|
|
|
|
|
|
ECLMotor::~ECLMotor() { |
|
|
@ -251,53 +175,7 @@ void ECLMotor::setTargetPosition(int32_t target) { |
|
|
|
motor->moveTo(target, this->target_speed_); |
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
target_pos_ = target; |
|
|
|
is_moving_ = true; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
|
|
|
|
#if 0
|
|
|
|
TMC51X0 *motor = AppHardware::ins()->getPump(index_); |
|
|
|
if(motor == nullptr) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if(is_Flip[index_]) { |
|
|
|
target = -target; |
|
|
|
ZLOGI(TAG, "【MOTOR 【%d】TARGET FLIP】", index_); |
|
|
|
} |
|
|
|
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
int32_t postion = 0; |
|
|
|
|
|
|
|
#if 0
|
|
|
|
if(0 == enc_val_) { |
|
|
|
postion = x_actual_; |
|
|
|
} |
|
|
|
else { |
|
|
|
postion = enc_val_; |
|
|
|
} |
|
|
|
#else
|
|
|
|
if(0 == enc_val_) { |
|
|
|
postion = enc_val_; |
|
|
|
} |
|
|
|
else { |
|
|
|
postion = x_actual_; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
const bool is_forward = target - postion > 0; |
|
|
|
isFoward_ = is_forward; |
|
|
|
target_pos_ = target; |
|
|
|
is_moving_ = true; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
#if TIMER_IS_FINE
|
|
|
|
this->setReadRate(READ_RATE_HIGH); |
|
|
|
#endif
|
|
|
|
|
|
|
|
int32_t abs_speed = abs(speed_); |
|
|
|
int32_t speed = is_forward ? abs_speed : -abs_speed; |
|
|
|
|
|
|
|
// 运行
|
|
|
|
this->ECL_Rotate(speed, false); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::setShiftPosition(int32_t shift_target) { |
|
|
@ -313,7 +191,6 @@ void ECLMotor::setShiftPosition(int32_t shift_target) { |
|
|
|
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
target_pos_ = target_pos_ + shift_target; |
|
|
|
is_moving_ = true; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
} |
|
|
|
|
|
|
@ -330,7 +207,6 @@ void ECLMotor::moveToWithSpeed(int32_t target, int32_t speed) { |
|
|
|
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
target_pos_ = target; |
|
|
|
is_moving_ = true; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
} |
|
|
|
|
|
|
@ -343,15 +219,10 @@ void ECLMotor::setSpeed(int32_t speed) { |
|
|
|
} |
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
this->target_speed_ = speed; |
|
|
|
#if 0
|
|
|
|
if(is_moving_) { |
|
|
|
motor->moveTo(target_pos_, this->target_speed_); |
|
|
|
} |
|
|
|
#else
|
|
|
|
if (is_moving_) { |
|
|
|
// 当前正在移动
|
|
|
|
if (!is_move_finished_) { |
|
|
|
motor->setVMax(this->target_speed_); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
osMutexRelease(mutex_); |
|
|
|
} |
|
|
|
|
|
|
@ -364,11 +235,11 @@ int32_t ECLMotor::getRTSpeed() { |
|
|
|
} |
|
|
|
|
|
|
|
// 获取电机运动状态
|
|
|
|
bool ECLMotor::isMoving() { |
|
|
|
bool ECLMotor::isMoveFinished() { |
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
bool moving = is_moving_; |
|
|
|
bool is_move_finshed = is_move_finished_; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
return moving; |
|
|
|
return is_move_finshed; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取编码器位置
|
|
|
@ -386,24 +257,19 @@ void ECLMotor::setEncoderPosition(int32_t encoderPos) { |
|
|
|
osMutexRelease(mutex_); |
|
|
|
} |
|
|
|
|
|
|
|
// 新增设置是否运动的接口
|
|
|
|
void ECLMotor::setMoving(bool moving) { |
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
is_moving_ = moving; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::setMotorIndex(int32_t index) { |
|
|
|
this->index_ = index; |
|
|
|
} |
|
|
|
|
|
|
|
bool ECLMotor::isHomed() { |
|
|
|
return isHomed_; |
|
|
|
bool ECLMotor::isHomeInit() { |
|
|
|
return is_home_init_; |
|
|
|
} |
|
|
|
|
|
|
|
bool ECLMotor::isHoming() { |
|
|
|
bool isDoHome = homeState_ != STATE_INIT; |
|
|
|
return isDoHome; |
|
|
|
bool ECLMotor::isHomeSuc() { |
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
bool is_home_suc = is_home_suc_; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
return is_home_suc; |
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::runhomeSuc() { |
|
|
@ -414,10 +280,16 @@ void ECLMotor::runhomeSuc() { |
|
|
|
// 发送 CAN 信息
|
|
|
|
motor->setEncVal(0); |
|
|
|
motor->setXACTUAL(0); |
|
|
|
this->isHomed_ = true; |
|
|
|
this->homeState_ = STATE_INIT; |
|
|
|
|
|
|
|
ZLOGI(TAG, "【HOMED】 MOVE TO HOME SUC"); { |
|
|
|
// 置标志位
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
this->is_home_init_ = true; |
|
|
|
this->is_home_suc_ = true; |
|
|
|
this->home_state_ = STATE_INIT; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
|
|
|
|
ZLOGI(TAG, "【 MOVE TO HOME SUC 】"); |
|
|
|
{ |
|
|
|
#if CAN_MODULE_ENABLE
|
|
|
|
CanMessage msg = CanProtocolFactory::createUploadEvent(seq_id_home_, Motor_Home_Finished, index_); |
|
|
|
AppHardware::ins()->can0Controller.sendMessage(msg); |
|
|
@ -426,42 +298,37 @@ void ECLMotor::runhomeSuc() { |
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::startMoveHome() { |
|
|
|
// 避免有相同的操作
|
|
|
|
bool isDoHoming = this->isHoming(); |
|
|
|
if (isDoHoming) { |
|
|
|
ZLOGI(TAG, "MOTOR [%d] HOME FAILED, Current is Homing", this->index_); |
|
|
|
// return;
|
|
|
|
} |
|
|
|
home_count_ = 0; // 开始前清零
|
|
|
|
bool isAtOrigin = ELCMotorHelper::isAtOrigin(this->index_); |
|
|
|
ZLOGI(TAG, "START NOT IN HOME") |
|
|
|
home_start_tick_ = 0; |
|
|
|
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
this->is_home_suc_ = false; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
|
|
|
|
const bool isAtOrigin = ELCMotorHelper::isAtOrigin(this->index_); |
|
|
|
// 当前是否在原点
|
|
|
|
if (isAtOrigin) { |
|
|
|
home_event_.event_type = EVENT_IN_ORIGIN; |
|
|
|
ZLOGI(TAG, "EVENT_IN_ORIGIN"); |
|
|
|
ZLOGI(TAG, "[PUT] EVENT IN ORIGIN"); |
|
|
|
osStatus_t status = osMessageQueuePut(homeEventQueue, &home_event_, 0U, 0U); |
|
|
|
if (status != osOK) { |
|
|
|
ZLOGE(TAG, "EVENT_IN_ORIGIN SEND FAIL, status: %d", status); |
|
|
|
ZLOGE(TAG, "EVENT IN ORIGIN SEND FAIL, status: %d", status); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// if (homeState_ == STATE_INIT)
|
|
|
|
{ |
|
|
|
home_event_.event_type = EVENT_START_HOMING; |
|
|
|
ZLOGI(TAG, "EVENT_START_HOMING"); |
|
|
|
ZLOGI(TAG, "[PUT] EVENT_START_HOMING"); |
|
|
|
osStatus_t status = osMessageQueuePut(homeEventQueue, &home_event_, 0U, 0U); |
|
|
|
if (status != osOK) { |
|
|
|
ZLOGE(TAG, "EVENT_START_HOMING SEND FAIL, status: %d", status); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::setHomeSeqId(uint8_t seq_id) { |
|
|
|
this->seq_id_home_ = seq_id; |
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::setMoveFinishSeqId(uint8_t seq_id) { |
|
|
|
this->seq_id_move_finished_ = seq_id; |
|
|
|
this->seq_id_move_ = seq_id; |
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::homingTask(void *arg) { |
|
|
@ -475,32 +342,27 @@ void ECLMotor::homingTask(void *arg) { |
|
|
|
if (motor == nullptr) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
ZLOGI(TAG, "HANDLE NOT HOMED"); |
|
|
|
#if 1
|
|
|
|
switch (home_event.event_type) { |
|
|
|
case EVENT_START_HOMING: { |
|
|
|
ZLOGI(TAG, "[]EVENT_START_HOMING"); |
|
|
|
if (eclMotor->homeState_ == STATE_INIT) { |
|
|
|
eclMotor->homeState_ = STATE_BACK_TO_ORIGIN_MIDDLE; |
|
|
|
osMutexAcquire(eclMotor->mutex_, osWaitForever); |
|
|
|
eclMotor->home_state_ = STATE_BACK_TO_ORIGIN_MIDDLE; |
|
|
|
osMutexRelease(eclMotor->mutex_); |
|
|
|
// 中速倒转
|
|
|
|
int speed = ELCMotorHelper::getRPerMinMiddleSpeed(eclMotor->index_); |
|
|
|
int absSpeed = abs(speed); |
|
|
|
eclMotor->ECL_Rotate(-absSpeed); |
|
|
|
|
|
|
|
ZLOGI(TAG, "【HOME】 BACK TO ORIGIN MIDDLE"); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case EVENT_ORIGIN_ENTER: { |
|
|
|
// ZLOGI(TAG, "[]EVENT_ORIGIN_ENTER");
|
|
|
|
// if first enter
|
|
|
|
if (eclMotor->homeState_ == STATE_BACK_TO_ORIGIN_MIDDLE) { |
|
|
|
if(eclMotor->home_state_ == STATE_BACK_TO_ORIGIN_MIDDLE) { |
|
|
|
// 停止
|
|
|
|
// 中速向前10mm
|
|
|
|
// int speed = ELCMotorHelper::getRPerMinMiddleSpeed(eclMotor->index_);
|
|
|
|
// eclMotor->ECL_Rotate(speed);
|
|
|
|
eclMotor->homeState_ = STATE_LEAVE_ORIGIN_MIDDLE; |
|
|
|
osMutexAcquire(eclMotor->mutex_, osWaitForever); |
|
|
|
eclMotor->home_state_ = STATE_LEAVE_ORIGIN_MIDDLE; |
|
|
|
osMutexRelease(eclMotor->mutex_); |
|
|
|
|
|
|
|
// 位置清零
|
|
|
|
motor->setEncVal(0); |
|
|
@ -509,12 +371,10 @@ void ECLMotor::homingTask(void *arg) { |
|
|
|
const int32_t speed = ELCMotorHelper::getRPerMinMiddleSpeed(eclMotor->index_); |
|
|
|
eclMotor->moveToWithSpeed(ELCMotorHelper::getForwordMoveStep(eclMotor->index_), speed); |
|
|
|
// 4000 4 圈
|
|
|
|
|
|
|
|
ZLOGI(TAG, "【HOME】 [EVENT_ORIGIN_ENTER] FORWARD TO ORIGIN MIDDLE"); |
|
|
|
} |
|
|
|
|
|
|
|
// if second enter
|
|
|
|
if (eclMotor->homeState_ == STATE_BACK_TO_ORIGIN_LOW) { |
|
|
|
if (eclMotor->home_state_ == STATE_BACK_TO_ORIGIN_LOW) { |
|
|
|
// 位置清零
|
|
|
|
// 电机停止
|
|
|
|
// 回归原点成功
|
|
|
@ -522,54 +382,29 @@ void ECLMotor::homingTask(void *arg) { |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case EVENT_ENCODER_NEAR_ORIGN: { |
|
|
|
// ZLOGI(TAG, "[]EVENT_ENCODER_NEAR_ORIGN");
|
|
|
|
if (eclMotor->homeState_ == STATE_LEAVE_ORIGIN_MIDDLE) { |
|
|
|
// 停止
|
|
|
|
// 低速回归
|
|
|
|
eclMotor->homeState_ = STATE_BACK_TO_ORIGIN_LOW; |
|
|
|
|
|
|
|
int speed = ELCMotorHelper::getRPerMinLowSpeed(eclMotor->index_); |
|
|
|
eclMotor->ECL_Rotate(-speed); |
|
|
|
ZLOGI(TAG, "【HOME】 BACK TO ORIGIN LOW"); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case EVENT_IN_ORIGIN: { |
|
|
|
// ZLOGI(TAG, "[]EVENT_IN_ORIGIN");
|
|
|
|
if (eclMotor->homeState_ == STATE_INIT) { |
|
|
|
ZLOGI(TAG, "[]EVENT IN ORIGIN"); |
|
|
|
// 中速向前10mm
|
|
|
|
eclMotor->homeState_ = STATE_FORWARD_TO_ORIGIN_MIDDLE; |
|
|
|
|
|
|
|
int speed = ELCMotorHelper::getRPerMinMiddleSpeed(eclMotor->index_); |
|
|
|
eclMotor->ECL_Rotate(speed); |
|
|
|
|
|
|
|
ZLOGI(TAG, "【HOME】 FORWARD TO ORIGIN MIDDLE"); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case EVENT_ORIGIN_LEAVE: { |
|
|
|
// ZLOGI(TAG, "[]EVENT_ORIGIN_LEAVE");
|
|
|
|
if (eclMotor->homeState_ == STATE_FORWARD_TO_ORIGIN_MIDDLE) { |
|
|
|
// 停止 前向移动 1mm
|
|
|
|
eclMotor->homeState_ = STATE_LEAVE_ORIGIN_MIDDLE; |
|
|
|
motor->stop(); |
|
|
|
// 位置清零
|
|
|
|
motor->setEncVal(0); |
|
|
|
motor->setXACTUAL(0); |
|
|
|
|
|
|
|
// 前向移动 1mm
|
|
|
|
osMutexAcquire(eclMotor->mutex_, osWaitForever); |
|
|
|
eclMotor->home_state_ = STATE_LEAVE_ORIGIN_MIDDLE; |
|
|
|
osMutexRelease(eclMotor->mutex_); |
|
|
|
|
|
|
|
const int32_t speed = ELCMotorHelper::getRPerMinMiddleSpeed(eclMotor->index_); |
|
|
|
eclMotor->moveToWithSpeed(ELCMotorHelper::getForwordMoveStep(eclMotor->index_), speed); |
|
|
|
|
|
|
|
ZLOGI(TAG, "【HOME】 FORWARD TO ORIGIN MIDDLE"); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case EVENT_MOTOR_MOVE_FINISHED: { |
|
|
|
ZLOGI(TAG, "[]EVENT_MOTOR_MOVE_FINISHED"); |
|
|
|
if (eclMotor->homeState_ == STATE_LEAVE_ORIGIN_MIDDLE) { |
|
|
|
ZLOGI(TAG, "[]EVENT MOTOR MOVE FINISHED"); |
|
|
|
if (eclMotor->home_state_ == STATE_LEAVE_ORIGIN_MIDDLE) { |
|
|
|
// 低速回归
|
|
|
|
eclMotor->homeState_ = STATE_BACK_TO_ORIGIN_LOW; |
|
|
|
osMutexAcquire(eclMotor->mutex_, osWaitForever); |
|
|
|
eclMotor->home_state_ = STATE_BACK_TO_ORIGIN_LOW; |
|
|
|
osMutexRelease(eclMotor->mutex_); |
|
|
|
const int speed = ELCMotorHelper::getRPerMinLowSpeed(eclMotor->index_); |
|
|
|
eclMotor->ECL_Rotate(-speed); |
|
|
|
ZLOGI(TAG, "【HOME】 BACK TO ORIGIN LOW"); |
|
|
@ -583,39 +418,17 @@ void ECLMotor::homingTask(void *arg) { |
|
|
|
} else { |
|
|
|
ZLOGI(TAG, "GET MESSAGE FAILED"); |
|
|
|
} |
|
|
|
ZLOGI(TAG, "RUN MOTOR [END] %d", eclMotor->index_); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ECLMotor::moveToHome() { |
|
|
|
#if 0
|
|
|
|
TMC51X0 *motor = AppHardware::ins()->getPump(index_); |
|
|
|
if (motor == nullptr) { |
|
|
|
return; |
|
|
|
} |
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
is_moving_ = false; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
|
|
|
|
int32_t abs_speed = abs(target_speed_); |
|
|
|
|
|
|
|
int32_t roback_speed = -abs_speed; |
|
|
|
#if TIMER_IS_FINE
|
|
|
|
this->setReadRate(READ_RATE_HIGH); |
|
|
|
#endif
|
|
|
|
|
|
|
|
// 倒转回HOME
|
|
|
|
this->ECL_Rotate(roback_speed); |
|
|
|
ZLOGI(TAG, "ECL MOTOR HOME ROBACK SPEED %d", roback_speed); |
|
|
|
#else
|
|
|
|
this->startMoveHome(); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::runZeroLimit(bool isEnter) { |
|
|
|
// 处理回home 位逻辑
|
|
|
|
if (isHoming()) { |
|
|
|
if (!isHomeSuc()) { |
|
|
|
TMC51X0 *motor = AppHardware::ins()->getPump(index_); |
|
|
|
if (motor == nullptr) { |
|
|
|
return; |
|
|
@ -632,7 +445,6 @@ void ECLMotor::runZeroLimit(bool isEnter) { |
|
|
|
} |
|
|
|
|
|
|
|
osMessageQueuePut(homeEventQueue, &home_event_, 0U, 0U); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -645,13 +457,12 @@ void ECLMotor::runZeroLimit(bool isEnter) { |
|
|
|
return; |
|
|
|
} |
|
|
|
motor->stop(); |
|
|
|
osDelay(10); { |
|
|
|
CanMessage msg = CanProtocolFactory::createUploadEvent(seq_id_move_finished_, Motor_Move_Finished, index_); |
|
|
|
{ |
|
|
|
#if CAN_MODULE_ENABLE
|
|
|
|
CanMessage msg = CanProtocolFactory::createUploadEvent(seq_id_move_, Motor_Move_Finished, index_); |
|
|
|
AppHardware::ins()->can0Controller.sendMessage(msg); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
osDelay(10); |
|
|
|
// 重置编码器 和 位置
|
|
|
|
motor->setXACTUAL(0); |
|
|
|
motor->setEncVal(0); |
|
|
@ -659,7 +470,6 @@ void ECLMotor::runZeroLimit(bool isEnter) { |
|
|
|
this->x_actual_ = 0; |
|
|
|
this->enc_val_ = 0; |
|
|
|
this->target_pos_ = 0; |
|
|
|
this->is_moving_ = false; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
ZLOGI("ECL", "MOTOR [%d] runZeroLimit", this->index_); |
|
|
|
} |
|
|
@ -674,6 +484,10 @@ void ECLMotor::runEndLimit(bool isEnter) { |
|
|
|
|
|
|
|
void ECLMotor::runE_Stop() { |
|
|
|
// 发送CAN 消息
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
this->is_home_suc_ = false; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
|
|
|
|
this->runStop(); |
|
|
|
} |
|
|
|
|
|
|
@ -693,14 +507,9 @@ void ECLMotor::runStop() { |
|
|
|
CanMessage msg = CanProtocolFactory::createUploadEvent(seq_id_home_, Motor_Move_Finished, index_); |
|
|
|
AppHardware::ins()->can0Controller.sendMessage(msg); |
|
|
|
#endif
|
|
|
|
|
|
|
|
osMutexAcquire(mutex_, osWaitForever); |
|
|
|
this->is_moving_ = false; |
|
|
|
osMutexRelease(mutex_); |
|
|
|
} |
|
|
|
|
|
|
|
void ECLMotor::ECL_Rotate(int32_t speed, const bool is_flip) { |
|
|
|
#ifdef TEST
|
|
|
|
TMC51X0 *motor = AppHardware::ins()->getPump(index_); |
|
|
|
if (motor == nullptr) { |
|
|
|
return; |
|
|
@ -713,7 +522,4 @@ void ECLMotor::ECL_Rotate(int32_t speed, const bool is_flip) { |
|
|
|
|
|
|
|
motor->rotate(speed); |
|
|
|
ZLOGI(TAG, "ECL MOTOR %d SPEED %d", index_, speed); |
|
|
|
#else
|
|
|
|
motor->rotate(roback_speed); |
|
|
|
#endif
|
|
|
|
} |