Skip to content

File syn_ramp.h

FileList > src > syntropic > util > syn_ramp.h

Go to the source code of this file

Ramp / motion profile generator. More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>

Classes

Type Name
struct SYN_Ramp
Ramp generator instance — current value, target, rate.

Public Types

Type Name
enum SYN_RampMode
Ramp profile mode.

Public Functions

Type Name
void syn_ramp_init (SYN_Ramp * ramp, int32_t initial)
Initialize ramp generator.
void syn_ramp_jump (SYN_Ramp * ramp, int32_t value)
Jump immediately to a value (no ramp).
void syn_ramp_set_target (SYN_Ramp * ramp, int32_t target, int32_t rate)
Set new target with linear ramp.
void syn_ramp_set_target_trapezoid (SYN_Ramp * ramp, int32_t target, int32_t max_rate, int32_t accel)
Set new target with trapezoidal ramp (acceleration/deceleration).
void syn_ramp_set_target_trapezoid_fp (SYN_Ramp * ramp, int32_t target, int32_t max_rate, int32_t accel, uint8_t frac_bits)
Set new target with fixed-point trapezoidal ramp.
int32_t syn_ramp_update (SYN_Ramp * ramp)
Update the ramp — call once per tick.

Public Static Functions

Type Name
bool syn_ramp_done (const SYN_Ramp * ramp)
Check if ramp has reached its target.
int32_t syn_ramp_value (const SYN_Ramp * ramp)
Get current value without updating.

Detailed Description

Generates smooth setpoint transitions for any controlled variable (valves, lights, temperature, motor speed, etc.).

Supports two modes: * LINEAR: constant slew rate * TRAPEZOID: acceleration/deceleration (trapezoidal velocity profile)

The trapezoid mode supports optional fixed-point velocity/acceleration via syn_ramp_set_target_trapezoid_fp(). This allows sub-unit-per-tick resolution — critical when converting from per-second to per-tick at high update rates where integer truncation would lose precision.

Usage:

static SYN_Ramp ramp;
syn_ramp_init(&ramp, 0);
syn_ramp_set_target(&ramp, 1000, 10);  // ramp to 1000 at 10/tick

// In your update loop:
int32_t output = syn_ramp_update(&ramp);

Public Types Documentation

enum SYN_RampMode

Ramp profile mode.

enum SYN_RampMode {
    SYN_RAMP_LINEAR = 0,
    SYN_RAMP_TRAPEZOID = 1
};


Public Functions Documentation

function syn_ramp_init

Initialize ramp generator.

void syn_ramp_init (
    SYN_Ramp * ramp,
    int32_t initial
) 

Parameters:

  • ramp Ramp instance.
  • initial Starting value.

function syn_ramp_jump

Jump immediately to a value (no ramp).

void syn_ramp_jump (
    SYN_Ramp * ramp,
    int32_t value
) 

Parameters:

  • ramp Ramp instance.
  • value Value to jump to.

function syn_ramp_set_target

Set new target with linear ramp.

void syn_ramp_set_target (
    SYN_Ramp * ramp,
    int32_t target,
    int32_t rate
) 

Parameters:

  • ramp Ramp instance.
  • target Desired final value.
  • rate Max change per update call (always positive).

function syn_ramp_set_target_trapezoid

Set new target with trapezoidal ramp (acceleration/deceleration).

void syn_ramp_set_target_trapezoid (
    SYN_Ramp * ramp,
    int32_t target,
    int32_t max_rate,
    int32_t accel
) 

Parameters:

  • ramp Ramp instance.
  • target Desired final value.
  • max_rate Max velocity (units/tick).
  • accel Acceleration (units/tick²). Controls smoothness.

function syn_ramp_set_target_trapezoid_fp

Set new target with fixed-point trapezoidal ramp.

void syn_ramp_set_target_trapezoid_fp (
    SYN_Ramp * ramp,
    int32_t target,
    int32_t max_rate,
    int32_t accel,
    uint8_t frac_bits
) 

Like syn_ramp_set_target_trapezoid(), but velocity and acceleration are in Qfrac_bits fixed-point. This allows sub-unit-per-tick resolution for smooth motion at high update rates.

Parameters:

  • ramp Ramp instance.
  • target Desired final value (integer, not fixed-point).
  • max_rate Max velocity in Qfrac_bits (e.g., Q8).
  • accel Acceleration in Qfrac_bits.
  • frac_bits Number of fractional bits (e.g., 8 for Q8).

function syn_ramp_update

Update the ramp — call once per tick.

int32_t syn_ramp_update (
    SYN_Ramp * ramp
) 

Parameters:

  • ramp Ramp instance.

Returns:

Current output value.


Public Static Functions Documentation

function syn_ramp_done

Check if ramp has reached its target.

static inline bool syn_ramp_done (
    const SYN_Ramp * ramp
) 

Parameters:

  • ramp Ramp instance.

Returns:

true if done.


function syn_ramp_value

Get current value without updating.

static inline int32_t syn_ramp_value (
    const SYN_Ramp * ramp
) 

Parameters:

  • ramp Ramp instance.

Returns:

Current value.



The documentation for this class was generated from the following file src/syntropic/util/syn_ramp.h