|
|
@ -474,6 +474,62 @@ int32_t StepMotorCtrlModule::step_motor_easy_move_to_end_point() { |
|
|
|
} |
|
|
|
return do_step_motor_easy_move_to_end_point(); |
|
|
|
} |
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_reciprocating_motion(int32_t startpos, int32_t endpos, int32_t times) { |
|
|
|
ZLOGI(TAG, "m%d motor_reciprocating_motion %d %d %d", m_id, startpos, endpos, times); |
|
|
|
|
|
|
|
int32_t ecode = check_befor_run(); |
|
|
|
if (ecode != 0) return ecode; |
|
|
|
|
|
|
|
int32_t x_startpos; |
|
|
|
int32_t x_endpos; |
|
|
|
int32_t x_beginpos; |
|
|
|
getnowpos(x_beginpos); |
|
|
|
|
|
|
|
if (m_cfg.min_d != 0 && x_startpos < m_cfg.min_d) x_startpos = m_cfg.min_d; |
|
|
|
if (m_cfg.max_d != 0 && x_startpos > m_cfg.max_d) x_startpos = m_cfg.max_d; |
|
|
|
|
|
|
|
if (m_cfg.min_d != 0 && x_endpos < m_cfg.min_d) x_endpos = m_cfg.min_d; |
|
|
|
if (m_cfg.max_d != 0 && x_endpos > m_cfg.max_d) x_endpos = m_cfg.max_d; |
|
|
|
m_thread.stop(); |
|
|
|
m_thread.start( |
|
|
|
[this, x_startpos, x_endpos, x_beginpos, times]() { |
|
|
|
befor_motor_move(); |
|
|
|
|
|
|
|
for (size_t i = 0; i < times; i++) { |
|
|
|
ZLOGI(TAG, "reciprocating_motion move pos:%d", x_startpos); |
|
|
|
moveTo(x_startpos, m_cfg.motor_default_velocity); |
|
|
|
while (!m_stepM1->isReachTarget()) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
|
|
|
|
|
vTaskDelay(5); |
|
|
|
} |
|
|
|
|
|
|
|
ZLOGI(TAG, "reciprocating_motion move pos:%d", x_endpos); |
|
|
|
moveTo(x_endpos, m_cfg.motor_default_velocity); |
|
|
|
while (!m_stepM1->isReachTarget()) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
|
|
|
|
|
vTaskDelay(5); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ZLOGI(TAG, "reciprocating_motion finish,move begin pos:%d", x_beginpos); |
|
|
|
moveTo(x_beginpos, m_cfg.motor_default_velocity); |
|
|
|
while (!m_stepM1->isReachTarget()) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
|
|
|
|
|
vTaskDelay(5); |
|
|
|
} |
|
|
|
|
|
|
|
after_motor_move(); |
|
|
|
}, |
|
|
|
[this]() { m_stepM1->stop(); }); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::do_step_motor_easy_rotate(int32_t direction) { |
|
|
|
m_thread.stop(); |
|
|
|