|
|
@ -110,6 +110,7 @@ int32_t StepMotorCtrlModule::_move_by(int32_t dx, action_cb_status_t status_cb) |
|
|
|
getnowpos(xnow); |
|
|
|
|
|
|
|
int32_t toxnow = xnow + dx; |
|
|
|
// ZLOGI(TAG, "m%d move_by %d xnow:%d toxnow:%d", m_id, dx, xnow, toxnow);
|
|
|
|
return move_to(toxnow, [this, status_cb, xnow](int32_t status) { |
|
|
|
if (status_cb) status_cb(status); |
|
|
|
}); |
|
|
@ -316,10 +317,27 @@ int32_t StepMotorCtrlModule::set_base_param(const base_param_t& param) { |
|
|
|
ZLOGI(TAG, "= min_x :%d", m_param.min_x); |
|
|
|
ZLOGI(TAG, "= max_x :%d", m_param.max_x); |
|
|
|
ZLOGI(TAG, "= shift_x :%d", m_param.shift_x); |
|
|
|
ZLOGI(TAG, "= run_to_zero_max_d :%d", m_param.run_to_zero_move_to_zero_max_d); |
|
|
|
ZLOGI(TAG, "= leave_from_zero_max_d :%d", m_param.run_to_zero_leave_from_zero_max_d); |
|
|
|
|
|
|
|
#if 0
|
|
|
|
s32 run_to_zero_max_d; |
|
|
|
s32 run_to_zero_speed; |
|
|
|
s32 run_to_zero_dec; |
|
|
|
|
|
|
|
s32 look_zero_edge_max_d; |
|
|
|
s32 look_zero_edge_speed; |
|
|
|
s32 look_zero_edge_dec; |
|
|
|
#endif
|
|
|
|
ZLOGI(TAG, "= run_to_zero_max_d :%d", m_param.run_to_zero_max_d); |
|
|
|
ZLOGI(TAG, "= run_to_zero_speed :%d", m_param.run_to_zero_speed); |
|
|
|
ZLOGI(TAG, "= run_to_zero_dec :%d", m_param.run_to_zero_dec); |
|
|
|
ZLOGI(TAG, "= look_zero_edge_max_d :%d", m_param.look_zero_edge_max_d); |
|
|
|
ZLOGI(TAG, "= look_zero_edge_speed :%d", m_param.look_zero_edge_speed); |
|
|
|
ZLOGI(TAG, "= look_zero_edge_dec :%d", m_param.look_zero_edge_dec); |
|
|
|
|
|
|
|
// ZLOGI(TAG, "= run_to_zero_max_d :%d", m_param.run_to_zero_move_to_zero_max_d);
|
|
|
|
// ZLOGI(TAG, "= leave_from_zero_max_d :%d", m_param.run_to_zero_leave_from_zero_max_d);
|
|
|
|
// ZLOGI(TAG, "= run_to_zero_speed :%d", m_param.run_to_zero_speed);
|
|
|
|
// ZLOGI(TAG, "= run_to_zero_dec :%d", m_param.run_to_zero_dec);
|
|
|
|
ZLOGI(TAG, "=================================="); |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -362,7 +380,7 @@ int32_t StepMotorCtrlModule::exec_move_to_zero_task() { |
|
|
|
if (!m_Xgpio->getState()) { |
|
|
|
{ |
|
|
|
ZLOGI(TAG, "---------STEP1-------- move to zero first"); |
|
|
|
_motor_move_by(-m_param.run_to_zero_move_to_zero_max_d, m_param.run_to_zero_speed * 2, m_param.acc, m_param.run_to_zero_dec); |
|
|
|
_motor_move_by(-m_param.run_to_zero_max_d, m_param.run_to_zero_speed, m_param.acc, m_param.run_to_zero_dec); |
|
|
|
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());
|
|
|
@ -396,7 +414,7 @@ int32_t StepMotorCtrlModule::exec_move_to_zero_task() { |
|
|
|
* @brief 如果设备已经在零点,则反向移动一定距离远离零点 |
|
|
|
*/ |
|
|
|
if (m_Xgpio->getState()) { |
|
|
|
_motor_move_by(m_param.run_to_zero_leave_from_zero_max_d, m_param.run_to_zero_speed, m_param.acc, m_param.run_to_zero_dec); |
|
|
|
_motor_move_by(m_param.look_zero_edge_max_d, m_param.look_zero_edge_speed, m_param.acc, m_param.look_zero_edge_dec); |
|
|
|
while (!_motor_is_reach_target()) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
if (!m_Xgpio->getState()) break; |
|
|
@ -417,37 +435,37 @@ int32_t StepMotorCtrlModule::exec_move_to_zero_task() { |
|
|
|
/*******************************************************************************
|
|
|
|
* 移动X轴到零点 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
ZLOGI(TAG, "---------STEP3-------- move to zero"); |
|
|
|
_motor_move_by(-m_param.run_to_zero_move_to_zero_max_d, m_param.run_to_zero_speed, m_param.acc, m_param.run_to_zero_dec); |
|
|
|
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 (m_Xgpio->getState()) { |
|
|
|
xreach_zero = true; |
|
|
|
_motor_stop(-1); |
|
|
|
|
|
|
|
while (!m_stepM1->isStoped()) { // 等待电机停止
|
|
|
|
_motor_stop(-1); |
|
|
|
vTaskDelay(10); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
vTaskDelay(1); |
|
|
|
} |
|
|
|
|
|
|
|
if (m_thread.getExitFlag()) { |
|
|
|
ZLOGI(TAG, "break move to zero thread exit"); |
|
|
|
return err::kce_break_by_user; |
|
|
|
} |
|
|
|
|
|
|
|
if (!xreach_zero) { |
|
|
|
// 触发异常回调
|
|
|
|
ZLOGE(TAG, "x reach zero failed"); |
|
|
|
return err::kce_not_found_x_zero_point; |
|
|
|
} |
|
|
|
} |
|
|
|
// {
|
|
|
|
// ZLOGI(TAG, "---------STEP3-------- move to zero");
|
|
|
|
// _motor_move_by(-m_param.run_to_zero_move_to_zero_max_d, m_param.run_to_zero_speed, m_param.acc, m_param.run_to_zero_dec);
|
|
|
|
// 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 (m_Xgpio->getState()) {
|
|
|
|
// xreach_zero = true;
|
|
|
|
// _motor_stop(-1);
|
|
|
|
|
|
|
|
// while (!m_stepM1->isStoped()) { // 等待电机停止
|
|
|
|
// _motor_stop(-1);
|
|
|
|
// vTaskDelay(10);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// vTaskDelay(1);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (m_thread.getExitFlag()) {
|
|
|
|
// ZLOGI(TAG, "break move to zero thread exit");
|
|
|
|
// return err::kce_break_by_user;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!xreach_zero) {
|
|
|
|
// // 触发异常回调
|
|
|
|
// ZLOGE(TAG, "x reach zero failed");
|
|
|
|
// return err::kce_not_found_x_zero_point;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (m_thread.getExitFlag()) { |
|
|
|
ZLOGI(TAG, "break move to zero thread exit"); |
|
|
@ -579,17 +597,20 @@ void StepMotorCtrlModule::call_exec_status_cb(int32_t status, action_cb_status_t |
|
|
|
void StepMotorCtrlModule::create_default_cfg(flash_config_t& cfg) { |
|
|
|
memset(&cfg, 0, sizeof(cfg)); |
|
|
|
cfg.base_param.distance_scale = 10000; |
|
|
|
cfg.base_param.ihold = 0; |
|
|
|
cfg.base_param.irun = 8; |
|
|
|
cfg.base_param.ihold = 1; |
|
|
|
cfg.base_param.irun = 3; |
|
|
|
cfg.base_param.iholddelay = 100; |
|
|
|
cfg.base_param.acc = 300; |
|
|
|
cfg.base_param.dec = 300; |
|
|
|
cfg.base_param.maxspeed = 800; |
|
|
|
|
|
|
|
cfg.base_param.run_to_zero_move_to_zero_max_d = 10000 * 100; |
|
|
|
cfg.base_param.run_to_zero_leave_from_zero_max_d = 10000 * 2; |
|
|
|
cfg.base_param.run_to_zero_speed = 100; |
|
|
|
cfg.base_param.run_to_zero_dec = 600; |
|
|
|
cfg.base_param.run_to_zero_max_d = 10000 * 100; |
|
|
|
cfg.base_param.run_to_zero_speed = 100; |
|
|
|
cfg.base_param.run_to_zero_dec = 600; |
|
|
|
|
|
|
|
cfg.base_param.look_zero_edge_max_d = 10000 * 5; |
|
|
|
cfg.base_param.look_zero_edge_speed = 100; |
|
|
|
cfg.base_param.look_zero_edge_dec = 600; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::flush() { |
|
|
|