From 5d816689f151633f924c959945fd87ca7d26a259 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 30 Jul 2023 21:19:17 +0800 Subject: [PATCH] update --- .../iflytop_can_slave_protocol.hpp | 1 + .../single_axis_motor_control.cpp | 63 +++++++++++----------- .../single_axis_motor_control.hpp | 22 ++++---- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/components/iflytop_can_slave_v1/iflytop_can_slave_protocol.hpp b/components/iflytop_can_slave_v1/iflytop_can_slave_protocol.hpp index 3be4176..5e5d5e6 100644 --- a/components/iflytop_can_slave_v1/iflytop_can_slave_protocol.hpp +++ b/components/iflytop_can_slave_v1/iflytop_can_slave_protocol.hpp @@ -148,6 +148,7 @@ class Reg_t { bool is(reg_flag_t flag) { return mask & flag; } int32_t getValue() { return value; } + icps::error_t setVal(int32_t v) { return setValue(v); } icps::error_t setValue(int32_t v) { if (is(klimit)) { if (v < min) diff --git a/components/single_axis_motor_control/single_axis_motor_control.cpp b/components/single_axis_motor_control/single_axis_motor_control.cpp index b5dc08c..bee2c2e 100644 --- a/components/single_axis_motor_control/single_axis_motor_control.cpp +++ b/components/single_axis_motor_control/single_axis_motor_control.cpp @@ -36,18 +36,17 @@ void SingleAxisMotorControler::initialize(const char* name, IflytopCanProtocolSt m_currentPosReg = m_processer->activeReg(m_slave, SAMC_REG_STAT_CURRENT_POS, icps::kwr, 0); m_exceptionReg = m_processer->activeReg(m_slave, SAMC_REG_STAT_EXCEPTION, icps::kwr, 0); - cfg_acc_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_ACC, icps::kwr, 0); - cfg_dec_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_DEC, icps::kwr, 0); - cfg_velocity_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_VELOCITY, icps::kwr, 0); - cfg_zero_shift_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_ZERO_SHIFT, icps::kwr, 0); // 零点偏移 - cfg_runhome_velocity_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNHOME_VELOCITY, icps::kwr, 0); // 归零速度 - cfg_runtohome_dec_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_DEC, icps::kwr, 0); // 归零减速度 - cfg_runtohome_max_distance_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_MAX_DISTANCE, icps::kwr, 0); // 归零最大距离 - cfg_runtohome_leave_zero_point_distance_reg = - m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_LEAVE_ZERO_POINT_DISTANCE, icps::kwr, 0); // 离开零点距离 - cfg_min_pos_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_MIN_POS, icps::kwr, 0); // 最小位置 - cfg_max_pos_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_MAX_POS, icps::kwr, 0); // 最大位置 - cfg_runtohome_keep_move_distance_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_KEEP_MOVE_DISTANCE, icps::kwr, 0); // 归零阶段1移动距离 + cfg_acc = m_processer->activeReg(m_slave, SAMC_REG_CFG_ACC, icps::kwr, 0); + cfg_dec = m_processer->activeReg(m_slave, SAMC_REG_CFG_DEC, icps::kwr, 0); + cfg_velocity = m_processer->activeReg(m_slave, SAMC_REG_CFG_VELOCITY, icps::kwr, 0); + cfg_zero_shift = m_processer->activeReg(m_slave, SAMC_REG_CFG_ZERO_SHIFT, icps::kwr, 0); // 零点偏移 + cfg_runhome_velocity = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNHOME_VELOCITY, icps::kwr, 0); // 归零速度 + cfg_runtohome_dec = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_DEC, icps::kwr, 0); // 归零减速度 + cfg_runtohome_max_distance = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_MAX_DISTANCE, icps::kwr, 0); // 归零最大距离 + cfg_runtohome_leave_zero_point_distance = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_LEAVE_ZERO_POINT_DISTANCE, icps::kwr, 0); // 离开零点距离 + cfg_min_pos = m_processer->activeReg(m_slave, SAMC_REG_CFG_MIN_POS, icps::kwr, 0); // 最小位置 + cfg_max_pos = m_processer->activeReg(m_slave, SAMC_REG_CFG_MAX_POS, icps::kwr, 0); // 最大位置 + cfg_runtohome_keep_move_distance = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_KEEP_MOVE_DISTANCE, icps::kwr, 0); // 归零阶段1移动距离 } icps::error_t SingleAxisMotorControler::onHostRegisterWriteEvent(icps::WriteEvent* event) { @@ -88,7 +87,7 @@ icps::error_t SingleAxisMotorControler::rotate(int32_t velocity) { m_step_scheduler.reset(); m_step_scheduler.pushActionAction([this, velocity](StepActionContext* context) { // - motor_rotate(velocity, cfg_acc_reg->getValue(), cfg_dec_reg->getValue()); + motor_rotate(velocity, cfg_acc->getValue(), cfg_dec->getValue()); }); m_step_scheduler.pushActionIsDone([](StepActionContext* context) { return false; }); m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); @@ -104,7 +103,7 @@ icps::error_t SingleAxisMotorControler::moveTo(int32_t pos) { m_step_scheduler.reset(); m_step_scheduler.pushActionAction([this, pos](StepActionContext* context) { // - motor_moveTo(pos, cfg_velocity_reg->getValue(), cfg_acc_reg->getValue(), cfg_dec_reg->getValue()); + motor_moveTo(pos, cfg_velocity->getValue(), cfg_acc->getValue(), cfg_dec->getValue()); }); m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); @@ -121,7 +120,7 @@ icps::error_t SingleAxisMotorControler::moveBy(int32_t pos) { m_step_scheduler.reset(); m_step_scheduler.pushActionAction([this, pos](StepActionContext* context) { // - motor_moveBy(pos, cfg_velocity_reg->getValue(), cfg_acc_reg->getValue(), cfg_dec_reg->getValue()); + motor_moveBy(pos, cfg_velocity->getValue(), cfg_acc->getValue(), cfg_dec->getValue()); }); m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); @@ -149,10 +148,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { m_motor->stop(); }); - motor_moveBy(-cfg_runtohome_max_distance_reg->getValue(), // - cfg_runhome_velocity_reg->getValue() * 2, // - cfg_acc_reg->getValue(), // - cfg_runtohome_dec_reg->getValue()); + motor_moveBy(-cfg_runtohome_max_distance->getValue(), // + cfg_runhome_velocity->getValue() * 2, // + cfg_acc->getValue(), // + cfg_runtohome_dec->getValue()); }); m_step_scheduler.pushActionIsDone([this](StepActionContext* context) { if (motorIsStop(context)) { @@ -173,10 +172,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { */ m_step_scheduler.pushActionAction([this](StepActionContext* context) { // regGpioIrqProcesser(nullptr); - motor_moveBy(cfg_runtohome_leave_zero_point_distance_reg->getValue(), // - cfg_runhome_velocity_reg->getValue(), // - cfg_acc_reg->getValue(), // - cfg_dec_reg->getValue()); // 此时处于零点位置,先离开原点一定位置 + motor_moveBy(cfg_runtohome_leave_zero_point_distance->getValue(), // + cfg_runhome_velocity->getValue(), // + cfg_acc->getValue(), // + cfg_dec->getValue()); // 此时处于零点位置,先离开原点一定位置 }); m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); @@ -190,10 +189,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { m_runToHomeContext.zeroPointPos = m_motor->getXACTUAL(); m_motor->stop(); }); - motor_moveBy(-cfg_runtohome_leave_zero_point_distance_reg->getValue() * 1.5, // - cfg_runhome_velocity_reg->getValue(), // - cfg_acc_reg->getValue(), // - cfg_runtohome_dec_reg->getValue()); // 此时处于零点位置,先离开原点一定位置 + motor_moveBy(-cfg_runtohome_leave_zero_point_distance->getValue() * 1.5, // + cfg_runhome_velocity->getValue(), // + cfg_acc->getValue(), // + cfg_runtohome_dec->getValue()); // 此时处于零点位置,先离开原点一定位置 }); m_step_scheduler.pushActionIsDone([this](StepActionContext* context) { if (motorIsStop(context)) { @@ -211,7 +210,7 @@ icps::error_t SingleAxisMotorControler::runToHome() { int32_t nowposition = m_motor->getXACTUAL(); int32_t nowposition_real = nowposition - m_runToHomeContext.zeroPointPos; ZLOGI(m_name, "nowposition:%d,zeroPointPosition:%d", nowposition, m_runToHomeContext.zeroPointPos); - m_motor->setXACTUAL(nowposition_real - cfg_zero_shift_reg->getValue()); + m_motor->setXACTUAL(nowposition_real - cfg_zero_shift->getValue()); }); /** @@ -219,10 +218,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { */ m_step_scheduler.pushActionAction([this](StepActionContext* context) { // regGpioIrqProcesser(nullptr); - motor_moveTo(0, // - cfg_runhome_velocity_reg->getValue(), // - cfg_acc_reg->getValue(), // - cfg_dec_reg->getValue()); // 此时处于零点位置,先离开原点一定位置 + motor_moveTo(0, // + cfg_runhome_velocity->getValue(), // + cfg_acc->getValue(), // + cfg_dec->getValue()); // 此时处于零点位置,先离开原点一定位置 }); m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); diff --git a/components/single_axis_motor_control/single_axis_motor_control.hpp b/components/single_axis_motor_control/single_axis_motor_control.hpp index ad28c7f..9e8eff2 100644 --- a/components/single_axis_motor_control/single_axis_motor_control.hpp +++ b/components/single_axis_motor_control/single_axis_motor_control.hpp @@ -91,17 +91,17 @@ class SingleAxisMotorControler : public ICPSListener { ZGPIO::onirq_t m_gpioirqprocesser; public: - icps::Reg_t* cfg_acc_reg; - icps::Reg_t* cfg_dec_reg; - icps::Reg_t* cfg_velocity_reg; - icps::Reg_t* cfg_zero_shift_reg; - icps::Reg_t* cfg_runhome_velocity_reg; - icps::Reg_t* cfg_runtohome_dec_reg; - icps::Reg_t* cfg_runtohome_max_distance_reg; - icps::Reg_t* cfg_runtohome_leave_zero_point_distance_reg; - icps::Reg_t* cfg_min_pos_reg; - icps::Reg_t* cfg_max_pos_reg; - icps::Reg_t* cfg_runtohome_keep_move_distance_reg; + icps::Reg_t* cfg_acc; + icps::Reg_t* cfg_dec; + icps::Reg_t* cfg_velocity; + icps::Reg_t* cfg_zero_shift; + icps::Reg_t* cfg_runhome_velocity; + icps::Reg_t* cfg_runtohome_dec; + icps::Reg_t* cfg_runtohome_max_distance; + icps::Reg_t* cfg_runtohome_leave_zero_point_distance; + icps::Reg_t* cfg_min_pos; + icps::Reg_t* cfg_max_pos; + icps::Reg_t* cfg_runtohome_keep_move_distance; public: SingleAxisMotorControler(){};