Loading...
Searching...
No Matches
Servo Motor Driver

High-level driver for servo motors. More...

Detailed Description

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.

Modules

 PWM based servo driver
 
 SAUL integration of the servo driver
 
 periph_timer_periodic based servo driver
 

Files

file  servo.h
 High-level driver for easy handling of servo motors.
 
file  servo_params.h
 Default configuration for servo devices.
 

Data Structures

struct  servo_pwm_params_t
 PWM configuration parameters for a servos. More...
 
struct  servo_timer_ctx_t
 Memory needed for book keeping when using periph_timer_periodic based servo driver. More...
 
struct  servo_timer_params_t
 Timer configuration parameters for a servos. More...
 
struct  servo_params_t
 Configuration parameters for a servo. More...
 
struct  servo
 Servo device state. More...
 

Macros

#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.
 

Typedefs

typedef struct servo servo_t
 Servo device state.
 

Functions

int servo_init (servo_t *dev, const servo_params_t *params)
 Initialize servo.
 
void servo_set (servo_t *dev, uint8_t pos)
 Set the servo motor to a specified position.
 

Variables

const saul_driver_t servo_saul_driver
 The SAUL adaption driver for servos.
 
servo_timer_ctx_t servo_timer_default_ctx
 Default timer context.
 

Macro Definition Documentation

◆ 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.

Typedef Documentation

◆ servo_t

typedef struct servo servo_t

Servo device state.

Definition at line 92 of file servo.h.

Function Documentation

◆ servo_init()

int servo_init ( servo_t dev,
const servo_params_t params 
)

Initialize servo.

Parameters
[out]devDevice handle to initialize
[in]paramsParameters defining the PWM configuration
Return values
0Success
<0Failure (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]devthe servo to set
[in]posthe 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.