|
|
@ -251,6 +251,19 @@ int32_t XYRobotCtrlModule::do_xymotor_move_to_zero() { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t XYRobotCtrlModule::waiting_for_stop(function<bool()> condition_fn, int32_t delay) { |
|
|
|
while (!_motor_is_reach_target()) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (condition_fn()) break; |
|
|
|
osDelay(delay); |
|
|
|
} |
|
|
|
_motor_stop(); |
|
|
|
while (_motor_is_reach_target()) { |
|
|
|
osDelay(10); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t XYRobotCtrlModule::exec_move_to_zero_task() { |
|
|
|
/*******************************************************************************
|
|
|
|
* 移动导零点 * |
|
|
@ -261,51 +274,15 @@ int32_t XYRobotCtrlModule::exec_move_to_zero_task() { |
|
|
|
|
|
|
|
if (!xgpio->getState()) { |
|
|
|
_motor_move_to_end(-1, 0, m_cfg.run_to_zero_speed); |
|
|
|
bool xreach_zero = false; |
|
|
|
|
|
|
|
while (!m_thread.getExitFlag() && !_motor_is_reach_target()) { |
|
|
|
// ZLOGI(TAG, "xgpio %d %d %d", m_Xgpio->getState(), m_stepM1->isReachTarget(), m_stepM2->isReachTarget());
|
|
|
|
if (xgpio->getState()) { |
|
|
|
xreach_zero = true; |
|
|
|
_motor_stop(); |
|
|
|
break; |
|
|
|
} |
|
|
|
vTaskDelay(1); |
|
|
|
} |
|
|
|
|
|
|
|
if (m_thread.getExitFlag()) { |
|
|
|
ZLOGI(TAG, "break move to zero thread exit"); |
|
|
|
return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
|
|
|
|
if (!xreach_zero) { |
|
|
|
ZLOGE(TAG, "find zero point fail"); |
|
|
|
return err::kxymotor_x_find_zero_edge_fail; |
|
|
|
} |
|
|
|
waiting_for_stop([this, xgpio]() { return xgpio->getState(); }, 2); |
|
|
|
if (m_thread.getExitFlag()) return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step1 reach x zero ok"); |
|
|
|
|
|
|
|
if (xgpio->getState()) { |
|
|
|
_motor_move_to_end(1, 0, m_cfg.look_zero_edge_speed); |
|
|
|
bool xleave_zero = false; |
|
|
|
while (!m_thread.getExitFlag() && !_motor_is_reach_target()) { |
|
|
|
if (!xgpio->getState()) { |
|
|
|
xleave_zero = true; |
|
|
|
_motor_stop(); |
|
|
|
break; |
|
|
|
} |
|
|
|
vTaskDelay(1); |
|
|
|
} |
|
|
|
|
|
|
|
if (m_thread.getExitFlag()) { |
|
|
|
ZLOGI(TAG, "break move to zero thread exit"); |
|
|
|
return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
|
|
|
|
if (!xleave_zero) { |
|
|
|
ZLOGI(TAG, "leave away zero failed"); |
|
|
|
return err::kxymotor_x_find_zero_edge_fail; |
|
|
|
} |
|
|
|
waiting_for_stop([this, xgpio]() { return !xgpio->getState(); }, 2); |
|
|
|
if (m_thread.getExitFlag()) return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step2 leave x zero ok"); |
|
|
|
/*******************************************************************************
|
|
|
@ -314,47 +291,18 @@ int32_t XYRobotCtrlModule::exec_move_to_zero_task() { |
|
|
|
|
|
|
|
if (!ygpio->getState()) { |
|
|
|
_motor_move_to_end(0, -1, m_cfg.run_to_zero_speed); |
|
|
|
bool yreach_zero = false; |
|
|
|
while (!m_thread.getExitFlag() && !_motor_is_reach_target()) { |
|
|
|
if (ygpio->getState()) { |
|
|
|
yreach_zero = true; |
|
|
|
_motor_stop(); |
|
|
|
break; |
|
|
|
} |
|
|
|
vTaskDelay(1); |
|
|
|
} |
|
|
|
if (m_thread.getExitFlag()) { |
|
|
|
ZLOGI(TAG, "break move to zero thread exit"); |
|
|
|
return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
if (!yreach_zero) { |
|
|
|
ZLOGE(TAG, "find zero point fail"); |
|
|
|
return err::kxymotor_y_find_zero_edge_fail; |
|
|
|
} |
|
|
|
waiting_for_stop([this, ygpio]() { return ygpio->getState(); }, 2); |
|
|
|
if (m_thread.getExitFlag()) return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step3 reach y zero ok"); |
|
|
|
|
|
|
|
if (ygpio->getState()) { |
|
|
|
_motor_move_to_end(0, 1, m_cfg.look_zero_edge_speed); |
|
|
|
bool yleave_zero = false; |
|
|
|
while (!m_thread.getExitFlag() && !_motor_is_reach_target()) { |
|
|
|
if (!ygpio->getState()) { |
|
|
|
yleave_zero = true; |
|
|
|
_motor_stop(); |
|
|
|
break; |
|
|
|
} |
|
|
|
vTaskDelay(1); |
|
|
|
} |
|
|
|
if (m_thread.getExitFlag()) { |
|
|
|
ZLOGI(TAG, "break move to zero thread exit"); |
|
|
|
return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
if (!yleave_zero) { |
|
|
|
ZLOGI(TAG, "leave away zero failed"); |
|
|
|
return err::kxymotor_y_find_zero_edge_fail; |
|
|
|
} |
|
|
|
waiting_for_stop([this, ygpio]() { return !ygpio->getState(); }, 2); |
|
|
|
if (m_thread.getExitFlag()) return err::kmodule_opeation_break_by_user; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step4 leave y zero ok"); |
|
|
|
|
|
|
|
ZLOGI(TAG, "move to zero ok"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|