ServoEasing
ServoEasing.hpp File Reference
#include <Arduino.h>
#include "ServoEasing.h"
Include dependency graph for ServoEasing.hpp:

Go to the source code of this file.

Macros

#define PART_OF_LINEAR_MOVEMENT   0.8
 
#define PART_OF_BOUNCE_MOVEMENT   (1.0 - PART_OF_LINEAR_MOVEMENT)
 
#define PART_OF_BOUNCE_MOVEMENT_HALF   ((1.0 - PART_OF_LINEAR_MOVEMENT) / 2)
 
#define OVERSHOOT_AMOUNT_MILLIS   50
 
#define OVERSHOOT_AMOUNT_UNITS   10
 

Functions

int clipDegreeSpecial (uint_fast8_t aDegreeToClip)
 Clips the unsigned degree value and handles unsigned underflow. More...
 
void handleServoTimerInterrupt ()
 Update all servos from list and check if all servos have stopped. More...
 
void enableServoEasingInterrupt ()
 Timer1 is used for the Arduino Servo library. More...
 
void disableServoEasingInterrupt ()
 
void setEasingTypeForAllServos (uint_fast8_t aEasingType)
 60 us for single servo + 160 us per servo if using I2C e.g.for PCA9685 expander at 400 kHz or + 100 at 800 kHz 20 us for last interrupt The first servo pulse starts just after this interrupt routine has finished More...
 
void setEasingTypeForMultipleServos (uint_fast8_t aNumberOfServos, uint_fast8_t aEasingType)
 Sets easing type aEasingType for the first aNumberOfServos in ServoEasingArray[]. More...
 
void setEaseToForAllServosSynchronizeAndStartInterrupt ()
 
void setEaseToForAllServosSynchronizeAndStartInterrupt (uint_fast16_t aDegreesPerSecond)
 
void setEaseToForAllServosSynchronizeAndWaitForAllServosToStop ()
 Synchronize and blocking wait until all servos are stopped Take the longer duration in order to move all servos synchronously. More...
 
void setEaseToForAllServosSynchronizeAndWaitForAllServosToStop (uint_fast16_t aDegreesPerSecond)
 
void synchronizeAndEaseToArrayPositions ()
 
void synchronizeAndEaseToArrayPositions (uint_fast16_t aDegreesPerSecond)
 
void printArrayPositions (Print *aSerial)
 Prints content of ServoNextPositionArray for debugging purposes. More...
 
void writeAllServos (int aDegreeOrMicrosecond)
 
void setSpeedForAllServos (uint_fast16_t aDegreesPerSecond)
 
bool setEaseToForAllServos ()
 Sets target position using content of ServoEasingNextPositionArray. More...
 
bool setEaseToForAllServos (uint_fast16_t aDegreesPerSecond)
 Sets target position using content of ServoEasingNextPositionArray and use aDegreesPerSecond instead of the one stored in mSpeed. More...
 
bool setEaseToDForAllServos (uint_fast16_t aMillisForMove)
 Sets target position using content of ServoEasingNextPositionArray and use aMillisForMove instead of the speed stored in mSpeed. More...
 
bool isOneServoMoving ()
 
void stopAllServos ()
 
void pauseAllServos ()
 
void resumeWithInterruptsAllServos ()
 
void resumeWithoutInterruptsAllServos ()
 
bool updateAllServos ()
 
void updateAndWaitForAllServosToStop ()
 Blocking wait until all servos are stopped. More...
 
bool delayAndUpdateAndWaitForAllServosToStop (unsigned long aMillisDelay, bool aTerminateDelayIfAllServosStopped)
 
void synchronizeAllServosStartAndWaitForAllServosToStop ()
 Synchronize and blocking wait until all servos are stopped. More...
 
void synchronizeAllServosAndStartInterrupt (bool aStartUpdateByInterrupt, bool aSynchronizeToMinimumDuration)
 Take the longest duration in order to move all servos synchronously. More...
 

Variables

const char easeTypeLinear[] PROGMEM = "linear"
 

Macro Definition Documentation

◆ OVERSHOOT_AMOUNT_MILLIS

#define OVERSHOOT_AMOUNT_MILLIS   50

Definition at line 2806 of file ServoEasing.hpp.

◆ OVERSHOOT_AMOUNT_UNITS

#define OVERSHOOT_AMOUNT_UNITS   10

Definition at line 2807 of file ServoEasing.hpp.

◆ PART_OF_BOUNCE_MOVEMENT

#define PART_OF_BOUNCE_MOVEMENT   (1.0 - PART_OF_LINEAR_MOVEMENT)

Definition at line 2803 of file ServoEasing.hpp.

◆ PART_OF_BOUNCE_MOVEMENT_HALF

#define PART_OF_BOUNCE_MOVEMENT_HALF   ((1.0 - PART_OF_LINEAR_MOVEMENT) / 2)

Definition at line 2804 of file ServoEasing.hpp.

◆ PART_OF_LINEAR_MOVEMENT

#define PART_OF_LINEAR_MOVEMENT   0.8

Definition at line 2802 of file ServoEasing.hpp.

Function Documentation

◆ clipDegreeSpecial()

int clipDegreeSpecial ( uint_fast8_t  aDegreeToClip)

Clips the unsigned degree value and handles unsigned underflow.

Returns
0 if aDegreeToClip >= 218 and 180 if 180 <= aDegreeToClip < 218

Definition at line 1991 of file ServoEasing.hpp.

◆ delayAndUpdateAndWaitForAllServosToStop()

bool delayAndUpdateAndWaitForAllServosToStop ( unsigned long  aMillisDelay,
bool  aTerminateDelayIfAllServosStopped 
)
Parameters
aMillisDelaythe milliseconds for blocking wait and update
aTerminateDelayIfAllServosStoppedif true, function returns before aMillisDelay if all servos are stopped
Returns
true if all Servos reached endAngle / stopped

Definition at line 2662 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ disableServoEasingInterrupt()

void disableServoEasingInterrupt ( )

Definition at line 2257 of file ServoEasing.hpp.

Here is the caller graph for this function:

◆ enableServoEasingInterrupt()

void enableServoEasingInterrupt ( )

Timer1 is used for the Arduino Servo library.

To have non blocking easing functions its unused channel B is used to generate an interrupt 100 us before the end of the 20 ms Arduino Servo refresh period. This interrupt then updates all servo values for the next refresh period. First interrupt is triggered not directly, but after 20 ms, since we are often called here at the time of the last interrupt of the preceding servo move.

Definition at line 2048 of file ServoEasing.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleServoTimerInterrupt()

void handleServoTimerInterrupt ( )

Update all servos from list and check if all servos have stopped.

Guarded by an macro in order to be able to overwrite it, e.g. for synchronizing with NeoPixel updates, which otherwise leads to servo twitching. See QuadrupedNeoPixel.cpp of QuadrupedControl example. We have (at least on Uno, Nano etc.) 100 us before the next servo period starts. See also setTimer1InterruptMarginMicros();

Definition at line 2012 of file ServoEasing.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isOneServoMoving()

bool isOneServoMoving ( )

Definition at line 2579 of file ServoEasing.hpp.

Here is the caller graph for this function:

◆ pauseAllServos()

void pauseAllServos ( )

Definition at line 2599 of file ServoEasing.hpp.

◆ printArrayPositions()

void printArrayPositions ( Print *  aSerial)

Prints content of ServoNextPositionArray for debugging purposes.

Parameters
aSerialThe Print object on which to write, for Arduino you can use &Serial.

Definition at line 2440 of file ServoEasing.hpp.

◆ resumeWithInterruptsAllServos()

void resumeWithInterruptsAllServos ( )

Definition at line 2611 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ resumeWithoutInterruptsAllServos()

void resumeWithoutInterruptsAllServos ( )

Definition at line 2619 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEaseToDForAllServos()

bool setEaseToDForAllServos ( uint_fast16_t  aMillisForMove)

Sets target position using content of ServoEasingNextPositionArray and use aMillisForMove instead of the speed stored in mSpeed.

Does not start interrupt/movement!

Returns
false if one servo was still moving

Definition at line 2568 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEaseToForAllServos() [1/2]

bool setEaseToForAllServos ( )

Sets target position using content of ServoEasingNextPositionArray.

Does not start interrupt/movement!

Returns
false if one servo was still moving

Definition at line 2535 of file ServoEasing.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEaseToForAllServos() [2/2]

bool setEaseToForAllServos ( uint_fast16_t  aDegreesPerSecond)

Sets target position using content of ServoEasingNextPositionArray and use aDegreesPerSecond instead of the one stored in mSpeed.

Does not start interrupt/movement!

Returns
false if one servo was still moving

Definition at line 2552 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEaseToForAllServosSynchronizeAndStartInterrupt() [1/2]

void setEaseToForAllServosSynchronizeAndStartInterrupt ( )

Definition at line 2402 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEaseToForAllServosSynchronizeAndStartInterrupt() [2/2]

void setEaseToForAllServosSynchronizeAndStartInterrupt ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2407 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEaseToForAllServosSynchronizeAndWaitForAllServosToStop() [1/2]

void setEaseToForAllServosSynchronizeAndWaitForAllServosToStop ( )

Synchronize and blocking wait until all servos are stopped Take the longer duration in order to move all servos synchronously.

Definition at line 2416 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEaseToForAllServosSynchronizeAndWaitForAllServosToStop() [2/2]

void setEaseToForAllServosSynchronizeAndWaitForAllServosToStop ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2421 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEasingTypeForAllServos()

void setEasingTypeForAllServos ( uint_fast8_t  aEasingType)

60 us for single servo + 160 us per servo if using I2C e.g.for PCA9685 expander at 400 kHz or + 100 at 800 kHz 20 us for last interrupt The first servo pulse starts just after this interrupt routine has finished

Definition at line 2386 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ setEasingTypeForMultipleServos()

void setEasingTypeForMultipleServos ( uint_fast8_t  aNumberOfServos,
uint_fast8_t  aEasingType 
)

Sets easing type aEasingType for the first aNumberOfServos in ServoEasingArray[].

Definition at line 2393 of file ServoEasing.hpp.

Here is the caller graph for this function:

◆ setSpeedForAllServos()

void setSpeedForAllServos ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2475 of file ServoEasing.hpp.

◆ stopAllServos()

void stopAllServos ( )

Definition at line 2588 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ synchronizeAllServosAndStartInterrupt()

void synchronizeAllServosAndStartInterrupt ( bool  aStartUpdateByInterrupt,
bool  aSynchronizeToMinimumDuration 
)

Take the longest duration in order to move all servos synchronously.

Parameters
aSynchronizeToMinimumDuration- Take the shortest duration for synchronizing

Definition at line 2691 of file ServoEasing.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ synchronizeAllServosStartAndWaitForAllServosToStop()

void synchronizeAllServosStartAndWaitForAllServosToStop ( )

Synchronize and blocking wait until all servos are stopped.

Definition at line 2682 of file ServoEasing.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ synchronizeAndEaseToArrayPositions() [1/2]

void synchronizeAndEaseToArrayPositions ( )

Definition at line 2426 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ synchronizeAndEaseToArrayPositions() [2/2]

void synchronizeAndEaseToArrayPositions ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2431 of file ServoEasing.hpp.

Here is the call graph for this function:

◆ updateAllServos()

bool updateAllServos ( )
Returns
true if all Servos reached endAngle / stopped

Definition at line 2630 of file ServoEasing.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateAndWaitForAllServosToStop()

void updateAndWaitForAllServosToStop ( )

Blocking wait until all servos are stopped.

Definition at line 2650 of file ServoEasing.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeAllServos()

void writeAllServos ( int  aDegreeOrMicrosecond)

Definition at line 2467 of file ServoEasing.hpp.

Here is the call graph for this function:

Variable Documentation

◆ PROGMEM

const char* const easeTypeStrings [] PROGMEM = "linear"

Definition at line 164 of file ServoEasing.hpp.