Skip to content

Commit

Permalink
Add stepsToStop() for issue #274
Browse files Browse the repository at this point in the history
  • Loading branch information
gin66 committed Jul 13, 2024
1 parent ead3ee5 commit a057c3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TODO:
pre-0.30.16:
- Fix missing parenthesis in preprocessor macro (#271)
- Position parameter for `forceStopAndNewPosition()` changed from `uint32_t` to `int32_t` (#268)
- Add `stepsToStop()` to predict motor stop position

0.30.15:
- Fix missing initialization in `getCurrentSpeedInTicks()` (#262)
Expand Down
15 changes: 15 additions & 0 deletions src/FastAccelStepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,21 @@ class FastAccelStepper {
void stopMove();
inline bool isStopping() { return _rg.isStopping(); }

// ### stepsToStop()
// This returns the current step value of the ramp.
// This equals the number of steps for a motor to
// reach the current position and speed from standstill
// and to come to standstill with deceleration if stopped
// immediately.
// This value is valid with or without linear acceleration
// being used.
// Primary use is to forecast possible stop position.
// The stop position is:
// getCurrentPosition() + stepsToStop()
// in case of a motor running in positive direction.
uint32_t stepsToStop() { return _rg.stepsToStop(); }


// ### forceStop()
// Abruptly stop the running stepper without deceleration.
// This can be called from an interrupt !
Expand Down
7 changes: 6 additions & 1 deletion src/RampGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ class RampGenerator {
return _ro.isStopInitiated() && isRampGeneratorActive();
}
inline bool isRampGeneratorActive() { return rampState() != RAMP_STATE_IDLE; }

inline uint32_t stepsToStop() {
fasDisableInterrupts();
uint32_t v = _rw.performed_ramp_up_steps;
fasEnableInterrupts();
return v;
}
inline void stopRamp() { _rw.stopRamp(); }
inline void setKeepRunning() { _ro.setKeepRunning(); }
inline bool isRunningContinuously() { return _ro.isRunningContinuously(); }
Expand Down

0 comments on commit a057c3e

Please sign in to comment.