Skip to content

Commit

Permalink
Add acceleration() getter
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Jan 28, 2024
1 parent 2e359b8 commit e8adfd5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
ContinuousStepper: changelog
============================

HEAD
----

* Add `acceleration()` getter

3.0.2
-----

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public:
// Call isSpinning() to know when the motion is complete.
void stop();

// Gets the acceleration in steps/s².
float_t acceleration() const;

// Returns the current speed.
// During accelerations and decelerations, this value differs from the
// target speed configured with spin().
Expand Down
1 change: 1 addition & 0 deletions extras/tests/ContinuousStepperTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_executable(ContinuousStepperTests
acceleration.cpp
begin.cpp
powerOff.cpp
powerOn.cpp
Expand Down
24 changes: 24 additions & 0 deletions extras/tests/ContinuousStepperTests/acceleration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <ContinuousStepper.h>
#include <TestFixtures.hpp>

TEST_CASE("ContinuousStepper<StepperDriver>::acceleration()") {
ContinuousStepper<StepperDriver> stepper;

GIVEN("setAcceleration() was NOT called") {
WHEN("acceleration() is called") {
THEN("it should return the default acceleration") {
CHECK(stepper.acceleration() == 1000);
}
}
}

GIVEN("setAcceleration(10) was called") {
stepper.setAcceleration(10);

WHEN("acceleration() is called") {
THEN("it should return 10") {
CHECK(stepper.acceleration() == 10);
}
}
}
}
4 changes: 4 additions & 0 deletions src/ContinuousStepper/ContinuousStepperImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class ContinuousStepperImpl : public TTicker, TickListener, public TStepper, Ste
targetSpeed_ = 0;
}

float_t acceleration() const {
return acceleration_;
}

float_t speed() const {
return currentSpeed_;
}
Expand Down

0 comments on commit e8adfd5

Please sign in to comment.