From a39ee1ce5ab526faf67d0cdbb23276ffc0595b75 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 25 Sep 2023 10:23:20 +0800 Subject: [PATCH] update --- components/tmc/basic/tmc_ic_interface.hpp | 9 ++++----- components/tmc/helpers/Config.h | 4 ++-- components/tmc/ic/tmc_driver_ic.hpp | 1 - components/tmc/ic/ztmc4361A.hpp | 27 +++++++++++---------------- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/components/tmc/basic/tmc_ic_interface.hpp b/components/tmc/basic/tmc_ic_interface.hpp index f8c2d2f..f2fdf22 100644 --- a/components/tmc/basic/tmc_ic_interface.hpp +++ b/components/tmc/basic/tmc_ic_interface.hpp @@ -3,11 +3,6 @@ namespace iflytop { using namespace std; class IStepperMotor; -// class MotorEventListener { -// public: -// virtual void onEvent(IStepperMotor* motor, StepperMotorEvent event) = 0; -// }; - class IStepperMotor { public: IStepperMotor() {} @@ -57,8 +52,12 @@ class IStepperMotor { virtual void setAcceleration(float accelerationpps2) = 0; // 设置最大加速度 virtual void setDeceleration(float accelerationpps2) = 0; // 设置最大减速度 + virtual void setMotorShaft(bool reverse) = 0; + virtual bool isReachTarget() = 0; virtual bool isStoped() = 0; + + virtual void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) = 0; }; } // namespace iflytop \ No newline at end of file diff --git a/components/tmc/helpers/Config.h b/components/tmc/helpers/Config.h index 2257961..4e8fdfb 100644 --- a/components/tmc/helpers/Config.h +++ b/components/tmc/helpers/Config.h @@ -30,8 +30,8 @@ typedef struct ConfigState state; uint8_t configIndex; int32_t shadowRegister[TMC_REGISTER_COUNT]; - uint8_t (*reset) (void); // tmc-ic 涓嶄細璋冪敤杩欎袱涓柟娉 by:zhaohe - uint8_t (*restore) (void); // tmc-ic 涓嶄細璋冪敤杩欎袱涓柟娉 by:zhaohe + uint8_t (*reset) (void); // tmc-ic 不会调用这两个方法 by:zhaohe + uint8_t (*restore) (void); // tmc-ic 不会调用这两个方法 by:zhaohe tmc_callback_config callback; uint8_t channel; } ConfigurationTypeDef; diff --git a/components/tmc/ic/tmc_driver_ic.hpp b/components/tmc/ic/tmc_driver_ic.hpp index c6105eb..834f9e4 100644 --- a/components/tmc/ic/tmc_driver_ic.hpp +++ b/components/tmc/ic/tmc_driver_ic.hpp @@ -39,7 +39,6 @@ class TMCDriverICInterface { virtual void enableIC(bool enable) = 0; virtual void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) = 0; - // register access virtual void writeDatagram(uint8_t address, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4) = 0; virtual void writeInt(uint8_t address, int32_t value) = 0; diff --git a/components/tmc/ic/ztmc4361A.hpp b/components/tmc/ic/ztmc4361A.hpp index e1218e7..0a66a98 100644 --- a/components/tmc/ic/ztmc4361A.hpp +++ b/components/tmc/ic/ztmc4361A.hpp @@ -8,7 +8,6 @@ #include "../basic/tmc_ic_interface.hpp" #include "sdk/os/zos.hpp" - #include "tmc_driver_ic.hpp" extern "C" { #include "TMC2160\TMC2160.h" @@ -68,15 +67,15 @@ class TMC4361A : public IStepperMotor { TMC4361A(/* args */); /******************************************************************************* - * 初始化相关方?? * + * 初始化相关方 * *******************************************************************************/ /** * @brief 静态方法,创建默认的TMC4361A配置参数,使用时只需修改自己需要的参数即可 * * 注意: - * 1. 该方法内部使用的是一个静态变量,所以每次调用该方法时,返回的都是同一个对象的地址?? - * 2. 该方法返回的数值不需要被释放?? + * 1. 该方法内部使用的是一个静态变量,所以每次调用该方法时,返回的都是同一个对象的地址 + * 2. 该方法返回的数值不需要被释放 * @param config */ @@ -99,22 +98,22 @@ class TMC4361A : public IStepperMotor { virtual void setAcceleration(float accelerationpps2); // 设置最大加速度 virtual void setDeceleration(float accelerationpps2); // 设置最大减速度 + virtual void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { driverIC_setIHOLD_IRUN(ihold, irun, iholddelay); } + virtual void setMotorShaft(bool reverse) { driverIC_setMotorShaft(reverse); } + /******************************************************************************* * 驱动器初始化方法 * *******************************************************************************/ /** - * @brief 初始化方?? + * @brief 初始化方 * - * @param channel SPI通道?? - * @param driver_ic_type 驱动芯片的类?? + * @param channel SPI通道 + * @param driver_ic_type 驱动芯片的类 */ int32_t readICVersion(); uint8_t reset(); uint8_t restore(); /******************************************************************************* - * 常用寄存器读写方?? * - *******************************************************************************/ - /******************************************************************************* * 驱动器寄存器读写方法 * *******************************************************************************/ void writeDatagram(uint8_t address, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4); @@ -123,8 +122,8 @@ class TMC4361A : public IStepperMotor { void readWriteCover(uint8_t *data, size_t length); void writeSubRegister(uint8_t address, uint32_t mask, uint32_t shift, uint32_t value); - int32_t getENC_POS_DEV(); // ENC_POS和XACTUAL的偏差?? - uint32_t readEVENTS(); // 读取事件寄存?? + int32_t getENC_POS_DEV(); // ENC_POS和XACTUAL的偏差 + uint32_t readEVENTS(); // 读取事件寄存 /******************************************************* * driverIc function * *******************************************************/ @@ -137,12 +136,8 @@ class TMC4361A : public IStepperMotor { void tmc4361AConfigCallback(ConfigState state); void readWriteArray(uint8_t *data, size_t length); - void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { driverIC_setIHOLD_IRUN(ihold, irun, iholddelay); } - void setMotorShaft(bool reverse) { driverIC_setMotorShaft(reverse); } - private: uint32_t haspassedms(uint32_t now, uint32_t last); - // void callOnEventCallback(StepperMotorEvent event); void driverIC_reset(); void driverIC_enableIC(bool enable);