From cfac84c0be585e819e53aebae6c76a6606ea8e24 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 8 Apr 2024 14:56:20 +0800 Subject: [PATCH] update --- components/step_motor_ctrl_module/tmc51x0_motor.cpp | 4 ++++ components/tmc/ic/ztmc5130.cpp | 4 +++- components/tmc/ic/ztmc5130.hpp | 6 ++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/components/step_motor_ctrl_module/tmc51x0_motor.cpp b/components/step_motor_ctrl_module/tmc51x0_motor.cpp index 3861a1f..d5f4fe3 100644 --- a/components/step_motor_ctrl_module/tmc51x0_motor.cpp +++ b/components/step_motor_ctrl_module/tmc51x0_motor.cpp @@ -164,6 +164,7 @@ int32_t TMC51X0Motor::move_to_zero(action_cb_status_t status_cb) { int32_t erro = _exec_move_to_zero_task(dx); if (erro == 0) { m_stepM1->setXACTUAL(0); + m_stepM1->setENCVAL(0); } call_exec_status_cb(erro, status_cb); }, @@ -193,6 +194,8 @@ int32_t TMC51X0Motor::move_to_zero_with_calibrate(int32_t nowx, action_cb_status m_param.motor_shift = calibrate_x; m_stepM1->setXACTUAL(0); + m_stepM1->setENCVAL(0); + call_exec_status_cb(erro, status_cb); return; }); @@ -615,6 +618,7 @@ int32_t TMC51X0Motor::motor_calculated_pos_by_move_to_zero() { m_com_reg.module_last_cmd_exec_status = erro; set_last_exec_status(erro, -dx + m_param.motor_shift); m_stepM1->setXACTUAL(0); + m_stepM1->setENCVAL(0); } }, [this]() { _motor_stop(); }); diff --git a/components/tmc/ic/ztmc5130.cpp b/components/tmc/ic/ztmc5130.cpp index 0e74633..33335ca 100644 --- a/components/tmc/ic/ztmc5130.cpp +++ b/components/tmc/ic/ztmc5130.cpp @@ -141,7 +141,9 @@ uint8_t TMC5130::reset() { } int32_t TMC5130::getXACTUAL() { return to_user_pos(readInt(TMC5130_XACTUAL)); } -void TMC5130::setXACTUAL(int32_t value) { writeInt(TMC5130_XACTUAL, to_motor_pos(value)); } +void TMC5130::setXACTUAL(int32_t value) { writeInt(TMC5130_XACTUAL, to_motor_pos(value)); } +void TMC5130::setENCVAL(int32_t val) { writeInt(TMC5130_XENC, to_motor_pos(val)); } + int32_t TMC5130::getVACTUAL() { return to_user_pos(readInt(TMC5130_VACTUAL)); } int32_t TMC5130::getENCVAL() { return to_user_pos(readInt(TMC5130_XENC)); } diff --git a/components/tmc/ic/ztmc5130.hpp b/components/tmc/ic/ztmc5130.hpp index 900a7cb..2d1c30c 100644 --- a/components/tmc/ic/ztmc5130.hpp +++ b/components/tmc/ic/ztmc5130.hpp @@ -112,9 +112,11 @@ class TMC5130 : public IStepperMotor { uint32_t readICVersion(); // 5130:0x11 5160:0x30 virtual int32_t getXACTUAL(); // 读取电机当前位置,与编码器的位置值不同,该值是电机在不丢步的情况下的位置 virtual void setXACTUAL(int32_t value); // 设置电机当前位置,与编码器的位置值不同,该值是电机在不丢步的情况下的位置 + void setENCVAL(int32_t val); - virtual int32_t getVACTUAL(); // 读取电机当前位置,与编码器的位置值不同,该值是电机在不丢步的情况下的位置 - virtual int32_t getENCVAL(); // + + virtual int32_t getVACTUAL(); // 读取电机当前位置,与编码器的位置值不同,该值是电机在不丢步的情况下的位置 + virtual int32_t getENCVAL(); // uint32_t readXTARGET(); // 读取驱动器目标位置 virtual int32_t getENC_POS() { return 0; } // TODO impl it