Class Servo
Defined in File servo.hpp
Class Documentation
-
class Servo
This class wraps around the PWM class to provide utilities for controlling a servo. In particular, this class limits some target PWM to a min and max PWM value and uses ramping to control the speed of the servo.
Public Functions
-
Servo(Drivers *drivers, tap::gpio::Pwm::Pin currpwmPinPort, float maximumPwm, float minimumPwm, float pwmRampSpeed)
Initializes the PWM bounds and associates the Servo with some PWM pin.
Note
maximumPwm
andminimumPwm
are limited to between [0, 1]. Also ifmaximumPwm
<minimumPwm
, an error is thrown and [minPwm, maxPwm] is set to [0, 1].- Parameters:
drivers – [in] Instance to the drivers class you would like to use.
pwmPin – [in] The pin to attach the Servo class with.
maximumPwm – [in] The maximum allowable PWM output. This is limited between 0 and 1.
minimumPwm – [in] The minimum allowable PWM output. This is limited between 0 and 1.
pwmRampSpeed – [in] The speed in PWM percent per millisecond.
-
void setTargetPwm(float PWM)
Limits
pwmOutputRamp
tominPwm
andmaxPwm
, then sets ramp output to the limited value. Do not repeatedly call (i.e. only call in aCommand
’sinitialize
function, for example).
-
void updateSendPwmRamp()
Updates the
pwmOutputRamp
object and then sets the output PWM to the updated ramp value.
-
float getPWM() const
- Returns:
The current PWM output to the servo.
-
float getMinPWM() const
- Returns:
The minimum PWM output (as a duty cycle).
-
float getMaxPWM() const
- Returns:
The maximum PWM output (as a duty cycle).
-
bool isRampTargetMet() const
- Returns:
true
if the ramp has met the desired PWM value (set withsetTargetPwm
). Use this to estimate when a servo movement is complete.
-
Servo(Drivers *drivers, tap::gpio::Pwm::Pin currpwmPinPort, float maximumPwm, float minimumPwm, float pwmRampSpeed)