FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
This template class supports one servomotor connected to a PWM pin. More...
#include <fastarduino/devices/servo.h>
Public Types | |
using | TIMER = TIMER_ |
The type of timer used to handle the connected servomotor. More... | |
using | TYPE = typename TIMER::TYPE |
The type of counter for TIMER_ . More... | |
Public Member Functions | |
Servo (TIMER &timer, uint16_t us_minimum, uint16_t us_maximum, uint16_t us_neutral=0) | |
Create a new servo handler, based on the provided timer (which will provide the frequency for pulse generation), and the additional parameters for pulse width. More... | |
void | detach () INLINE |
Detach the servomotor from this handler. More... | |
void | set_counter (TYPE value) INLINE |
Set the Timer counter that will change the pulse width, hence the servo angle. More... | |
void | set_pulse (uint16_t pulse_us) |
Set the pulse width in microsecond, hence the servo angle. More... | |
void | rotate (int8_t angle) |
Rotate the servomotor at the given angle position. More... | |
constexpr TYPE | calculate_counter (uint16_t pulse_us) const |
Calculate the counter value to use with set_counter() in order to generate a pulse of the given width. More... | |
Static Public Attributes | |
static constexpr const board::PWMPin | PWMPIN = PWMPIN_ |
The PWM pin for this PWMOutput. More... | |
static constexpr const board::DigitalPin | PIN = board_traits::PWMPin_trait<PWMPIN>::ACTUAL_PIN |
The pin to which the servomotor is connected. More... | |
This template class supports one servomotor connected to a PWM pin.
Servomotors are driven by the width of pulses generated at a specific frequency (specific to each model, but typically around 50Hz, i.e. one pulse every 20ms), a specific width matches a specific rotation angle of the servo.
TIMER_ | the type of timer used to handle the connected servomotor; this must be a timer::PulseTimer type. |
PWMPIN_ | the board::PWMPin to which the servomotor is connected; this must be a PWM pin, connected to TIMER_ . |
using devices::servo::Servo< TIMER_, PWMPIN_ >::TIMER = TIMER_ |
using devices::servo::Servo< TIMER_, PWMPIN_ >::TYPE = typename TIMER::TYPE |
|
inline |
Create a new servo handler, based on the provided timer
(which will provide the frequency for pulse generation), and the additional parameters for pulse width.
timer | the timer::PulseTimer that will handle pulse generation for this servomotor |
us_minimum | the minimal pulse width in microseconds; this matches the minimal angle of the servo. |
us_maximum | the maximal pulse width in microseconds: this matches the maximal angle of the servo. |
us_neutral | the pulse width, in microseconds, that matches the 0 angle; when not provided (or 0 ), it will be calculated as the average of us_minimum and us_maximum . |
|
inline |
|
inline |
Set the Timer counter that will change the pulse width, hence the servo angle.
This method is the most optimized way to change the servo angle. However, it requires preliminary calculation of counter values from the desired angles. Calculation can be performed by calculate_counter()
.
value | the new counter value to use for fixing pulse width |
|
inline |
Set the pulse width in microsecond, hence the servo angle.
This method is less optimized way than set_counter()
to change the servo angle.
pulse_us | the new pulse width in microseconds |
|
inline |
Rotate the servomotor at the given angle
position.
This method is less optimized than set_counter()
and more efficient than set_pulse()
, but it provides a more friendly API as it uses real physical parameters.
angle | the new angle, in degrees, to rotate the servo to; it must be between -90 and +90 . |
|
inlineconstexpr |
Calculate the counter value to use with set_counter()
in order to generate a pulse of the given width.
This method is constexpr
hence it can be evaluated at compile-time if provided with a constant value.
pulse_us | the pulse width, in microseconds, for which to compute the counter value |
pulse_us
width
|
staticconstexpr |
|
staticconstexpr |