Derivs Limiter
|
This library can be used to limit the first and second derivative of a variable as it approaches a target value. https://github.com/joshua-8/Derivs_Limiter. More...
#include <Derivs_Limiter.h>
Public Member Functions | |
Derivs_Limiter (float _velLimit, float _accelLimit, float _decelLimit=NAN, float _target=0, float _startPos=0, float _startVel=0, bool _preventGoingWrongWay=false, bool _preventGoingTooFast=false, float _posLimitLow=-INFINITY, float _posLimitHigh=INFINITY, float _maxStoppingDecel=2, float *_posPointer=NULL, float *_velPointer=NULL) | |
constructor for Derivs_Limiter class | |
Derivs_Limiter () | |
default constructor for Derivs_Limiter | |
void | setPositionVelocity (float pos=0, float vel=0) |
set position and velocity | |
void | setTargetAndPosition (float targ=0, float pos=0) |
set target and position | |
bool | setPosition (float pos=0) |
set position, ignored if NAN | |
bool | setVelocity (float vel=0) |
set velocity | |
bool | setVelLimit (float velLim) |
set velocity limit | |
bool | setAccelLimit (float accelLim) |
set acceleration limit | |
void | setDecelLimit (float _decelLimit=NAN) |
set deceleration limit | |
void | setAccelAndDecelLimits (float _accelLimit, float _decelLimit=NAN) |
combines setAccelLimit() with setDecelLimit() | |
void | setVelAccelLimits (float velLim, float accLim, float decLim=NAN) |
set velocity and acceleration limits | |
float | getVelLimit () |
get velocity limit setting | |
float | getAccelLimit () |
get acceleration limit setting | |
float | getDecelLimit () |
get deceleration limit setting | |
float | getVelocity () |
get the current velocity | |
float | getAcceleration () |
get the current acceleration | |
float | getPosition () |
get the current position value, but doesn't calculate anything | |
void | setMaxStoppingDecel (float _maxStoppingDecel) |
set setting for how many times accelLimit can be used to stop in time for target position | |
float | getMaxStoppingDecel () |
get setting for how many times accelLimit can be used to stop in time for target position | |
float | getLowPosLimit () |
get the lower boundary for position | |
float | getHighPosLimit () |
get the higher boundary for position | |
bool | setLowPosLimit (float lowLimit) |
set the lower boundary for position | |
bool | setHighPosLimit (float highLimit) |
set the higher boundary for position | |
void | setPosLimits (float lowLimit, float highLimit) |
set the boundaries for position | |
bool | setTarget (float _target) |
set target position (doesn't run calculation, make sure to run calc() yourself) | |
float | getTarget () |
get target position | |
void | setPositionAndTarget (float targPos) |
set position and target to a value | |
void | jogPosition (float increment) |
set position and target to position + increment | |
void | resetTime () |
If calc hasn't been run for a while, use this before starting to use it again to protect from large jumps. | |
unsigned long | getLastTime () |
returns the value of micros() when calc() last ran | |
float | getTimeInterval () |
returns the time (in seconds) between the two most recent calculation times | |
float | getTargetDelta () |
returns the change in target from the most recent run of calc() | |
float | getLastTarget () |
what was target in the most recent run of calc() | |
float | getPositionDelta () |
returns the change in position from the most recent run of calc() | |
float | getLastPosition () |
what was position in the most recent run of calc(), can be used to see if position was changed outside of calc() | |
float | getTargetDeltaPerTime () |
how fast was target changing (distance/time) | |
void | setPositionPointer (float *_positionPointer) |
set pointer to an external variable that will be read and modified during calc as position | |
void | setVelocityPointer (float *_velocityPointer) |
set pointer to an external variable that will be read and modified during calc as velocity | |
void | setPreventGoingWrongWay (bool _preventGoingWrongWay) |
sets value of preventGoingWrongWay, true = immediately set velocity to zero if moving away from target, false = stay under accel limit | |
bool | getPreventGoingWrongWay () |
returns value of preventGoingWrongWay setting | |
void | setPreventGoingTooFast (bool _preventGoingTooFast) |
sets value of preventGoingTooFast, true = constrain velocity to velLimit, false decelerate at accelLimit to velLimit | |
bool | getPreventGoingTooFast () |
returns value of preventGoingTooFast setting | |
bool | isPosAtTarget () |
does position equal target? | |
bool | isPosNotAtTarget () |
is position not equal to target? | |
float | distToTarget () |
returns target - position | |
void | setVelConstant (float vel) |
switch to velocity mode, and set velocity immediately to a constant value. | |
void | setVelTarget (float vel) |
switch to velocity mode, and set a target velocity that the target should go towards limited by accelLimit | |
bool | isPosModeNotVelocity () |
true if in position target mode, false if in velocity target mode | |
float | getVelTarget () |
get the target velocity used by the velocity control mode | |
void | resetVelLimitToOriginal () |
resets the velocity limit to the value set in the constructor or setVelLimit() | |
boolean | setVelLimitForTimedMove (float _dist, float _time, float _maxVel=NAN) |
This function changes velLimit so that a move of a specified distance takes the specified time (if possible given acceleration limit) | |
boolean | setTargetAndVelLimitForTimedMove (float _target, float _time, float _maxVel=NAN) |
This function changes velLimit so that a move to the specified target position takes the specified time (if possible given acceleration limit) | |
boolean | setTargetTimedMovePreferred (float _target, float _time, float _maxVel=NAN) |
This function changes velLimit so that a move to the specified target position takes the specified time if possible given acceleration limit, and if not possible resets the velocity limit to the original value (or _maxVel if not NAN) and goes to the target at that speed instead. | |
float | calc () |
call this as frequently as possible to calculate all the values | |
float | calc (float _target) |
call this as frequently as possible to calculate all the values | |
Protected Member Functions | |
virtual float | _calc () |
this is where the actual code is | |
Protected Attributes | |
float | position |
float | velocity |
float | accel |
unsigned long | lastTime |
float | target |
float | velLimit |
float | accelLimit |
float | decelLimit |
float | time |
bool | preventGoingWrongWay |
bool | preventGoingTooFast |
float | posLimitLow |
float | posLimitHigh |
float | maxStoppingDecel |
float | lastTarget |
float | targetDelta |
float | lastPos |
float | posDelta |
float | originalVelLimit |
float * | positionPointer |
float * | velocityPointer |
bool | posMode |
float | velocityTarget |
This library can be used to limit the first and second derivative of a variable as it approaches a target value. https://github.com/joshua-8/Derivs_Limiter.
|
inline |
constructor for Derivs_Limiter class
_velLimit | (float) velocity limit (units per second) |
_accelLimit | (float) acceleration limit (units per second per second) |
_decelLimit | (float) default=NAN, deceleration limit (units per second per second), set to NAN to use accelLimit |
_target | (float) default=0, target value to make position approach |
_startPos | (float) default=0, starting position |
_startVel | (float) default=0, starting velocity |
_preventGoingWrongWay | (bool) default=false, stop immediately if velocity is going away from target |
_preventGoingTooFast | (bool) default=false, constrain velocity to within velLimit |
_posLimitLow | (float) default=-INFINITY, lower bound for position |
_posLimitHigh | (float) default=INFINITY, upper bound for position, will be set to _posLimitLow if below _posLimitLow |
_maxStoppingDecel | (float) default=2, how many times accelLimit can be used to stop in time for target position (can be 1 through INFINITY) |
_posPointer | set pointer to an external variable that will be read and modified during calc as position. use &var |
_velPointer | set pointer to an external variable that will be read and modified during calc as velocity. use &var |
|
inline |
default constructor for Derivs_Limiter
|
inlineprotectedvirtual |
this is where the actual code is
(float) | position |
|
inline |
call this as frequently as possible to calculate all the values
(float) | position |
|
inline |
call this as frequently as possible to calculate all the values
_target | set the target position, ignored if NAN |
(float) | position |
|
inline |
returns target - position
(float) |
|
inline |
get the current acceleration
(float) | (units per second per second) |
|
inline |
get acceleration limit setting
(float) |
|
inline |
get deceleration limit setting
(float) |
|
inline |
get the higher boundary for position
(float) |
|
inline |
|
inline |
what was target in the most recent run of calc()
(float) |
|
inline |
returns the value of micros() when calc() last ran
unsigned | long |
|
inline |
get the lower boundary for position
(float) |
|
inline |
get setting for how many times accelLimit can be used to stop in time for target position
(float) |
|
inline |
get the current position value, but doesn't calculate anything
(float) |
|
inline |
returns the change in position from the most recent run of calc()
(float) |
|
inline |
returns value of preventGoingTooFast setting
(bool) |
|
inline |
returns value of preventGoingWrongWay setting
(bool) |
|
inline |
get target position
(float) |
|
inline |
returns the change in target from the most recent run of calc()
(float) |
|
inline |
how fast was target changing (distance/time)
(float) |
|
inline |
returns the time (in seconds) between the two most recent calculation times
(float) |
|
inline |
get velocity limit setting
(float) |
|
inline |
get the current velocity
(float) | (units per second) |
|
inline |
get the target velocity used by the velocity control mode
(float) |
|
inline |
does position equal target?
(bool) |
|
inline |
true if in position target mode, false if in velocity target mode
(bool) |
|
inline |
is position not equal to target?
(bool) |
|
inline |
set position and target to position + increment
increment | (float) |
None |
|
inline |
If calc hasn't been run for a while, use this before starting to use it again to protect from large jumps.
None |
|
inline |
resets the velocity limit to the value set in the constructor or setVelLimit()
None |
|
inline |
|
inline |
set acceleration limit
accelLim | (float) acceleration limit (units per second per second) |
(bool) | true if limit changed |
|
inline |
set deceleration limit
_decelLimit | (float) deceleration limit, if NAN decelLimit gets set to accelLimit |
None |
|
inline |
set the higher boundary for position
highLimit | (float), INFINITY means no limit |
(bool) | did boundary change (was it valid) |
|
inline |
set the lower boundary for position
lowLimit | (float), -INFINITY means no limit |
(bool) | did boundary change (was it valid) |
|
inline |
set setting for how many times accelLimit can be used to stop in time for target position
_maxStoppingDecel | (float) must be >=1.0, can be INFINITY |
None |
|
inline |
set position, ignored if NAN
pos | (float) default: 0, ignored if NAN |
(bool) | true if position changed |
|
inline |
set position and target to a value
targPos | (float) |
None |
|
inline |
set pointer to an external variable that will be read and modified during calc as position
_positionPointer | (float*) |
None |
|
inline |
set position and velocity
pos | (float) default: 0, ignored if NAN |
vel | (float) default: 0, ignored if NAN |
None |
|
inline |
set the boundaries for position
lowLimit | (float) |
highLimit | (float) |
None |
|
inline |
sets value of preventGoingTooFast, true = constrain velocity to velLimit, false decelerate at accelLimit to velLimit
_preventGoingTooFast | (bool) |
None |
|
inline |
sets value of preventGoingWrongWay, true = immediately set velocity to zero if moving away from target, false = stay under accel limit
_preventGoingWrongWay | (bool) |
None |
|
inline |
set target position (doesn't run calculation, make sure to run calc() yourself)
_target | (float) position, ignored if NAN |
(bool) | position==target |
|
inline |
set target and position
targ | (float) default: 0, ignored if NAN |
pos | (float) default: 0, ignored if NAN |
None |
|
inline |
This function changes velLimit so that a move to the specified target position takes the specified time (if possible given acceleration limit)
_target | (float) position you'd like to move to |
_time | (float) how long you would like the movement to take |
_maxVel | (float, optional, default=NAN) maximum allowable velocity, if the required velocity exceeds this the function returns false, if NAN the velocity limit set in the constructor or setVelLimit() is used |
(bool) | true if move possible within time given acceleration limit, false if not possible (and nothing is changed) |
|
inline |
This function changes velLimit so that a move to the specified target position takes the specified time if possible given acceleration limit, and if not possible resets the velocity limit to the original value (or _maxVel if not NAN) and goes to the target at that speed instead.
_target | (float) position you'd like to move to |
_time | (float) how long you would like the movement to take |
_maxVel | (float, optional, default=NAN) maximum allowable velocity, if the required velocity exceeds this the function returns false, if NAN the velocity limit set in the constructor or setVelLimit() is used |
(bool) | true if move possible within time given acceleration limit, false if not possible (and move happens with maxVel instead but will not complete in time) |
|
inline |
set velocity and acceleration limits
velLim | (float) velocity limit |
accLim | (float) acceleration limit |
decLim | (float) deceleration limit, set NAN to set equal to acceleration limit |
None |
|
inline |
switch to velocity mode, and set velocity immediately to a constant value.
vel | (float) |
None |
|
inline |
set velocity limit
velLim | (float) velocity limit (units per second) |
(bool) | true if limit changed |
|
inline |
This function changes velLimit so that a move of a specified distance takes the specified time (if possible given acceleration limit)
_dist | (float) how far you want to move |
_time | (float) time in seconds that you would like it to take to move the given distance |
_maxVel | (float, optional, default=NAN) maximum allowable velocity, if the required velocity exceeds this the function returns false, if NAN the velocity limit set in the constructor or setVelLimit() is used |
(bool) | true if move possible within time given acceleration limit, false if not possible (and nothing is changed) |
|
inline |
set velocity
vel | (float) default: 0, ignored if NAN |
(bool) | true if velocity changed |
|
inline |
set pointer to an external variable that will be read and modified during calc as velocity
_velocityPointer | (float*) |
None |
|
inline |
switch to velocity mode, and set a target velocity that the target should go towards limited by accelLimit
vel | (float) |
None |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |