ServoEasing
|
#include <ServoEasing.h>
Public Member Functions | |
ServoEasing () | |
uint8_t | attach (int aPin) |
Specify the microseconds values for 0 and 180 degree for the servo. More... | |
uint8_t | attach (int aPin, int aInitialDegreeOrMicrosecond) |
Combination of attach with initial write(). More... | |
uint8_t | attachWithTrim (int aPin, int aTrimDegreeOrMicrosecond, int aInitialDegreeOrMicrosecond) |
Combination of attach with initial setTrim() and write(). More... | |
uint8_t | attach (int aPin, int aMicrosecondsForServo0Degree, int aMicrosecondsForServo180Degree) |
uint8_t | attach (int aPin, int aInitialDegreeOrMicrosecond, int aMicrosecondsForServo0Degree, int aMicrosecondsForServo180Degree) |
Specify the start value written to the servo and the microseconds values for 0 and 180 degree for the servo. More... | |
uint8_t | attachWithTrim (int aPin, int aTrimDegreeOrMicrosecond, int aInitialDegreeOrMicrosecond, int aMicrosecondsForServo0Degree, int aMicrosecondsForServo180Degree) |
uint8_t | attach (int aPin, int aMicrosecondsForServoLowDegree, int aMicrosecondsForServoHighDegree, int aServoLowDegree, int aServoHighDegree) |
Attaches servo to pin and sets the servo timing parameters. More... | |
uint8_t | attach (int aPin, int aInitialDegreeOrMicrosecond, int aMicrosecondsForServoLowDegree, int aMicrosecondsForServoHighDegree, int aServoLowDegree, int aServoHighDegree) |
The microseconds values at aServoLowDegree and aServoHighDegree are used to compute the microseconds values at 0 and 180 degrees By modifying the Micoseconds* and *Degree parameter values you can also provide an initial trim and reverse. More... | |
uint8_t | attachWithTrim (int aPin, int aTrimDegreeOrMicrosecond, int aInitialDegreeOrMicrosecond, int aMicrosecondsForServoLowDegree, int aMicrosecondsForServoHighDegree, int aServoLowDegree, int aServoHighDegree) |
void | detach () |
Mark a detached servo in the array by setting the object pointer to NULL The next attach() then uses this NULL pointer position and thus gets the index of the former detached one. More... | |
void | setReverseOperation (bool aOperateServoReverse) |
void | setTrim (int aTrimDegreeOrMicrosecond, bool aDoWrite=false) |
void | _setTrimMicrosecondsOrUnits (int aTrimMicrosecondsOrUnits, bool aDoWrite=false) |
void | setMaxConstraint (int aMaxDegreeOrMicrosecond) |
void | setMinConstraint (int aMinDegreeOrMicrosecond) |
void | setMinMaxConstraint (int aMinDegreeOrMicrosecond, int aMaxDegreeOrMicrosecond) |
void | setEasingType (uint_fast8_t aEasingType) |
uint_fast8_t | getEasingType () |
float | callEasingFunction (float aPercentageOfCompletion) |
void | registerUserEaseInFunction (float(*aUserEaseInFunction)(float aPercentageOfCompletion, void *aUserDataPointer), void *aUserDataPointer=NULL) |
void | setUserDataPointer (void *aUserDataPointer) |
void | write (int aTargetDegreeOrMicrosecond) |
void | _writeMicrosecondsOrUnits (int aTargetDegreeOrMicrosecond) |
Internal function Before sending the value to the underlying Servo library, trim and reverse is applied. More... | |
void | easeTo (int aTargetDegreeOrMicrosecond) |
void | easeTo (int aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond) |
Blocking move without interrupt. More... | |
void | easeToD (int aTargetDegreeOrMicrosecond, uint_fast16_t aMillisForMove) |
bool | setEaseTo (int aTargetDegreeOrMicrosecond) |
bool | setEaseTo (int aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond) |
Sets easing parameter, but does not start interrupt. More... | |
bool | startEaseTo (int aTargetDegreeOrMicrosecond) |
Starts interrupt for update() More... | |
bool | startEaseTo (int aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond, bool aStartUpdateByInterrupt=START_UPDATE_BY_INTERRUPT) |
Compute the MillisForCompleteMove parameter for use of startEaseToD() function and handle CALL_STYLE_BOUNCING_OUT_IN flag, which requires double time. More... | |
bool | setEaseToD (int aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond) |
Sets easing parameter, but does not start. More... | |
bool | startEaseToD (int aTargetDegreeOrMicrosecond, uint_fast16_t aMillisForMove, bool aStartUpdateByInterrupt=START_UPDATE_BY_INTERRUPT) |
Sets up all the values required for a smooth move to new value Lower level function with time instead of speed parameter. More... | |
void | write (float aTargetDegreeOrMicrosecond) |
void | easeTo (float aTargetDegreeOrMicrosecond) |
void | easeTo (float aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond) |
void | easeToD (float aTargetDegreeOrMicrosecond, uint_fast16_t aMillisForMove) |
bool | setEaseTo (float aTargetDegreeOrMicrosecond) |
bool | setEaseTo (float aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond) |
bool | startEaseTo (float aTargetDegreeOrMicrosecond) |
bool | startEaseTo (float aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond, bool aStartUpdateByInterrupt=START_UPDATE_BY_INTERRUPT) |
bool | setEaseToD (float aTargetDegreeOrMicrosecond, uint_fast16_t aDegreesPerSecond) |
bool | startEaseToD (float aTargetDegreeOrMicrosecond, uint_fast16_t aMillisForMove, bool aStartUpdateByInterrupt=START_UPDATE_BY_INTERRUPT) |
bool | noMovement (uint_fast16_t aMillisToWait) |
stay at the position for aMillisToWait Used as delay for callback More... | |
void | setSpeed (uint_fast16_t aDegreesPerSecond) |
uint_fast16_t | getSpeed () |
void | stop () |
This stops the servo at any position. More... | |
void | pause () |
void | resumeWithInterrupts () |
void | resumeWithoutInterrupts () |
bool | update () |
void | setTargetPositionReachedHandler (void(*aTargetPositionReachedHandler)(ServoEasing *)) |
int | getCurrentAngle () |
int | getCurrentMicroseconds () |
int | getEndMicrosecondsOrUnits () |
int | getEndMicrosecondsOrUnitsWithTrim () |
Not used internally. More... | |
int | getDeltaMicrosecondsOrUnits () |
int | getMillisForCompleteMove () |
bool | isMoving () |
Test if servo is moving yet. More... | |
bool | isMovingAndCallYield () __attribute__((deprecated("Replaced by isMoving(). Often better to use areInterruptsActive() instead."))) |
Call yield here (actually only for ESP8266), so the user do not need to care for it in long running loops. More... | |
int | MicrosecondsOrUnitsToDegree (int aMicrosecondsOrUnits) |
Used to convert e.g. More... | |
int | MicrosecondsToDegree (int aMicroseconds) |
Only used in startEaseTo to compute target degree For PCA9685, we have stored units in mServo0DegreeMicrosecondsOrUnits and mServo180DegreeMicrosecondsOrUnits. More... | |
int | MicrosecondsOrUnitsToMicroseconds (int aMicrosecondsOrUnits) |
int | DegreeOrMicrosecondToMicrosecondsOrUnits (int aDegreeOrMicrosecond) |
We have around 10 us per degree Used to convert (external) provided degree values to internal microseconds For degree parameter, return map(aDegreeOrMicrosecond, 0, 180, mServo0DegreeMicrosecondsOrUnits, mServo180DegreeMicrosecondsOrUnits);. More... | |
int | DegreeOrMicrosecondToMicrosecondsOrUnits (float aDegreeOrMicrosecond) |
int | DegreeToMicrosecondsOrUnitsWithTrimAndReverse (int aDegree) |
Mainly for testing, since trim and reverse are applied at each write. More... | |
void | synchronizeServosAndStartInterrupt (bool doUpdateByInterrupt) |
void | print (Print *aSerial, bool doExtendedOutput=true) |
Do a printDynamic() and a printStatic() More... | |
void | printDynamic (Print *aSerial, bool doExtendedOutput=true) |
Prints values which may change from move to move. More... | |
void | printStatic (Print *aSerial) |
Prints values which normally does NOT change from move to move. More... | |
float | LinearWithQuadraticBounce (float aPercentageOfCompletion) |
PRECISION (LinearWithQuadraticBounce) is like linear, but adds a 5 degree bounce in the last 20 % of the movement time at one direction. More... | |
bool | InitializeAndCheckI2CConnection (Stream *aSerial) |
Static Public Member Functions | |
static void | printEasingType (Print *aSerial, uint_fast8_t aEasingType) |
static float | QuadraticEaseIn (float aPercentageOfCompletion) |
The simplest non linear easing function. More... | |
static float | CubicEaseIn (float aPercentageOfCompletion) |
static float | QuarticEaseIn (float aPercentageOfCompletion) |
static float | SineEaseIn (float aPercentageOfCompletion) |
Take half of negative cosines of first quadrant Is behaves almost like QUADRATIC. More... | |
static float | CircularEaseIn (float aPercentageOfCompletion) |
It is very fast in the middle! see: https://easings.net/#easeInOutCirc and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c. More... | |
static float | BackEaseIn (float aPercentageOfCompletion) |
see: https://easings.net/#easeInOutBack and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c More... | |
static float | ElasticEaseIn (float aPercentageOfCompletion) |
see: https://easings.net/#easeInOutElastic and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c More... | |
static float | EaseOutBounce (float aPercentageOfCompletion) |
!!! ATTENTION !!! we have only the out function implemented see: https://easings.net/de#easeOutBounce and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c More... | |
static bool | areInterruptsActive () |
The recommended test if at least one servo is moving yet. More... | |
Public Attributes | |
volatile int | mCurrentMicrosecondsOrUnits |
Internally only microseconds (or units (= 4.88 us) if using PCA9685 expander) and not degree are used to speed up things. More... | |
int | mStartMicrosecondsOrUnits |
Only used with millisAtStartMove to compute currentMicrosecondsOrUnits in update() More... | |
int | mEndMicrosecondsOrUnits |
Only used once as last value if movement was finished to provide exact end position. More... | |
int | mDeltaMicrosecondsOrUnits |
end - start More... | |
uint_fast16_t | mSpeed |
max speed is 450 degree/sec for SG90 and 540 degree/second for MG90 servos -> see speedTest.cpp More... | |
uint8_t | mEasingType |
void * | UserDataPointer |
float(* | mUserEaseInFunction )(float aPercentageOfCompletion, void *aUserDataPointer) |
volatile bool | mServoMoves |
uint8_t | mServoPin |
pin number / port number of PCA9685 [0-15] or NO_SERVO_ATTACHED_PIN_NUMBER - at least required for Lightweight Servo Library More... | |
uint8_t | mServoIndex |
Index in sServoArray or INVALID_SERVO if error while attach() or if detached. More... | |
uint32_t | mMillisAtStartMove |
uint_fast16_t | mMillisForCompleteMove |
bool | mServoIsPaused |
uint32_t | mMillisAtStopMove |
bool | mOperateServoReverse |
Reverse means, that values for 180 and 0 degrees are swapped by: aValue = mServo180DegreeMicrosecondsOrUnits - (aValue - mServo0DegreeMicrosecondsOrUnits) Be careful, if you specify different end values, it may not behave, as you expect. More... | |
int | mMaxMicrosecondsOrUnits |
Max value checked at _writeMicrosecondsOrUnits(), before trim and reverse is applied. More... | |
int | mMinMicrosecondsOrUnits |
Min value checked at _writeMicrosecondsOrUnits(), before trim and reverse is applied. More... | |
int | mTrimMicrosecondsOrUnits |
This value is always added by the function _writeMicrosecondsOrUnits() to the requested degree/units/microseconds value. More... | |
int | mServo0DegreeMicrosecondsOrUnits |
Values contain always microseconds except for servos connected to a PCA9685 expander, where they contain PWM units. More... | |
int | mServo180DegreeMicrosecondsOrUnits |
void(* | TargetPositionReachedHandler )(ServoEasing *) |
Is called any time when target servo position is reached. More... | |
Static Public Attributes | |
static volatile bool | sInterruptsAreActive = false |
It is required for ESP32, where the timer interrupt routine does not block the loop. More... | |
static uint_fast8_t | sServoArrayMaxIndex = 0 |
Two arrays of all servos to enable synchronized movings Servos are inserted in the order, in which they are attached I use an fixed array and not a list, since accessing an array is much easier and faster. More... | |
static ServoEasing * | ServoEasingArray [MAX_EASING_SERVOS] |
static float | ServoEasingNextPositionArray [MAX_EASING_SERVOS] |
Used exclusively for *ForAllServos() functions. More... | |
Definition at line 414 of file ServoEasing.h.
ServoEasing::ServoEasing | ( | ) |
Definition at line 395 of file ServoEasing.hpp.
void ServoEasing::_setTrimMicrosecondsOrUnits | ( | int | aTrimMicrosecondsOrUnits, |
bool | aDoWrite = false |
||
) |
aTrimMicrosecondsOrUnits | This trim value is always added to the degree/units/microseconds value requested |
aDoWrite | If true, apply value directly to servo by calling _writeMicrosecondsOrUnits() using mCurrentMicrosecondsOrUnits This shows the effect of the trim as a servo movement If false, no internal value e.g. ServoEasingNextPositionArray or mCurrentMicrosecondsOrUnits is updated! |
Definition at line 715 of file ServoEasing.hpp.
void ServoEasing::_writeMicrosecondsOrUnits | ( | int | aTargetDegreeOrMicrosecond | ) |
Internal function Before sending the value to the underlying Servo library, trim and reverse is applied.
Definition at line 801 of file ServoEasing.hpp.
|
static |
The recommended test if at least one servo is moving yet.
Definition at line 1628 of file ServoEasing.hpp.
uint8_t ServoEasing::attach | ( | int | aPin | ) |
Specify the microseconds values for 0 and 180 degree for the servo.
The values can be determined by the EndPositionsTest example.
aPin | Pin number or port number of PCA9685 [0-15] |
If USE_LEIGHTWEIGHT_SERVO_LIB is enabled: Return 0/false if not pin 9 or 10 else return aPin Pin number != 9 results in using pin 10. If USE_PCA9685_SERVO_EXPANDER is enabled: Return true only if channel number is between 0 and 15 since PCA9685 has only 16 channels, else returns false Else return servoIndex / internal channel number
Definition at line 443 of file ServoEasing.hpp.
uint8_t ServoEasing::attach | ( | int | aPin, |
int | aInitialDegreeOrMicrosecond | ||
) |
Combination of attach with initial write().
Definition at line 455 of file ServoEasing.hpp.
uint8_t ServoEasing::attach | ( | int | aPin, |
int | aInitialDegreeOrMicrosecond, | ||
int | aMicrosecondsForServo0Degree, | ||
int | aMicrosecondsForServo180Degree | ||
) |
Specify the start value written to the servo and the microseconds values for 0 and 180 degree for the servo.
The values can be determined by the EndPositionsTest example. By modifying the Micoseconds* parameter values you can also provide an initial trim. Initial trim is the behavior for mTrimMicrosecondsOrUnits == 0.
Definition at line 473 of file ServoEasing.hpp.
uint8_t ServoEasing::attach | ( | int | aPin, |
int | aInitialDegreeOrMicrosecond, | ||
int | aMicrosecondsForServoLowDegree, | ||
int | aMicrosecondsForServoHighDegree, | ||
int | aServoLowDegree, | ||
int | aServoHighDegree | ||
) |
The microseconds values at aServoLowDegree and aServoHighDegree are used to compute the microseconds values at 0 and 180 degrees By modifying the Micoseconds* and *Degree parameter values you can also provide an initial trim and reverse.
Initial trim is the behavior for mTrimMicrosecondsOrUnits == 0. This can be used e.g. to run the servo from virtual -90 to +90 degree (See TwoServos example).
Definition at line 490 of file ServoEasing.hpp.
uint8_t ServoEasing::attach | ( | int | aPin, |
int | aMicrosecondsForServo0Degree, | ||
int | aMicrosecondsForServo180Degree | ||
) |
Definition at line 448 of file ServoEasing.hpp.
uint8_t ServoEasing::attach | ( | int | aPin, |
int | aMicrosecondsForServoLowDegree, | ||
int | aMicrosecondsForServoHighDegree, | ||
int | aServoLowDegree, | ||
int | aServoHighDegree | ||
) |
Attaches servo to pin and sets the servo timing parameters.
aPin | Pin number or port number of PCA9685 [0-15] |
aMicrosecondsForServoLowDegree,aMicrosecondsForServoHighDegree | no units accepted, only microseconds! |
aServoLowDegree | can be negative. For this case an appropriate trim value is added, since this is the only way to handle negative values. |
aServoHighDegree | The degree value for the corresponding aMicrosecondsForServoHighDegree parameter. |
Definition at line 517 of file ServoEasing.hpp.
uint8_t ServoEasing::attachWithTrim | ( | int | aPin, |
int | aTrimDegreeOrMicrosecond, | ||
int | aInitialDegreeOrMicrosecond | ||
) |
Combination of attach with initial setTrim() and write().
Definition at line 462 of file ServoEasing.hpp.
uint8_t ServoEasing::attachWithTrim | ( | int | aPin, |
int | aTrimDegreeOrMicrosecond, | ||
int | aInitialDegreeOrMicrosecond, | ||
int | aMicrosecondsForServo0Degree, | ||
int | aMicrosecondsForServo180Degree | ||
) |
Definition at line 478 of file ServoEasing.hpp.
uint8_t ServoEasing::attachWithTrim | ( | int | aPin, |
int | aTrimDegreeOrMicrosecond, | ||
int | aInitialDegreeOrMicrosecond, | ||
int | aMicrosecondsForServoLowDegree, | ||
int | aMicrosecondsForServoHighDegree, | ||
int | aServoLowDegree, | ||
int | aServoHighDegree | ||
) |
Definition at line 498 of file ServoEasing.hpp.
|
static |
see: https://easings.net/#easeInOutBack and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c
Definition at line 2561 of file ServoEasing.hpp.
float ServoEasing::callEasingFunction | ( | float | aPercentageOfCompletion | ) |
Definition at line 1554 of file ServoEasing.hpp.
|
static |
It is very fast in the middle! see: https://easings.net/#easeInOutCirc and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c.
Definition at line 2553 of file ServoEasing.hpp.
|
static |
Definition at line 2532 of file ServoEasing.hpp.
int ServoEasing::DegreeOrMicrosecondToMicrosecondsOrUnits | ( | float | aDegreeOrMicrosecond | ) |
Definition at line 989 of file ServoEasing.hpp.
int ServoEasing::DegreeOrMicrosecondToMicrosecondsOrUnits | ( | int | aDegreeOrMicrosecond | ) |
We have around 10 us per degree Used to convert (external) provided degree values to internal microseconds For degree parameter, return map(aDegreeOrMicrosecond, 0, 180, mServo0DegreeMicrosecondsOrUnits, mServo180DegreeMicrosecondsOrUnits);.
Definition at line 963 of file ServoEasing.hpp.
int ServoEasing::DegreeToMicrosecondsOrUnitsWithTrimAndReverse | ( | int | aDegree | ) |
Mainly for testing, since trim and reverse are applied at each write.
Definition at line 1018 of file ServoEasing.hpp.
void ServoEasing::detach | ( | ) |
Mark a detached servo in the array by setting the object pointer to NULL The next attach() then uses this NULL pointer position and thus gets the index of the former detached one.
Definition at line 638 of file ServoEasing.hpp.
|
static |
!!! ATTENTION !!! we have only the out function implemented see: https://easings.net/de#easeOutBounce and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c
Definition at line 2664 of file ServoEasing.hpp.
void ServoEasing::easeTo | ( | float | aTargetDegreeOrMicrosecond | ) |
Definition at line 1032 of file ServoEasing.hpp.
void ServoEasing::easeTo | ( | float | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aDegreesPerSecond | ||
) |
Definition at line 1053 of file ServoEasing.hpp.
void ServoEasing::easeTo | ( | int | aTargetDegreeOrMicrosecond | ) |
Definition at line 1028 of file ServoEasing.hpp.
void ServoEasing::easeTo | ( | int | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aDegreesPerSecond | ||
) |
Blocking move without interrupt.
aTargetDegreeOrMicrosecond | For servos connected to a PCA9685 assume units, else assume microseconds |
aDegreesPerSecond | Can range from 1 to the physically maximum value of 450 |
Definition at line 1041 of file ServoEasing.hpp.
void ServoEasing::easeToD | ( | float | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aMillisForMove | ||
) |
Definition at line 1076 of file ServoEasing.hpp.
void ServoEasing::easeToD | ( | int | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aMillisForMove | ||
) |
Definition at line 1065 of file ServoEasing.hpp.
|
static |
see: https://easings.net/#easeInOutElastic and https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c
Definition at line 2570 of file ServoEasing.hpp.
int ServoEasing::getCurrentAngle | ( | ) |
Definition at line 1649 of file ServoEasing.hpp.
int ServoEasing::getCurrentMicroseconds | ( | ) |
Definition at line 1653 of file ServoEasing.hpp.
int ServoEasing::getDeltaMicrosecondsOrUnits | ( | ) |
Definition at line 1668 of file ServoEasing.hpp.
uint_fast8_t ServoEasing::getEasingType | ( | ) |
Definition at line 740 of file ServoEasing.hpp.
int ServoEasing::getEndMicrosecondsOrUnits | ( | ) |
Definition at line 1657 of file ServoEasing.hpp.
int ServoEasing::getEndMicrosecondsOrUnitsWithTrim | ( | ) |
Not used internally.
Definition at line 1664 of file ServoEasing.hpp.
int ServoEasing::getMillisForCompleteMove | ( | ) |
Definition at line 1672 of file ServoEasing.hpp.
uint_fast16_t ServoEasing::getSpeed | ( | ) |
Definition at line 683 of file ServoEasing.hpp.
bool ServoEasing::InitializeAndCheckI2CConnection | ( | Stream * | aSerial | ) |
bool ServoEasing::isMoving | ( | ) |
Test if servo is moving yet.
Definition at line 1615 of file ServoEasing.hpp.
bool ServoEasing::isMovingAndCallYield | ( | ) |
Call yield here (actually only for ESP8266), so the user do not need to care for it in long running loops.
yield() will only allow higher priority tasks to run. yield() is dangerous for ESP32, since the timer is detached AFTER mServoMoves is set to false in handleServoTimerInterrupt(). Then one core may check mServoMoves and start a new move with initializing the timer, and then the timer gets detached by handleServoTimerInterrupt() which leads to an error: CORRUPT HEAP: Bad head at ...
Definition at line 1645 of file ServoEasing.hpp.
float ServoEasing::LinearWithQuadraticBounce | ( | float | aFactorOfTimeCompletion | ) |
PRECISION (LinearWithQuadraticBounce) is like linear, but adds a 5 degree bounce in the last 20 % of the movement time at one direction.
So the target position is always approached from one side. This enables it to taken out the slack/backlash of any hardware moved by the servo. IN = Negative bounce for movings from above (go in to origin) OUT = Positive bounce for movings from below (go out from origin) we are called with 1.0 to 0.0
Definition at line 2588 of file ServoEasing.hpp.
int ServoEasing::MicrosecondsOrUnitsToDegree | ( | int | aMicrosecondsOrUnits | ) |
Used to convert e.g.
mCurrentMicrosecondsOrUnits back to degree
aMicrosecondsOrUnits | For servos connected to a PCA9685 assume units, else assume microseconds Do not use map function, because it does no rounding |
Formula for microseconds: (aMicrosecondsOrUnits - mServo0DegreeMicrosecondsOrUnits) * (180 / 1856) // 1856 = 180 - 0 degree micros Formula for PCA9685 units (aMicrosecondsOrUnits - mServo0DegreeMicrosecondsOrUnits) * (180 / 380) // 380 = 180 - 0 degree units Formula for both without rounding map(aMicrosecondsOrUnits, mServo0DegreeMicrosecondsOrUnits, mServo180DegreeMicrosecondsOrUnits, 0, 180)
Definition at line 912 of file ServoEasing.hpp.
int ServoEasing::MicrosecondsOrUnitsToMicroseconds | ( | int | aMicrosecondsOrUnits | ) |
Definition at line 949 of file ServoEasing.hpp.
int ServoEasing::MicrosecondsToDegree | ( | int | aMicroseconds | ) |
Only used in startEaseTo to compute target degree For PCA9685, we have stored units in mServo0DegreeMicrosecondsOrUnits and mServo180DegreeMicrosecondsOrUnits.
aMicroseconds | Always assume microseconds, thus for PCA9685 we must convert 0 and 180 degree values back to microseconds |
Definition at line 892 of file ServoEasing.hpp.
bool ServoEasing::noMovement | ( | uint_fast16_t | aMillisToWait | ) |
stay at the position for aMillisToWait Used as delay for callback
Definition at line 1223 of file ServoEasing.hpp.
void ServoEasing::pause | ( | ) |
Definition at line 1356 of file ServoEasing.hpp.
void ServoEasing::print | ( | Print * | aSerial, |
bool | doExtendedOutput = true |
||
) |
Do a printDynamic() and a printStatic()
aSerial | The Print object on which to write, for Arduino you can use &Serial. |
doExtendedOutput | Print also microseconds values for degrees. |
Definition at line 1681 of file ServoEasing.hpp.
void ServoEasing::printDynamic | ( | Print * | aSerial, |
bool | doExtendedOutput = true |
||
) |
Prints values which may change from move to move.
aSerial | The Print object on which to write, for Arduino you can use &Serial. |
doExtendedOutput | Print also microseconds values for degrees. |
Definition at line 1714 of file ServoEasing.hpp.
|
static |
aSerial | The Print object on which to write, for Arduino you can use &Serial. |
aEasingType | No range checking! |
Definition at line 1690 of file ServoEasing.hpp.
void ServoEasing::printStatic | ( | Print * | aSerial | ) |
Prints values which normally does NOT change from move to move.
aSerial | The Print object on which to write, for Arduino you can use &Serial. |
Definition at line 1773 of file ServoEasing.hpp.
|
static |
The simplest non linear easing function.
Definition at line 2528 of file ServoEasing.hpp.
|
static |
Definition at line 2536 of file ServoEasing.hpp.
void ServoEasing::registerUserEaseInFunction | ( | float(*)(float aPercentageOfCompletion, void *aUserDataPointer) | aUserEaseInFunction, |
void * | aUserDataPointer = NULL |
||
) |
Definition at line 745 of file ServoEasing.hpp.
void ServoEasing::resumeWithInterrupts | ( | ) |
Definition at line 1363 of file ServoEasing.hpp.
void ServoEasing::resumeWithoutInterrupts | ( | ) |
Definition at line 1371 of file ServoEasing.hpp.
bool ServoEasing::setEaseTo | ( | float | aTargetDegreeOrMicrosecond | ) |
Definition at line 1091 of file ServoEasing.hpp.
bool ServoEasing::setEaseTo | ( | float | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aDegreesPerSecond | ||
) |
Definition at line 1103 of file ServoEasing.hpp.
bool ServoEasing::setEaseTo | ( | int | aTargetDegreeOrMicrosecond | ) |
Definition at line 1087 of file ServoEasing.hpp.
bool ServoEasing::setEaseTo | ( | int | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aDegreesPerSecond | ||
) |
Sets easing parameter, but does not start interrupt.
Definition at line 1099 of file ServoEasing.hpp.
bool ServoEasing::setEaseToD | ( | float | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aDegreesPerSecond | ||
) |
Definition at line 1215 of file ServoEasing.hpp.
bool ServoEasing::setEaseToD | ( | int | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aMillisForMove | ||
) |
Sets easing parameter, but does not start.
Definition at line 1211 of file ServoEasing.hpp.
void ServoEasing::setEasingType | ( | uint_fast8_t | aEasingType | ) |
Definition at line 736 of file ServoEasing.hpp.
void ServoEasing::setMaxConstraint | ( | int | aMaxDegreeOrMicrosecond | ) |
Definition at line 723 of file ServoEasing.hpp.
void ServoEasing::setMinConstraint | ( | int | aMinDegreeOrMicrosecond | ) |
Definition at line 726 of file ServoEasing.hpp.
void ServoEasing::setMinMaxConstraint | ( | int | aMinDegreeOrMicrosecond, |
int | aMaxDegreeOrMicrosecond | ||
) |
Definition at line 729 of file ServoEasing.hpp.
void ServoEasing::setReverseOperation | ( | bool | aOperateServoReverse | ) |
Definition at line 679 of file ServoEasing.hpp.
void ServoEasing::setSpeed | ( | uint_fast16_t | aDegreesPerSecond | ) |
Definition at line 687 of file ServoEasing.hpp.
void ServoEasing::setTargetPositionReachedHandler | ( | void(*)(ServoEasing *) | aTargetPositionReachedHandler | ) |
Definition at line 1378 of file ServoEasing.hpp.
void ServoEasing::setTrim | ( | int | aTrimDegreeOrMicrosecond, |
bool | aDoWrite = false |
||
) |
aTrimDegreeOrMicrosecond | This trim value is always added to the degree/units/microseconds value requested |
aDoWrite | If true, apply value directly to servo by calling _writeMicrosecondsOrUnits() using mCurrentMicrosecondsOrUnits This shows the effect of the trim as a servo movement If false, no internal value e.g. ServoEasingNextPositionArray or mCurrentMicrosecondsOrUnits is updated! |
Definition at line 697 of file ServoEasing.hpp.
void ServoEasing::setUserDataPointer | ( | void * | aUserDataPointer | ) |
Definition at line 750 of file ServoEasing.hpp.
|
static |
Take half of negative cosines of first quadrant Is behaves almost like QUADRATIC.
Definition at line 2544 of file ServoEasing.hpp.
bool ServoEasing::startEaseTo | ( | float | aTargetDegreeOrMicrosecond | ) |
Definition at line 1114 of file ServoEasing.hpp.
bool ServoEasing::startEaseTo | ( | float | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aDegreesPerSecond, | ||
bool | aStartUpdateByInterrupt = START_UPDATE_BY_INTERRUPT |
||
) |
Definition at line 1165 of file ServoEasing.hpp.
bool ServoEasing::startEaseTo | ( | int | aTargetDegreeOrMicrosecond | ) |
Starts interrupt for update()
Definition at line 1110 of file ServoEasing.hpp.
bool ServoEasing::startEaseTo | ( | int | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aDegreesPerSecond, | ||
bool | aStartUpdateByInterrupt = START_UPDATE_BY_INTERRUPT |
||
) |
Compute the MillisForCompleteMove parameter for use of startEaseToD() function and handle CALL_STYLE_BOUNCING_OUT_IN flag, which requires double time.
Definition at line 1123 of file ServoEasing.hpp.
bool ServoEasing::startEaseToD | ( | float | aTargetDegreeOrMicrosecond, |
uint_fast16_t | aMillisForMove, | ||
bool | aStartUpdateByInterrupt = START_UPDATE_BY_INTERRUPT |
||
) |
Definition at line 1287 of file ServoEasing.hpp.
bool ServoEasing::startEaseToD | ( | int | aDegreeOrMicrosecond, |
uint_fast16_t | aMillisForMove, | ||
bool | aStartUpdateByInterrupt = START_UPDATE_BY_INTERRUPT |
||
) |
Sets up all the values required for a smooth move to new value Lower level function with time instead of speed parameter.
Definition at line 1232 of file ServoEasing.hpp.
void ServoEasing::stop | ( | ) |
This stops the servo at any position.
Definition at line 1346 of file ServoEasing.hpp.
void ServoEasing::synchronizeServosAndStartInterrupt | ( | bool | doUpdateByInterrupt | ) |
bool ServoEasing::update | ( | ) |
Definition at line 1420 of file ServoEasing.hpp.
void ServoEasing::write | ( | float | aTargetDegreeOrMicrosecond | ) |
Definition at line 778 of file ServoEasing.hpp.
void ServoEasing::write | ( | int | aTargetDegreeOrMicrosecond | ) |
aTargetDegreeOrMicrosecond | treat values less than 400 as angles in degrees, others are handled as microseconds |
Definition at line 759 of file ServoEasing.hpp.
volatile int ServoEasing::mCurrentMicrosecondsOrUnits |
Internally only microseconds (or units (= 4.88 us) if using PCA9685 expander) and not degree are used to speed up things.
Other expander or libraries can therefore easily be added. set by write() and _writeMicrosecondsOrUnits(). Required as start for next move and to avoid unnecessary writes.
Definition at line 587 of file ServoEasing.h.
int ServoEasing::mDeltaMicrosecondsOrUnits |
end - start
Definition at line 590 of file ServoEasing.h.
uint8_t ServoEasing::mEasingType |
Definition at line 598 of file ServoEasing.h.
int ServoEasing::mEndMicrosecondsOrUnits |
Only used once as last value if movement was finished to provide exact end position.
Definition at line 589 of file ServoEasing.h.
int ServoEasing::mMaxMicrosecondsOrUnits |
Max value checked at _writeMicrosecondsOrUnits(), before trim and reverse is applied.
Definition at line 635 of file ServoEasing.h.
uint32_t ServoEasing::mMillisAtStartMove |
Definition at line 621 of file ServoEasing.h.
uint32_t ServoEasing::mMillisAtStopMove |
Definition at line 625 of file ServoEasing.h.
uint_fast16_t ServoEasing::mMillisForCompleteMove |
Definition at line 622 of file ServoEasing.h.
int ServoEasing::mMinMicrosecondsOrUnits |
Min value checked at _writeMicrosecondsOrUnits(), before trim and reverse is applied.
Definition at line 636 of file ServoEasing.h.
bool ServoEasing::mOperateServoReverse |
Reverse means, that values for 180 and 0 degrees are swapped by: aValue = mServo180DegreeMicrosecondsOrUnits - (aValue - mServo0DegreeMicrosecondsOrUnits) Be careful, if you specify different end values, it may not behave, as you expect.
For this case better use the attach function with 5 parameter. true -> direction is reversed
Definition at line 633 of file ServoEasing.h.
int ServoEasing::mServo0DegreeMicrosecondsOrUnits |
Values contain always microseconds except for servos connected to a PCA9685 expander, where they contain PWM units.
Values are set exclusively by attach(), and here it is determined if they contain microseconds or PWM units.
Definition at line 644 of file ServoEasing.h.
int ServoEasing::mServo180DegreeMicrosecondsOrUnits |
Definition at line 645 of file ServoEasing.h.
uint8_t ServoEasing::mServoIndex |
Index in sServoArray or INVALID_SERVO if error while attach() or if detached.
Definition at line 619 of file ServoEasing.h.
bool ServoEasing::mServoIsPaused |
Definition at line 624 of file ServoEasing.h.
volatile bool ServoEasing::mServoMoves |
Definition at line 605 of file ServoEasing.h.
uint8_t ServoEasing::mServoPin |
pin number / port number of PCA9685 [0-15] or NO_SERVO_ATTACHED_PIN_NUMBER - at least required for Lightweight Servo Library
Definition at line 617 of file ServoEasing.h.
uint_fast16_t ServoEasing::mSpeed |
max speed is 450 degree/sec for SG90 and 540 degree/second for MG90 servos -> see speedTest.cpp
in DegreesPerSecond - only set by setSpeed(int16_t aSpeed);
Definition at line 595 of file ServoEasing.h.
int ServoEasing::mStartMicrosecondsOrUnits |
Only used with millisAtStartMove to compute currentMicrosecondsOrUnits in update()
Definition at line 588 of file ServoEasing.h.
int ServoEasing::mTrimMicrosecondsOrUnits |
This value is always added by the function _writeMicrosecondsOrUnits() to the requested degree/units/microseconds value.
Definition at line 638 of file ServoEasing.h.
float(* ServoEasing::mUserEaseInFunction) (float aPercentageOfCompletion, void *aUserDataPointer) |
Definition at line 601 of file ServoEasing.h.
|
static |
Definition at line 663 of file ServoEasing.h.
|
static |
Used exclusively for *ForAllServos() functions.
Is updated by write() or startEaseToD() function, to keep it synchronized. Can contain degree values or microseconds but not units. Use float since we want to support higher precision for degrees.
Definition at line 664 of file ServoEasing.h.
|
static |
It is required for ESP32, where the timer interrupt routine does not block the loop.
Maybe it runs on another CPU? The interrupt routine first sets the mServoMoves flag to false and then disables the timer. But on a ESP32 polling the flag and then starting next movement and enabling timer happens BEFORE the timer is disabled. And this crashes the kernel in esp_timer_delete, which will lead to a reboot. true if interrupts are still active, i.e. at least one Servo is moving with interrupts.
Definition at line 655 of file ServoEasing.h.
|
static |
Two arrays of all servos to enable synchronized movings Servos are inserted in the order, in which they are attached I use an fixed array and not a list, since accessing an array is much easier and faster.
list to hold all ServoEasing Objects in order to move them together Cannot use "static servo_t servos[MAX_SERVOS];" from Servo library since it is static :-(
Using an dynamic array may be possible, but in this case we must first malloc(), then memcpy() and then free(), which leads to heap fragmentation. maximum index of an attached servo in sServoArray[]
Definition at line 662 of file ServoEasing.h.
void(* ServoEasing::TargetPositionReachedHandler) (ServoEasing *) |
Is called any time when target servo position is reached.
Definition at line 647 of file ServoEasing.h.
void* ServoEasing::UserDataPointer |
Definition at line 600 of file ServoEasing.h.