Skyward boardcore
|
Driver to operate a PWM controlled servo motor. More...
#include <Servo.h>
Public Member Functions | |
Servo (TIM_TypeDef *const timer, TimerUtils::Channel pwmChannel, unsigned int minPulse=1000, unsigned int maxPulse=2000, unsigned int frequency=50) | |
Prepare the timer and sets the PWM output to the minimum. | |
void | enable () |
Starts producing the PWM signal. | |
void | disable () |
Stops producing the PWM signal. | |
void | setPosition (float position, bool limited=true) |
Set the position of the servomotor. | |
void | setPosition90Deg (float degrees) |
void | setPosition120Deg (float degrees) |
void | setPosition180Deg (float degrees) |
void | setPosition360Deg (float degrees) |
float | getPosition () |
Returns the current position of the servomotor. | |
float | getPosition90Deg () |
float | getPosition180Deg () |
float | getPosition360Deg () |
ServoData | getState () |
Returns the current position and the current timestamp. | |
Driver to operate a PWM controlled servo motor.
Servo motors often are controlled via a PWM signal. A PWM signal is a simple rectangular wave with a set frequency and duty cycle. Usually servo motor listen for a pulse with a specific duration between two limits you can set to this driver. The position is then proportional to the size of the pulse relative to the range. A PWM signal is then used to periodically tell the servo the position where it should be.
Also Servo motors comes in a variety of motion range configurations. This driver is prepared for non continuous rotation servo motor, which usually have a range of 90, 180 or 360 degrees. The driver accepts the position relative to the range (a percentage basically) but provides tree function to convert to and from degrees.
The PWM signal is disabled automatically when the Servo object is destructed and the output of the signal pin will be low.
Note that the peripheral clock of the undelying timer used to generate the PWM signal, is enabled when the object is created and disabled when destructed. When using the same timer for two or more sensors keep in mind that you could encounter issues.
|
explicit |
Prepare the timer and sets the PWM output to the minimum.
More specifically, the PWM output is prepared to be equal to minPulse but it is not enabled! After creating the object the PWM signal is not active. This is to ensure the servo motor doesn't move unexpectedly.
Note that the timer peripheral's clock is enabled automatically when the PWM object is created.
void Boardcore::Servo::disable | ( | ) |
void Boardcore::Servo::enable | ( | ) |
float Boardcore::Servo::getPosition | ( | ) |
ServoData Boardcore::Servo::getState | ( | ) |
void Boardcore::Servo::setPosition | ( | float | position, |
bool | limited = true ) |