From 147006090edd19ab50f0d20e887bbe51d80c2453 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 5 Nov 2023 19:11:25 +0800 Subject: [PATCH] update --- .../step_motor_ctrl_module.hpp | 3 +++ components/tmc/basic/tmc_ic_interface.hpp | 2 ++ components/tmc/ic/ztmc5130.cpp | 27 ++++++++++++++++++---- components/tmc/ic/ztmc5130.hpp | 5 ++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp index bbfa647..4bdd98f 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp @@ -163,6 +163,9 @@ class StepMotorCtrlModule : public I_StepMotorCtrlModule, public ZIModule, publi virtual int32_t motor_easy_move_to(int32_t position) override; virtual int32_t motor_easy_move_to_zero(int32_t direction) override; + IStepperMotor* _getStepMotor() { return m_stepM1; } + base_param_t& _get_base_param() { return m_param; } + private: void active_cfg(); diff --git a/components/tmc/basic/tmc_ic_interface.hpp b/components/tmc/basic/tmc_ic_interface.hpp index 793ba54..0bf0ba5 100644 --- a/components/tmc/basic/tmc_ic_interface.hpp +++ b/components/tmc/basic/tmc_ic_interface.hpp @@ -63,6 +63,8 @@ class IStepperMotor { virtual void setScaleDenominator(int32_t scale) = 0; virtual void enable(bool enable) = 0; + + virtual void setNoAccLimit(bool enable){}; }; } // namespace iflytop \ No newline at end of file diff --git a/components/tmc/ic/ztmc5130.cpp b/components/tmc/ic/ztmc5130.cpp index fe91cfa..70aa154 100644 --- a/components/tmc/ic/ztmc5130.cpp +++ b/components/tmc/ic/ztmc5130.cpp @@ -10,7 +10,7 @@ using namespace iflytop; * @brief 静态方法,创建默认的TMC5130配置参数,使用时只需修改自己需要的参数即可 * * 注意: - * 1. 该方法内部使用的是一个静态变量,所以每次调用该方法时,返回的都是同一个对象的地址?? + * 1. 该方法内部使用的是个静态变量,所以每次调用该方法时,返回的都是同一个对象的地址?? * 2. 该方法返回的数值不需要被释放?? * @param config */ @@ -62,13 +62,19 @@ void TMC5130::initialize(cfg_t *cfg) { writeInt(TMC5130_XACTUAL, 0x00000000); writeInt(TMC5130_VACTUAL, 0x00000000); - writeInt(TMC5130_VSTART, 5); + + writeInt(TMC5130_VSTART, 100); writeInt(TMC5130_A1, 1000); writeInt(TMC5130_V1, 0); writeInt(TMC5130_D1, 1000); - writeInt(TMC5130_VSTOP, 10); - writeInt(TMC5130_TZEROWAIT, 1000); + writeInt(TMC5130_VSTOP, 100); + writeInt(TMC5130_TZEROWAIT, 0); + + // writeInt(TMC5130_VSTART, 100); + // writeInt(TMC5130_V1, 0); + // writeInt(TMC5130_VSTOP, 100); + // writeInt(TMC5130_TZEROWAIT, 0); setAcceleration(100); setDeceleration(100); @@ -76,6 +82,16 @@ void TMC5130::initialize(cfg_t *cfg) { enableIC(true); } +void TMC5130::setNoAccLimit(bool enable) { + if (!enable) { + writeInt(TMC5130_VSTART, 100); + writeInt(TMC5130_VSTOP, 100); + } else { + writeInt(TMC5130_VSTART, 262144 - 1); // 2^18-1 + writeInt(TMC5130_VSTOP, 262144 - 1); // 2^18-1 + } +} + void TMC5130::enableIC(bool enable) { // m_port->TMC5130Port_setENNPinState(m_channel, !enable); SET_PIN(m_ennpin, !enable); @@ -211,7 +227,8 @@ int32_t TMC5130::readInt(uint8_t address) { return ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | (data[3] << 8) | data[4]; } int32_t TMC5130::to_motor_acc(int32_t acc) { // - int32_t val = acc / 60.0 * 51200; + int32_t val = acc / 60.0 * 51200; // 65535 + // if (val > 65535) val = 65535; return val; } int32_t TMC5130::to_motor_vel(int32_t vel) { // diff --git a/components/tmc/ic/ztmc5130.hpp b/components/tmc/ic/ztmc5130.hpp index e5e3dc8..8676311 100644 --- a/components/tmc/ic/ztmc5130.hpp +++ b/components/tmc/ic/ztmc5130.hpp @@ -91,6 +91,8 @@ class TMC5130 : public IStepperMotor { int32_t m_scale = 10000; int32_t m_scale_deceleration = 1; + // int32_t m_subdivision = 256; + public: TMC5130(/* args */); @@ -123,6 +125,7 @@ class TMC5130 : public IStepperMotor { virtual void setDeceleration(float accelerationpps2); void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay); + // void setSubdivision(uint8_t subdivision); void setMotorShaft(bool reverse); // 设置电机旋转方向 @@ -149,6 +152,8 @@ class TMC5130 : public IStepperMotor { void writeInt(uint8_t address, int32_t value); int32_t readInt(uint8_t address); + void setNoAccLimit(bool enable) override; + private: uint32_t haspassedms(uint32_t now, uint32_t last);