Skip to content

File syn_servo.c

FileList > motor > syn_servo.c

Go to the source code of this file

Servo controller implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_servo.h"
  • #include <string.h>

Public Functions

Type Name
void syn_servo_init (SYN_Servo * servo, uint16_t pulse_min, uint16_t pulse_max, uint16_t angle_range)
Initialize a servo.
void syn_servo_move_to (SYN_Servo * servo, uint16_t angle, uint16_t duration)
Start a smooth move to an angle.
void syn_servo_set_angle (SYN_Servo * servo, uint16_t angle)
Set servo position by angle (immediate).
void syn_servo_set_pulse (SYN_Servo * servo, uint16_t us)
Set servo position by raw pulse width (immediate).
void syn_servo_update (SYN_Servo * servo)
Update servo position for smooth movement.

Public Static Functions

Type Name
uint16_t angle_to_us (const SYN_Servo * s, uint16_t angle)
Convert angle to pulse width in microseconds.
uint16_t clamp_us (const SYN_Servo * s, uint16_t us)
Clamp pulse width to min/max range.

Public Functions Documentation

function syn_servo_init

Initialize a servo.

void syn_servo_init (
    SYN_Servo * servo,
    uint16_t pulse_min,
    uint16_t pulse_max,
    uint16_t angle_range
) 

Parameters:

  • servo Servo instance.
  • pulse_min Minimum pulse width in µs (0° position).
  • pulse_max Maximum pulse width in µs (max angle position).
  • angle_range Full angular range in degrees.

function syn_servo_move_to

Start a smooth move to an angle.

void syn_servo_move_to (
    SYN_Servo * servo,
    uint16_t angle,
    uint16_t duration
) 

Parameters:

  • servo Servo.
  • angle Target angle.
  • duration Movement duration in milliseconds.

function syn_servo_set_angle

Set servo position by angle (immediate).

void syn_servo_set_angle (
    SYN_Servo * servo,
    uint16_t angle
) 

Parameters:

  • servo Servo handle.
  • angle Angle in degrees (0 to angle_range).

function syn_servo_set_pulse

Set servo position by raw pulse width (immediate).

void syn_servo_set_pulse (
    SYN_Servo * servo,
    uint16_t us
) 

Parameters:

  • servo Servo handle.
  • us Pulse width in microseconds.

function syn_servo_update

Update servo position for smooth movement.

void syn_servo_update (
    SYN_Servo * servo
) 

Call periodically (e.g., every 10–20ms) while a smooth move is active.

Parameters:

  • servo Servo instance.

Public Static Functions Documentation

function angle_to_us

Convert angle to pulse width in microseconds.

static uint16_t angle_to_us (
    const SYN_Servo * s,
    uint16_t angle
) 

Parameters:

  • s Servo instance.
  • angle Angle (0 to angle_range).

Returns:

Pulse width in µs.


function clamp_us

Clamp pulse width to min/max range.

static uint16_t clamp_us (
    const SYN_Servo * s,
    uint16_t us
) 

Parameters:

  • s Servo instance.
  • us Pulse width in µs.

Returns:

Clamped pulse width.



The documentation for this class was generated from the following file src/syntropic/motor/syn_servo.c