|
|
@ -112,6 +112,8 @@ int32_t StepMotorCtrlModule::pri_module_xxx_reg(int32_t param_id, bool read, int |
|
|
|
PROCESS_REG(kreg_step_motor_enable_enc, REG_GET(m_cfg.motor_enable_enc), REG_SET(m_cfg.motor_enable_enc)); |
|
|
|
PROCESS_REG(kreg_step_motor_dzero_pos, REG_GET(m_cfg.motor_dzero), update_dzero(m_cfg.motor_dzero)); |
|
|
|
|
|
|
|
PROCESS_REG(kret_step_motor_pos_devi_tolerance, REG_GET(m_cfg.pos_devi_tolerance), update_dzero(m_cfg.pos_devi_tolerance)); |
|
|
|
|
|
|
|
default: |
|
|
|
return err::kmodule_not_find_reg; |
|
|
|
break; |
|
|
@ -121,7 +123,7 @@ int32_t StepMotorCtrlModule::pri_module_xxx_reg(int32_t param_id, bool read, int |
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_enable(int32_t enable) { |
|
|
|
ZLOGI(TAG, "m%d motor_enable %ld", m_id, enable); |
|
|
|
m_stepM1->stop(); |
|
|
|
m_thread.stop(); |
|
|
|
m_stepM1->enable(enable); |
|
|
|
m_state.enable = enable; |
|
|
|
return 0; |
|
|
@ -505,7 +507,7 @@ int32_t StepMotorCtrlModule::step_motor_easy_reciprocating_motion(int32_t startp |
|
|
|
ZLOGI(TAG, "reciprocating_motion move pos:%d", x_startpos); |
|
|
|
moveTo(x_startpos, m_cfg.motor_default_velocity); |
|
|
|
while (!m_stepM1->isReachTarget()) { |
|
|
|
osDelay(50); |
|
|
|
osDelay(20); |
|
|
|
|
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
@ -514,7 +516,7 @@ int32_t StepMotorCtrlModule::step_motor_easy_reciprocating_motion(int32_t startp |
|
|
|
ZLOGI(TAG, "reciprocating_motion move pos:%d", x_endpos); |
|
|
|
moveTo(x_endpos, m_cfg.motor_default_velocity); |
|
|
|
while (!m_stepM1->isReachTarget()) { |
|
|
|
osDelay(50); |
|
|
|
osDelay(20); |
|
|
|
|
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
@ -527,7 +529,7 @@ int32_t StepMotorCtrlModule::step_motor_easy_reciprocating_motion(int32_t startp |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
|
|
|
|
|
osDelay(50); |
|
|
|
osDelay(20); |
|
|
|
} |
|
|
|
|
|
|
|
after_motor_move(); |
|
|
@ -549,7 +551,7 @@ int32_t StepMotorCtrlModule::do_step_motor_easy_rotate(int32_t direction) { |
|
|
|
while (true) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
|
osDelay(50); |
|
|
|
osDelay(20); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -567,15 +569,13 @@ int32_t StepMotorCtrlModule::do_step_motor_easy_move_to(int32_t tox) { |
|
|
|
[this, tox]() { |
|
|
|
befor_motor_move(); |
|
|
|
|
|
|
|
{ |
|
|
|
do { |
|
|
|
int32_t expectation_dpos = tox - getnowpos(); |
|
|
|
moveTo(tox, m_cfg.motor_default_velocity); |
|
|
|
while (!m_stepM1->isReachTarget()) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!check_when_run()) break; |
|
|
|
if (!waitforstop(nullptr)) break; |
|
|
|
|
|
|
|
osDelay(50); |
|
|
|
} |
|
|
|
} |
|
|
|
checkdpos(expectation_dpos); |
|
|
|
} while (false); |
|
|
|
|
|
|
|
after_motor_move(); |
|
|
|
}, |
|
|
@ -628,6 +628,47 @@ int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_io(int32_t ioindex, int3 |
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_end_point() { return do_step_motor_easy_move_to_io(1, 1); } |
|
|
|
|
|
|
|
void StepMotorCtrlModule::checkdpos(int32_t expect_dpos) { |
|
|
|
int32_t dpos = getnowpos() - m_state.before_move_pos; |
|
|
|
if (m_cfg.pos_devi_tolerance != 0 && (abs(expect_dpos - dpos) > m_cfg.pos_devi_tolerance)) { |
|
|
|
ZLOGE(TAG, "check pos devi tolerance fail.... dpos%d,expectation_dpos:%d", dpos, expect_dpos); |
|
|
|
setErrorFlag(err::kstep_motor_lost_step); |
|
|
|
} else { |
|
|
|
ZLOGE(TAG, "dpos%d,expect_dpos:%d", dpos, expect_dpos); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_to_zero_point_quick() { |
|
|
|
//
|
|
|
|
ZLOGI(TAG, "m%d motor_move_to_zero_point_quick", m_id); |
|
|
|
m_thread.stop(); |
|
|
|
creg.module_status = 1; |
|
|
|
m_thread.start( |
|
|
|
[this]() { |
|
|
|
befor_motor_move(); |
|
|
|
bool moveToZero = false; |
|
|
|
do { |
|
|
|
// 期望偏差
|
|
|
|
int32_t expectation_dpos = 0 + m_cfg.motor_dzero - getnowpos(); |
|
|
|
// 快速移动到零点
|
|
|
|
moveTo(0 + m_cfg.motor_dzero, m_cfg.motor_default_velocity); |
|
|
|
// 等待移动到目标点
|
|
|
|
if (!waitforstop([this]() { return m_iotable[0].getState(); })) break; |
|
|
|
// 移动到零点
|
|
|
|
if (!exec_move_to_io_task(0, -1)) break; |
|
|
|
moveToZero = true; |
|
|
|
// 校验偏差
|
|
|
|
checkdpos(expectation_dpos); |
|
|
|
} while (false); |
|
|
|
|
|
|
|
after_motor_move(); |
|
|
|
if (moveToZero) setnowpos(0 + m_cfg.motor_dzero); |
|
|
|
}, |
|
|
|
[this]() { m_stepM1->stop(); }); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
|
int32_t StepMotorCtrlModule::getnowpos(int32_t& x) { |
|
|
|
if (m_cfg.motor_enable_enc == 0) { |
|
|
@ -637,6 +678,12 @@ int32_t StepMotorCtrlModule::getnowpos(int32_t& x) { |
|
|
|
x = m_stepM1->read_enc_val(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t StepMotorCtrlModule::getnowpos() { |
|
|
|
int32_t x; |
|
|
|
getnowpos(x); |
|
|
|
return x; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::trysyncpos() { |
|
|
|
if (m_cfg.motor_enable_enc == 0) { |
|
|
|
return 0; |
|
|
@ -670,3 +717,29 @@ int32_t StepMotorCtrlModule::update_dzero(int32_t dzero) { |
|
|
|
setnowpos(nowabs + m_cfg.motor_dzero); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
bool StepMotorCtrlModule::waitforstop(function<bool()> checkstop, int checkperiod) { |
|
|
|
bool suc = true; |
|
|
|
while (true) { |
|
|
|
if (m_thread.getExitFlag() || !check_when_run()) { |
|
|
|
suc = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
if (checkstop && checkstop()) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (m_stepM1->isReachTarget()) { |
|
|
|
break; |
|
|
|
} |
|
|
|
osDelay(checkperiod); |
|
|
|
} |
|
|
|
m_stepM1->stop(); |
|
|
|
|
|
|
|
while (m_thread.getExitFlag()) { |
|
|
|
if (m_stepM1->isReachTarget()) break; |
|
|
|
osDelay(checkperiod); |
|
|
|
} |
|
|
|
|
|
|
|
return suc; |
|
|
|
} |