Skip to content
Snippets Groups Projects
Commit 908bf85b authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

[Stepper] Added function to zero the position and fixed a bug

parent 79a931b5
Branches
Tags
No related merge requests found
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#pragma once
#include <interfaces-impl/gpio_impl.h> #include <interfaces-impl/gpio_impl.h>
#include <interfaces/delays.h> #include <interfaces/delays.h>
#include <utils/testutils/MockGpioPin.h> #include <utils/testutils/MockGpioPin.h>
...@@ -74,6 +76,12 @@ public: ...@@ -74,6 +76,12 @@ public:
*/ */
void setMicrostepping(Microstep microstep); void setMicrostepping(Microstep microstep);
/**
* @brief Zeros the driver's internal position.
*
*/
void zeroPosition();
/** /**
* @brief Move the stepper motor by the specified amount of steps. * @brief Move the stepper motor by the specified amount of steps.
*/ */
...@@ -184,6 +192,8 @@ inline void Stepper::setMicrostepping(Microstep microstep) ...@@ -184,6 +192,8 @@ inline void Stepper::setMicrostepping(Microstep microstep)
} }
} }
void Stepper::zeroPosition() { currentPosition = 0; }
inline void Stepper::move(int32_t steps) inline void Stepper::move(int32_t steps)
{ {
if (speed == 0) if (speed == 0)
...@@ -229,7 +239,7 @@ inline uint32_t Stepper::getCurrentPosition() { return currentPosition; } ...@@ -229,7 +239,7 @@ inline uint32_t Stepper::getCurrentPosition() { return currentPosition; }
inline float Stepper::getCurrentDegPosition() inline float Stepper::getCurrentDegPosition()
{ {
return currentPosition * stepAngle; return currentPosition * stepAngle / getMicrosteppingValue();
} }
inline int Stepper::getMicrosteppingValue() inline int Stepper::getMicrosteppingValue()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment