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.
Public Functions Documentation¶
function syn_ramp_init¶
Initialize ramp generator.
Parameters:
rampRamp instance.initialStarting value.
function syn_ramp_jump¶
Jump immediately to a value (no ramp).
Parameters:
rampRamp instance.valueValue to jump to.
function syn_ramp_set_target¶
Set new target with linear ramp.
Parameters:
rampRamp instance.targetDesired final value.rateMax 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:
rampRamp instance.targetDesired final value.max_rateMax velocity (units/tick).accelAcceleration (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:
rampRamp instance.targetDesired final value (integer, not fixed-point).max_rateMax velocity in Qfrac_bits(e.g., Q8).accelAcceleration in Qfrac_bits.frac_bitsNumber of fractional bits (e.g., 8 for Q8).
function syn_ramp_update¶
Update the ramp — call once per tick.
Parameters:
rampRamp instance.
Returns:
Current output value.
Public Static Functions Documentation¶
function syn_ramp_done¶
Check if ramp has reached its target.
Parameters:
rampRamp instance.
Returns:
true if done.
function syn_ramp_value¶
Get current value without updating.
Parameters:
rampRamp instance.
Returns:
Current value.
The documentation for this class was generated from the following file src/syntropic/util/syn_ramp.h