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. 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)
 Take the longer 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 2579 of file ServoEasing.hpp.

◆ OVERSHOOT_AMOUNT_UNITS

#define OVERSHOOT_AMOUNT_UNITS   10

Definition at line 2580 of file ServoEasing.hpp.

◆ PART_OF_BOUNCE_MOVEMENT

#define PART_OF_BOUNCE_MOVEMENT   (1.0 - PART_OF_LINEAR_MOVEMENT)

Definition at line 2576 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 2577 of file ServoEasing.hpp.

◆ PART_OF_LINEAR_MOVEMENT

#define PART_OF_LINEAR_MOVEMENT   0.8

Definition at line 2575 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 1821 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 2446 of file ServoEasing.hpp.

◆ disableServoEasingInterrupt()

void disableServoEasingInterrupt ( )

Definition at line 2072 of file ServoEasing.hpp.

◆ 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 1866 of file ServoEasing.hpp.

◆ 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 100 us before the next servo period starts.

Definition at line 1841 of file ServoEasing.hpp.

◆ isOneServoMoving()

bool isOneServoMoving ( )

Definition at line 2366 of file ServoEasing.hpp.

◆ pauseAllServos()

void pauseAllServos ( )

Definition at line 2386 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 2251 of file ServoEasing.hpp.

◆ resumeWithInterruptsAllServos()

void resumeWithInterruptsAllServos ( )

Definition at line 2398 of file ServoEasing.hpp.

◆ resumeWithoutInterruptsAllServos()

void resumeWithoutInterruptsAllServos ( )

Definition at line 2406 of file ServoEasing.hpp.

◆ 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 2355 of file ServoEasing.hpp.

◆ 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 2322 of file ServoEasing.hpp.

◆ 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 2339 of file ServoEasing.hpp.

◆ setEaseToForAllServosSynchronizeAndStartInterrupt() [1/2]

void setEaseToForAllServosSynchronizeAndStartInterrupt ( )

Definition at line 2214 of file ServoEasing.hpp.

◆ setEaseToForAllServosSynchronizeAndStartInterrupt() [2/2]

void setEaseToForAllServosSynchronizeAndStartInterrupt ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2219 of file ServoEasing.hpp.

◆ setEaseToForAllServosSynchronizeAndWaitForAllServosToStop() [1/2]

void setEaseToForAllServosSynchronizeAndWaitForAllServosToStop ( )

Synchronize and blocking wait until all servos are stopped.

Definition at line 2227 of file ServoEasing.hpp.

◆ setEaseToForAllServosSynchronizeAndWaitForAllServosToStop() [2/2]

void setEaseToForAllServosSynchronizeAndWaitForAllServosToStop ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2232 of file ServoEasing.hpp.

◆ 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 2198 of file ServoEasing.hpp.

◆ setEasingTypeForMultipleServos()

void setEasingTypeForMultipleServos ( uint_fast8_t  aNumberOfServos,
uint_fast8_t  aEasingType 
)

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

Definition at line 2205 of file ServoEasing.hpp.

◆ setSpeedForAllServos()

void setSpeedForAllServos ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2286 of file ServoEasing.hpp.

◆ stopAllServos()

void stopAllServos ( )

Definition at line 2375 of file ServoEasing.hpp.

◆ synchronizeAllServosAndStartInterrupt()

void synchronizeAllServosAndStartInterrupt ( bool  aStartUpdateByInterrupt)

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

Definition at line 2474 of file ServoEasing.hpp.

◆ synchronizeAllServosStartAndWaitForAllServosToStop()

void synchronizeAllServosStartAndWaitForAllServosToStop ( )

Synchronize and blocking wait until all servos are stopped.

Definition at line 2466 of file ServoEasing.hpp.

◆ synchronizeAndEaseToArrayPositions() [1/2]

void synchronizeAndEaseToArrayPositions ( )

Definition at line 2237 of file ServoEasing.hpp.

◆ synchronizeAndEaseToArrayPositions() [2/2]

void synchronizeAndEaseToArrayPositions ( uint_fast16_t  aDegreesPerSecond)

Definition at line 2242 of file ServoEasing.hpp.

◆ updateAllServos()

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

Definition at line 2417 of file ServoEasing.hpp.

◆ updateAndWaitForAllServosToStop()

void updateAndWaitForAllServosToStop ( )

Blocking wait until all servos are stopped.

Definition at line 2434 of file ServoEasing.hpp.

◆ writeAllServos()

void writeAllServos ( int  aDegreeOrMicrosecond)

Definition at line 2278 of file ServoEasing.hpp.

Variable Documentation

◆ PROGMEM

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

Definition at line 165 of file ServoEasing.hpp.