From 16ccc17d6d41154562af9294f49c5545cedaea00 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 10 Sep 2024 20:25:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B0=E5=AF=8CmoveToEnd=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tmcdriver/tmc51x0/tmc51x0.cpp | 8 +++++++- tmcdriver/tmc51x0/tmc51x0.hpp | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tmcdriver/tmc51x0/tmc51x0.cpp b/tmcdriver/tmc51x0/tmc51x0.cpp index 6041775..4131cba 100644 --- a/tmcdriver/tmc51x0/tmc51x0.cpp +++ b/tmcdriver/tmc51x0/tmc51x0.cpp @@ -213,7 +213,7 @@ void TMC51X0::stop() { } else { rotate(0); } - + m_isMoveToEnd = false; // rotate(0); } void TMC51X0::rotate(int32_t velocity) { @@ -222,6 +222,7 @@ void TMC51X0::rotate(int32_t velocity) { velocity = to_motor_vel(velocity); writeInt(TMC5130_VMAX, abs(velocity)); writeInt(TMC5130_RAMPMODE, (velocity >= 0) ? TMC5130_MODE_VELPOS : TMC5130_MODE_VELNEG); + m_isMoveToEnd = false; } void TMC51X0::moveTo(int32_t position, uint32_t velocityMax) { zlock_guard lkg(m_mutex); @@ -231,6 +232,7 @@ void TMC51X0::moveTo(int32_t position, uint32_t velocityMax) { writeInt(TMC5130_RAMPMODE, TMC5130_MODE_POSITION); writeInt(TMC5130_VMAX, velocityMax); writeInt(TMC5130_XTARGET, position); + m_isMoveToEnd = false; } void TMC51X0::moveToEnd(int32_t direction, uint32_t velocityMax) { zlock_guard lkg(m_mutex); @@ -248,8 +250,12 @@ void TMC51X0::moveToEnd(int32_t direction, uint32_t velocityMax) { writeInt(TMC5130_VMAX, to_motor_vel(velocityMax)); writeInt(TMC5130_XTARGET, INT32_MIN / 1.5 + 1000); } + m_isMoveToEnd = true; } +void TMC51X0::refreshMoveToEnd() { setXACTUAL(0); } +bool TMC51X0::isMoveToEnd() { return m_isMoveToEnd; } + void TMC51X0::moveBy(int32_t relativePosition, uint32_t velocityMax) { // determine actual position and add numbers of ticks to move zlock_guard lkg(m_mutex); diff --git a/tmcdriver/tmc51x0/tmc51x0.hpp b/tmcdriver/tmc51x0/tmc51x0.hpp index 02aefe2..a862dfa 100644 --- a/tmcdriver/tmc51x0/tmc51x0.hpp +++ b/tmcdriver/tmc51x0/tmc51x0.hpp @@ -6,8 +6,8 @@ #include // -#include "../tmc/tmc_type.h" #include "../tmc/tmc_reg_cache.hpp" +#include "../tmc/tmc_type.h" #include "reg/TMC5130_Type.h" #include "stm32basic/stm32basic.hpp" namespace iflytop { @@ -25,7 +25,6 @@ class TMC51X0Cfg { TMC51X0Cfg() {} }; - class TMC51X0 { protected: TMC51X0Cfg m_cfg; @@ -42,8 +41,9 @@ class TMC51X0 { double m_onecirclepulse = 51200; int32_t m_enc_resolution = 0; // - zmutex m_mutex = {"TMC51X0"}; - bool m_driErr = false; + zmutex m_mutex = {"TMC51X0"}; + bool m_driErr = false; + bool m_isMoveToEnd = false; public: void initialize(int mid, TMC51X0Cfg cfg); @@ -69,6 +69,8 @@ class TMC51X0 { void rotate(int32_t velocity); void moveTo(int32_t position, uint32_t velocityMax); void moveToEnd(int32_t direction, uint32_t velocityMax); + void refreshMoveToEnd(); + bool isMoveToEnd(); void moveBy(int32_t relativePosition, uint32_t velocityMax); void stop(); /***********************************************************************************************************************