|
@ -5,6 +5,7 @@ |
|
|
|
|
|
|
|
|
#include "a8000_protocol\protocol.hpp"
|
|
|
#include "a8000_protocol\protocol.hpp"
|
|
|
#include "sdk\components\flash\znvs.hpp"
|
|
|
#include "sdk\components\flash\znvs.hpp"
|
|
|
|
|
|
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|
|
using namespace iflytop; |
|
|
using namespace iflytop; |
|
|
#define TAG "SMCM"
|
|
|
#define TAG "SMCM"
|
|
|
|
|
|
|
|
@ -23,6 +24,11 @@ void StepMotorCtrlModule::initialize(int moduleid, IStepperMotor* stepM, ZGPIO i |
|
|
|
|
|
|
|
|
step_motor_active_cfg(); |
|
|
step_motor_active_cfg(); |
|
|
step_motor_enable(true); |
|
|
step_motor_enable(true); |
|
|
|
|
|
|
|
|
|
|
|
TMC5130* tmcmotor = dynamic_cast<TMC5130*>(m_stepM1); |
|
|
|
|
|
if (tmcmotor) { |
|
|
|
|
|
tmcmotor->getGState(); // 读取状态,清空下复位标识
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
void StepMotorCtrlModule::create_default_cfg(config_t& cfg) { |
|
|
void StepMotorCtrlModule::create_default_cfg(config_t& cfg) { |
|
|
memset(&cfg, 0, sizeof(cfg)); |
|
|
memset(&cfg, 0, sizeof(cfg)); |
|
@ -64,7 +70,7 @@ int32_t StepMotorCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t |
|
|
case kreg_step_motor_iholddelay: |
|
|
case kreg_step_motor_iholddelay: |
|
|
case kreg_step_motor_max_d: |
|
|
case kreg_step_motor_max_d: |
|
|
case kreg_step_motor_min_d: |
|
|
case kreg_step_motor_min_d: |
|
|
step_motor_active_cfg(); |
|
|
|
|
|
|
|
|
return 0; |
|
|
} |
|
|
} |
|
|
return suc; |
|
|
return suc; |
|
|
} |
|
|
} |
|
@ -113,125 +119,6 @@ int32_t StepMotorCtrlModule::step_motor_stop(int32_t breakstop) { |
|
|
m_stepM1->stop(); |
|
|
m_stepM1->stop(); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
int32_t StepMotorCtrlModule::step_motor_easy_rotate(int32_t direction) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_rotate %d", m_id, direction); |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
if (!m_state.enable) { |
|
|
|
|
|
return err::kstep_motor_not_enable; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this, direction]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
m_stepM1->setAcceleration(m_cfg.motor_default_acc); |
|
|
|
|
|
m_stepM1->setDeceleration(m_cfg.motor_default_dec); |
|
|
|
|
|
|
|
|
|
|
|
int32_t vel = m_cfg.motor_default_velocity; |
|
|
|
|
|
if (direction <= 0) vel = -vel; |
|
|
|
|
|
m_stepM1->rotate(vel); |
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
|
|
if (!check_when_run()) break; |
|
|
|
|
|
vTaskDelay(5); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
after_motor_move(); |
|
|
|
|
|
}, |
|
|
|
|
|
[this]() { m_stepM1->stop(); }); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_to(int32_t tox) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_to %d", m_id, tox); |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
if (!m_state.enable) { |
|
|
|
|
|
return err::kstep_motor_not_enable; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m_cfg.min_d != 0 && tox < m_cfg.min_d) tox = m_cfg.min_d; |
|
|
|
|
|
if (m_cfg.max_d != 0 && tox > m_cfg.max_d) tox = m_cfg.max_d; |
|
|
|
|
|
|
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this, tox]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
m_stepM1->setAcceleration(m_cfg.motor_default_acc); |
|
|
|
|
|
m_stepM1->setDeceleration(m_cfg.motor_default_dec); |
|
|
|
|
|
int32_t motor_pos = 0; |
|
|
|
|
|
inter_forward_kinematics(tox, motor_pos); |
|
|
|
|
|
m_stepM1->moveTo(motor_pos, 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, tox]() { m_stepM1->stop(); }); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_by(int32_t distance) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_by %d", m_id, distance); |
|
|
|
|
|
int32_t motor_pos = 0; |
|
|
|
|
|
step_motor_read_pos(&motor_pos); |
|
|
|
|
|
motor_pos += distance; |
|
|
|
|
|
return step_motor_easy_move_to(motor_pos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_to_zero() { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_to_zero", m_id); |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
if (!m_state.enable) { |
|
|
|
|
|
return err::kstep_motor_not_enable; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m_nio == 0) { |
|
|
|
|
|
return err::kstep_motor_ioindex_out_of_range; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
exec_move_to_io_task(0, -1); |
|
|
|
|
|
after_motor_move(); |
|
|
|
|
|
m_stepM1->setXACTUAL(0); |
|
|
|
|
|
}, |
|
|
|
|
|
[this]() { m_stepM1->stop(); }); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_to_io %d %d", m_id, ioindex, direction); |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
if (!m_state.enable) { |
|
|
|
|
|
return err::kstep_motor_not_enable; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ioindex < 0 || ioindex >= m_nio) { |
|
|
|
|
|
return err::kstep_motor_ioindex_out_of_range; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this, ioindex, direction]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
exec_move_to_io_task(ioindex, direction); |
|
|
|
|
|
after_motor_move(); |
|
|
|
|
|
}, |
|
|
|
|
|
[this]() { m_stepM1->stop(); }); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_set_current_pos(int32_t pos) { |
|
|
int32_t StepMotorCtrlModule::step_motor_easy_set_current_pos(int32_t pos) { |
|
|
int32_t motor_pos = 0; |
|
|
int32_t motor_pos = 0; |
|
@ -263,6 +150,11 @@ int32_t StepMotorCtrlModule::step_motor_read_io_state(int32_t ioindex, int32_t* |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_read_motoric_status(int32_t* errorflag) { |
|
|
|
|
|
*errorflag = m_state.motorStatus; |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
|
* INTER * |
|
|
* INTER * |
|
|
***********************************************************************************************************************/ |
|
|
***********************************************************************************************************************/ |
|
@ -279,10 +171,12 @@ int StepMotorCtrlModule::inter_get_pos(int32_t& x) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
void StepMotorCtrlModule::befor_motor_move() { //
|
|
|
void StepMotorCtrlModule::befor_motor_move() { //
|
|
|
m_state.before_move_pos = m_stepM1->getXACTUAL(); |
|
|
|
|
|
creg.m_module_status = 1; |
|
|
|
|
|
creg.module_errorcode = 0; |
|
|
|
|
|
creg.module_errorbitflag0 = 0; |
|
|
|
|
|
|
|
|
m_state.before_move_pos = m_stepM1->getXACTUAL(); |
|
|
|
|
|
creg.m_module_status = 1; |
|
|
|
|
|
creg.module_errorcode = 0; |
|
|
|
|
|
|
|
|
|
|
|
step_motor_active_cfg(); |
|
|
|
|
|
m_stepM1->enable(1); |
|
|
} |
|
|
} |
|
|
void StepMotorCtrlModule::after_motor_move() { |
|
|
void StepMotorCtrlModule::after_motor_move() { |
|
|
m_state.after_move_pos = m_stepM1->getXACTUAL(); |
|
|
m_state.after_move_pos = m_stepM1->getXACTUAL(); |
|
@ -292,9 +186,53 @@ void StepMotorCtrlModule::after_motor_move() { |
|
|
} |
|
|
} |
|
|
creg.m_module_status = 0; |
|
|
creg.m_module_status = 0; |
|
|
} |
|
|
} |
|
|
bool StepMotorCtrlModule::check_when_run() { return true; } |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t direction) { |
|
|
|
|
|
|
|
|
void StepMotorCtrlModule::dumpTMC5130Status(TMC5130::DevStatusReg_t* status) { |
|
|
|
|
|
ZLOGE(TAG, "sg_result: %d", status->sg_result); |
|
|
|
|
|
ZLOGE(TAG, "fsactive: %d", status->fsactive); |
|
|
|
|
|
ZLOGE(TAG, "cs_actual: %d", status->cs_actual); |
|
|
|
|
|
ZLOGE(TAG, "stallguard: %d", status->stallguard); |
|
|
|
|
|
ZLOGE(TAG, "ot: %d", status->ot); |
|
|
|
|
|
ZLOGE(TAG, "otpw: %d", status->otpw); |
|
|
|
|
|
ZLOGE(TAG, "s2ga: %d", status->s2ga); |
|
|
|
|
|
ZLOGE(TAG, "s2gb: %d", status->s2gb); |
|
|
|
|
|
ZLOGE(TAG, "ola: %d", status->ola); |
|
|
|
|
|
ZLOGE(TAG, "olb: %d", status->olb); |
|
|
|
|
|
ZLOGE(TAG, "stst: %d", status->stst); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void StepMotorCtrlModule::setErrorFlag(int32_t ecode, uint32_t motorStatue) { |
|
|
|
|
|
creg.module_errorcode = ecode; |
|
|
|
|
|
m_state.motorStatus = motorStatue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool StepMotorCtrlModule::check_when_run() { |
|
|
|
|
|
//
|
|
|
|
|
|
TMC5130* tmc5130 = dynamic_cast<TMC5130*>(m_stepM1); |
|
|
|
|
|
if (tmc5130) { |
|
|
|
|
|
auto state = tmc5130->getGState(); |
|
|
|
|
|
auto devStatus = tmc5130->getDevStatus(); |
|
|
|
|
|
if (state.reset) { |
|
|
|
|
|
ZLOGE(TAG, "motor reset when run"); |
|
|
|
|
|
setErrorFlag(err::kstep_motor_subic_reset, (*(uint32_t*)&devStatus)); |
|
|
|
|
|
return false; |
|
|
|
|
|
} else if (state.uv_cp) { |
|
|
|
|
|
ZLOGE(TAG, "motor uv_cp when run"); |
|
|
|
|
|
dumpTMC5130Status(&devStatus); |
|
|
|
|
|
setErrorFlag(err::kstep_motor_uv_cp, (*(uint32_t*)&devStatus)); |
|
|
|
|
|
return false; |
|
|
|
|
|
} else if (state.drv_err) { |
|
|
|
|
|
ZLOGE(TAG, "motor drv_err when run"); |
|
|
|
|
|
setErrorFlag(err::kstep_motor_drv_err, (*(uint32_t*)&devStatus)); |
|
|
|
|
|
dumpTMC5130Status(&devStatus); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t direction) { |
|
|
int32_t runToPointSpeed = m_cfg.motor_run_to_zero_speed; |
|
|
int32_t runToPointSpeed = m_cfg.motor_run_to_zero_speed; |
|
|
int32_t runToPointDec = m_cfg.motor_run_to_zero_dec; |
|
|
int32_t runToPointDec = m_cfg.motor_run_to_zero_dec; |
|
|
|
|
|
|
|
@ -304,6 +242,7 @@ int32_t StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t direc |
|
|
direction = direction >= 0 ? 1 : -1; |
|
|
direction = direction >= 0 ? 1 : -1; |
|
|
|
|
|
|
|
|
ZGPIO* gpio = &m_iotable[ioindex]; |
|
|
ZGPIO* gpio = &m_iotable[ioindex]; |
|
|
|
|
|
if (!check_when_run()) return false; |
|
|
|
|
|
|
|
|
if (!gpio->getState()) { |
|
|
if (!gpio->getState()) { |
|
|
ZLOGI(TAG, "---------STEP1-------- move to point"); |
|
|
ZLOGI(TAG, "---------STEP1-------- move to point"); |
|
@ -328,10 +267,13 @@ int32_t StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t direc |
|
|
// 失败返回
|
|
|
// 失败返回
|
|
|
if (!xreach_io) { |
|
|
if (!xreach_io) { |
|
|
ZLOGE(TAG, "x reach io failed"); |
|
|
ZLOGE(TAG, "x reach io failed"); |
|
|
return err::kxymotor_not_found_x_zero_point; |
|
|
|
|
|
|
|
|
setErrorFlag(err::kstep_motor_not_found_zero_point, 0); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!check_when_run()) return false; |
|
|
|
|
|
|
|
|
// 如果设备已经在零点,则反向移动一定距离远离零点
|
|
|
// 如果设备已经在零点,则反向移动一定距离远离零点
|
|
|
if (gpio->getState()) { |
|
|
if (gpio->getState()) { |
|
|
ZLOGI(TAG, "---------STEP2-------- find edge"); |
|
|
ZLOGI(TAG, "---------STEP2-------- find edge"); |
|
@ -354,17 +296,20 @@ int32_t StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t direc |
|
|
|
|
|
|
|
|
if (!reach_edge) { |
|
|
if (!reach_edge) { |
|
|
ZLOGE(TAG, "leave away zero failed"); |
|
|
ZLOGE(TAG, "leave away zero failed"); |
|
|
return err::kxymotor_x_find_zero_edge_fail; |
|
|
|
|
|
|
|
|
setErrorFlag(err::kstep_motor_not_found_point_edge, 0); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!check_when_run()) return false; |
|
|
|
|
|
|
|
|
if (m_thread.getExitFlag()) { |
|
|
if (m_thread.getExitFlag()) { |
|
|
ZLOGI(TAG, "break move to zero thread exit"); |
|
|
|
|
|
return err::kmodule_opeation_break_by_user; |
|
|
|
|
|
|
|
|
ZLOGW(TAG, "break move to zero thread exit"); |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ZLOGI(TAG, "_exec_move_to_io_task_fn success"); |
|
|
ZLOGI(TAG, "_exec_move_to_io_task_fn success"); |
|
|
return 0; |
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void StepMotorCtrlModule::_rotate(int32_t vel, int32_t acc, int32_t dec) { |
|
|
void StepMotorCtrlModule::_rotate(int32_t vel, int32_t acc, int32_t dec) { |
|
@ -372,4 +317,172 @@ void StepMotorCtrlModule::_rotate(int32_t vel, int32_t acc, int32_t dec) { |
|
|
m_stepM1->setAcceleration(acc); |
|
|
m_stepM1->setAcceleration(acc); |
|
|
m_stepM1->setDeceleration(dec); |
|
|
m_stepM1->setDeceleration(dec); |
|
|
m_stepM1->rotate(vel); |
|
|
m_stepM1->rotate(vel); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
|
|
|
* 电机控制接口 * |
|
|
|
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::module_clear_error() { |
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief |
|
|
|
|
|
* 驱动器大部分的错误,在不重启的情况下,是无法清除的。module_clear_error这里不生效 |
|
|
|
|
|
*/ |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::check_befor_run() { |
|
|
|
|
|
if (!m_state.enable) { |
|
|
|
|
|
return err::kstep_motor_not_enable; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (creg.module_errorcode == err::kstep_motor_subic_reset) { |
|
|
|
|
|
return creg.module_errorcode; |
|
|
|
|
|
} else if (creg.module_errorcode == err::kstep_motor_drv_err) { |
|
|
|
|
|
return creg.module_errorcode; |
|
|
|
|
|
} else if (creg.module_errorcode == err::kstep_motor_uv_cp) { |
|
|
|
|
|
return creg.module_errorcode; |
|
|
|
|
|
} else { |
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 其他错误允许设备继续运行 |
|
|
|
|
|
*/ |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_rotate(int32_t direction) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_rotate %d", m_id, direction); |
|
|
|
|
|
|
|
|
|
|
|
int32_t ecode = check_befor_run(); |
|
|
|
|
|
if (ecode != 0) return ecode; |
|
|
|
|
|
|
|
|
|
|
|
return do_step_motor_easy_rotate(direction); |
|
|
|
|
|
} |
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_by(int32_t distance) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_by %d", m_id, distance); |
|
|
|
|
|
int32_t ecode = check_befor_run(); |
|
|
|
|
|
if (ecode != 0) return ecode; |
|
|
|
|
|
return do_step_motor_easy_move_by(distance); |
|
|
|
|
|
} |
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_to(int32_t tox) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_to %d", m_id, tox); |
|
|
|
|
|
int32_t ecode = check_befor_run(); |
|
|
|
|
|
if (ecode != 0) return ecode; |
|
|
|
|
|
|
|
|
|
|
|
return do_step_motor_easy_move_to(tox); |
|
|
|
|
|
} |
|
|
|
|
|
int32_t StepMotorCtrlModule::step_motor_easy_move_to_zero() { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_to_zero", m_id); |
|
|
|
|
|
int32_t ecode = check_befor_run(); |
|
|
|
|
|
if (ecode != 0) return ecode; |
|
|
|
|
|
|
|
|
|
|
|
if (m_nio == 0) { |
|
|
|
|
|
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) { |
|
|
|
|
|
ZLOGI(TAG, "m%d motor_move_to_io %d %d", m_id, ioindex, direction); |
|
|
|
|
|
|
|
|
|
|
|
int32_t ecode = check_befor_run(); |
|
|
|
|
|
if (ecode != 0) return ecode; |
|
|
|
|
|
|
|
|
|
|
|
if (ioindex < 0 || ioindex >= m_nio) { |
|
|
|
|
|
return err::kstep_motor_ioindex_out_of_range; |
|
|
|
|
|
} |
|
|
|
|
|
return do_step_motor_easy_move_to_io(ioindex, direction); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::do_step_motor_easy_rotate(int32_t direction) { |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this, direction]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
{ |
|
|
|
|
|
m_stepM1->setAcceleration(m_cfg.motor_default_acc); |
|
|
|
|
|
m_stepM1->setDeceleration(m_cfg.motor_default_dec); |
|
|
|
|
|
|
|
|
|
|
|
int32_t vel = m_cfg.motor_default_velocity; |
|
|
|
|
|
if (direction <= 0) vel = -vel; |
|
|
|
|
|
m_stepM1->rotate(vel); |
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
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_move_to(int32_t tox) { |
|
|
|
|
|
if (m_cfg.min_d != 0 && tox < m_cfg.min_d) tox = m_cfg.min_d; |
|
|
|
|
|
if (m_cfg.max_d != 0 && tox > m_cfg.max_d) tox = m_cfg.max_d; |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this, tox]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
m_stepM1->setAcceleration(m_cfg.motor_default_acc); |
|
|
|
|
|
m_stepM1->setDeceleration(m_cfg.motor_default_dec); |
|
|
|
|
|
int32_t motor_pos = 0; |
|
|
|
|
|
inter_forward_kinematics(tox, motor_pos); |
|
|
|
|
|
m_stepM1->moveTo(motor_pos, 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, tox]() { m_stepM1->stop(); }); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::do_step_motor_easy_move_by(int32_t distance) { |
|
|
|
|
|
int32_t motor_pos = 0; |
|
|
|
|
|
step_motor_read_pos(&motor_pos); |
|
|
|
|
|
motor_pos += distance; |
|
|
|
|
|
return step_motor_easy_move_to(motor_pos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_zero() { |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
exec_move_to_io_task(0, -1); |
|
|
|
|
|
after_motor_move(); |
|
|
|
|
|
m_stepM1->setXACTUAL(0); |
|
|
|
|
|
}, |
|
|
|
|
|
[this]() { m_stepM1->stop(); }); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) { |
|
|
|
|
|
m_thread.stop(); |
|
|
|
|
|
m_thread.start( |
|
|
|
|
|
[this, ioindex, direction]() { |
|
|
|
|
|
befor_motor_move(); |
|
|
|
|
|
exec_move_to_io_task(ioindex, direction); |
|
|
|
|
|
after_motor_move(); |
|
|
|
|
|
}, |
|
|
|
|
|
[this]() { m_stepM1->stop(); }); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |