Ramp#

typedef struct uz_ramp_t uz_ramp_t#
struct uz_ramp_config#

Configuration struct for the ramp module.

Public Members

float maximum_slope_per_second#

Maximum output change per second in signal units

float sample_time_seconds#

Sample time of the ramp call

float initial_value#

Initial ramp output value

uz_ramp_t *uz_ramp_init(struct uz_ramp_config config)#

Initializes a ramp instance with configurable slope and sample time.

Parameters:
  • config – Configuration struct of the ramp module

Returns:

uz_ramp_t* Pointer to ramp instance

float uz_ramp_step(uz_ramp_t *self, float reference_value)#

Executes one ramp step and updates the internal output linearly towards the reference value.

Parameters:
  • self – Pointer instance of uz_ramp_t

  • reference_value – Target value for the ramp output

Returns:

float Current ramp output

void uz_ramp_set_to_value_instant(uz_ramp_t *self, float value)#

Sets the current ramp output to a defined value instantly without the ramp.

Parameters:
  • self – Pointer instance of uz_ramp_t

  • value – New current ramp output

void uz_ramp_reset(uz_ramp_t *self)#

Resets the current ramp output to zero.

Parameters:
  • self – Pointer instance of uz_ramp_t

Example#

Listing 67 Example ramp usage for a speed reference signal#
 1#include "uz_signals.h"
 2
 3int main(void) {
 4   struct uz_ramp_config config = {
 5      .maximum_slope_per_second = 100.0f,
 6      .sample_time_seconds = 0.0001f,
 7      .initial_value = 0.0f
 8   };
 9   uz_ramp_t *speed_reference_ramp = uz_ramp_init(config);
10   float reference_value = 500.0f;
11   float ramped_reference = uz_ramp_step(speed_reference_ramp, reference_value);
12}

Description#

uz_ramp_step limits the rate of change of a signal. On every call, the output moves linearly from the current output value towards the requested reference value. The maximum change per call \(\Delta_{max}\) is given by:

\[\Delta_{max} = slope_{max} \cdot T_s,\]

where \(slope_{max}\) is the configured maximum slope per second, and \(T_s\) is the sample time. If the remaining distance to the target is smaller than \(\Delta_{max}\), the output is set directly to the target value. Otherwise, the output changes by exactly \(\Delta_{max}\) in the direction of the target.

../../../_images/ramp01.png

Fig. 319 Result of a test scenario with an input change from 0 to 1000 with a configured slope of 100 per second.#

Changing the input reference_value during execution of the ramp, this changed input becomes the new target, and the ramp will re-aim toward the new reference_value.

../../../_images/ramp02.png

Fig. 320 Result of the test scenario above, where during execution of the ramp a new input value of 200 is provided.#

Warning

When not reset by calling uz_ramp_reset(uz_ramp_t *self), the ramp will keep its last output value.