|
|
@ -16,7 +16,6 @@ void StepMotorCtrlModule::initialize(int moduleid, TMC51X0* stepM, ZGPIO iotable |
|
|
|
m_iotable = iotable; |
|
|
|
m_nio = nio; |
|
|
|
|
|
|
|
|
|
|
|
m_thread.init(TAG, 1024, osPriorityNormal); |
|
|
|
m_cfg = *cfg; |
|
|
|
m_default_cfg = *cfg; |
|
|
@ -442,13 +441,13 @@ bool StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t directio |
|
|
|
|
|
|
|
if (!check_when_run()) return false; |
|
|
|
|
|
|
|
if (!getIOState(ioindex)) { |
|
|
|
if (isIORelease(ioindex)) { |
|
|
|
ZLOGI(TAG, "---------STEP1-------- move to point"); |
|
|
|
rotate(direction, runToPointSpeed); |
|
|
|
bool xreach_io = false; |
|
|
|
|
|
|
|
while (!m_thread.getExitFlag()) { |
|
|
|
if (getIOState(ioindex)) { |
|
|
|
if (isIOTrigger(ioindex)) { |
|
|
|
xreach_io = true; |
|
|
|
m_stepM1->stop(); |
|
|
|
break; |
|
|
@ -474,13 +473,13 @@ bool StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t directio |
|
|
|
|
|
|
|
// 如果设备已经在零点,则反向移动一定距离远离零点
|
|
|
|
|
|
|
|
if (getIOState(ioindex)) { |
|
|
|
if (isIOTrigger(ioindex)) { |
|
|
|
ZLOGI(TAG, "---------STEP2-------- find edge"); |
|
|
|
rotate(-direction, lookPointVelocity); |
|
|
|
bool reach_edge = false; |
|
|
|
|
|
|
|
while (!m_thread.getExitFlag()) { |
|
|
|
if (!getIOState(ioindex)) { |
|
|
|
if (isIORelease(ioindex)) { |
|
|
|
reach_edge = true; |
|
|
|
m_stepM1->stop(); |
|
|
|
break; |
|
|
@ -503,13 +502,13 @@ bool StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t directio |
|
|
|
if (!check_when_run()) return false; |
|
|
|
|
|
|
|
// 如果设备已经在零点,则反向移动一定距离远离零点
|
|
|
|
if (!getIOState(ioindex)) { |
|
|
|
if (isIORelease(ioindex)) { |
|
|
|
ZLOGI(TAG, "---------STEP3-------- bak to gpio trigger edge"); |
|
|
|
rotate(direction, lookPointVelocity); |
|
|
|
bool reach_edge = false; |
|
|
|
|
|
|
|
while (!m_thread.getExitFlag()) { |
|
|
|
if (getIOState(ioindex)) { |
|
|
|
if (isIOTrigger(ioindex)) { |
|
|
|
reach_edge = true; |
|
|
|
m_stepM1->stop(); |
|
|
|
break; |
|
|
@ -632,7 +631,6 @@ int32_t StepMotorCtrlModule::step_motor_easy_move_to_zero() { |
|
|
|
return err::kstep_motor_ioindex_out_of_range; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return do_step_motor_easy_move_to_zero(); |
|
|
|
} |
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) { |
|
|
@ -997,3 +995,20 @@ bool StepMotorCtrlModule::getIOState(int32_t ioindex) { |
|
|
|
return m_iotable[ioindex].getState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bool StepMotorCtrlModule::isIOTrigger(int32_t ioindex) { |
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
bool state = getIOState(ioindex); |
|
|
|
if (!state) return false; |
|
|
|
zos_early_delayus(100); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
bool StepMotorCtrlModule::isIORelease(int32_t ioindex) { |
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
bool state = getIOState(ioindex); |
|
|
|
if (state) return false; |
|
|
|
zos_early_delayus(100); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |