Arduino 库,可实现平滑的伺服运动。
Its purpose is to interpolate the movement between two servo positions set by software.
If your servo control data is e.g. generated by an joystick or other "slow" changing inputs and therefore does not change suddenly or does not jump, you most likely do not need this library!, you may consider to use a digital low pass or simple EMA filters to smooth your values used to control the servos.
ServoEasing works with the Arduino Servo library as well as with PCA9685 servo expanders. The expander in turn requires the Arduino Wire library or a compatible one and is bound to their restrictions.
For ESP32 you need to install the Arduino ESP32Servo library.
If you require only one or two servos, you may want to use the included LightweightServo library which is like the Adafruit TiCoServo library, but more lightweight and currently only for Uno, Nano, instead of the Arduino Servo library. The LightweightServo library uses the internal Timer1 with no software overhead and therefore has no problems with servo twitching or interrupt blocking libraries like SoftwareSerial, Adafruit_NeoPixel and DmxSimple.
For instructions how to enable these alternatives, see Compile options / macros.
attach(int aPin, int aInitialDegreeOrMicrosecond, int aMicrosecondsForServoLowDegree, int aMicrosecondsForServoHighDegree, int aServoLowDegree, int aServoHighDegree).setIntegerDegreeForAllServos(3, 135, 135, 135).ServoEasing::ServoEasingArray[].Linear Quadratic Cubic Quartic
Sine Circular Back Elastic Bounce
Precision Dummy User defined
All ease functions are called internally with the value: PercentageOfCompletion / 100 giving a call value from 0 to 1.
Since the values are computed in a fixed 20 ms raster, the last degree increment or decrement in an easing may be much smaller than the increment/decrement before, resulting in some small discontinuities between adjacent movements.
To restrict servo movements to a fixed range, you can specify constraints with setMinMaxConstraint(int aMinDegreeOrMicrosecond, int aMaxDegreeOrMicrosecond) like it is done in the TwoServos example.
By setting speed -which is an uint16- to a real high value like e.g. 50000, you can effectively disable easing and get almost the same behavior as if using Servo.write() function directly.
For floating point constants, use the notation of 123.456f with trailing f (for a floating point constant) to avoid compiler errors. A Doxygen documentation of the sources is available here.
See also the examples here.
void setup() {
Servo1.attach(SERVO1_PIN, 45);
}
void loop() {
Servo1.setEasingType(EASE_CUBIC_IN_OUT); // EASE_LINEAR is default
Servo1.easeTo(135, 40); // Blocking call
Servo1.startEaseTo(45, 40, START_UPDATE_BY_INTERRUPT); // Non blocking call
// Now the servo is moving to the end position independently of your program.
delay(5000);
}Just call myServo.startEaseTo() instead of myServo.write() and you are done. Or if you want to wait (blocking) until servo has arrived, use myServo.easeTo().
Do not forget to initially set the start position for the Servo, since the library has no knowledge about your servos initial position and therefore starts at 0 ° at the first move, which may be undesirable.
Setting the start position of the servo can be done as the second parameter to myServo.attach(int aPin, int aInitialDegree) or by calling myServo.write(int aDegree),
And do not forget to initially set the moving speed (as degrees per second) with myServo.setSpeed() or as second parameter to startEaseTo() or easeTo(). Otherwise the Servo will start with the speed of 5 ° per second, to indicate that speed was not set.
You can handle multiple servos simultaneously by special functions like
writeAllServos(), setSpeedForAllServos(), setIntegerDegreeForAllServos(), setEaseToDForAllServos(), updateAndWaitForAllServosToStop(), `setEaseToForAllServosSynchronizeAndWaitFor
暂无开放 Issues,或尚未同步最近议题。