High-level driver for servo motors.
More...
High-level driver for servo motors.
Usage
Select a flavor of the driver, e.g. USEMODULE += servo_pwm
for PWM based servo driver or USEMODULE += servo_timer
for periph_timer_periodic based servo driver to use. Typically, the PWM implementation is the preferred one, but some MCU (e.g. nRF52xxx) cannot configure the PWM peripheral to run anywhere close to the 50 Hz to 100 Hz required.
In addition, you many need to extend or adapt servo_params and, depending on the selected implementation, servo_pwm_params or servo_timer_params to match your hardware configuration.
The test application in tests/drivers/servo
can serve as starting point for users.
|
file | servo.h |
| High-level driver for easy handling of servo motors.
|
|
file | servo_params.h |
| Default configuration for servo devices.
|
|
|
#define | SERVO_TIMER_MAX_CHAN 4 |
| In case the servo_timer backend is used to driver the servo, this is the highest channel number usable by the driver.
|
|
◆ SERVO_TIMER_MAX_CHAN
#define SERVO_TIMER_MAX_CHAN 4 |
In case the servo_timer
backend is used to driver the servo, this is the highest channel number usable by the driver.
- Note
- To drive n servos, n + 1 timer channels are required. Hence, this must be at least 2
Trimming this down safes a small bit of RAM: Storage for one pointer is wasted on every servo that could be controlled by a timer but is not actually used.
Definition at line 66 of file servo.h.
◆ servo_t
Servo device state.
Definition at line 92 of file servo.h.
◆ servo_init()
Initialize servo.
- Parameters
-
[out] | dev | Device handle to initialize |
[in] | params | Parameters defining the PWM configuration |
- Return values
-
0 | Success |
<0 | Failure (as negative errno code to indicate cause) |
◆ servo_set()
void servo_set |
( |
servo_t * |
dev, |
|
|
uint8_t |
pos |
|
) |
| |
Set the servo motor to a specified position.
The position of the servo is specified in the fraction of maximum extension, with 0 being the lowest extension (e.g. on an 180° servo it would be at -90°) and UINT8_MAX
being the highest extension (e.g. +90° on that 180° servo).
- Parameters
-
[in] | dev | the servo to set |
[in] | pos | the extension to set |
Note: 8 bit of resolution may seem low, but is indeed more than high enough for any practical PWM based servo. For higher precision, stepper motors would be required.