Skip to content
Ramp.md

Ramp

Generates a linearly increasing signal from an offset to a target value over a specified duration.

The ramp component produces an output signal that starts at the offset value, then increases linearly to reach offset+height over the specified duration. After the duration elapses, the output remains constant at the final value.

y={offset,if t<start_timeoffset+(tstart_time)heightduration,if start_timet<start_time+durationoffset+height,if tstart_time+duration

This component extends from Signal

Usage

Ramp(start_time=0.0, offset=0.0, duration, height)

Parameters:

NameDescriptionUnitsDefault value
start_timeTime at which the signal starts changing from its offset values0
offsetConstant value added to the signal output0
durationDuration of the ramp transitions
heightTotal height (amplitude) of the ramp

Connectors

  • y - This connector represents a real signal as an output from a component (RealOutput)

Behavior

y(t)=ifelse(start_time<t,ifelse(t<duration+start_time,offset+height(start_time+t)duration,height+offset),offset)

Source

dyad
# Generates a linearly increasing signal from an offset to a target value over a specified duration.
#
# The ramp component produces an output signal that starts at the `offset` value, then increases
# linearly to reach `offset`+`height` over the specified `duration`. After the `duration` elapses, the
# output remains constant at the final value.
#
# ```math
# y = \begin{cases}
# \text{offset}, & \text{if } t < \text{start\_time} \\
# \text{offset} + (t - \text{start\_time}) \cdot \frac{\text{height}}{\text{duration}}, & \text{if } \text{start\_time} \leq t < \text{start\_time} + \text{duration} \\
# \text{offset} + \text{height}, & \text{if } t \geq \text{start\_time} + \text{duration}
# \end{cases}
# ```
component Ramp
  extends Signal
  # Duration of the ramp transition
  parameter duration::Time
  # Total height (amplitude) of the ramp
  parameter height::Real
relations
  y = if start_time<time then if time<start_time+duration then offset+(time-start_time)*height/duration else offset+height else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Ramp.svg"}}}
end
Flattened Source
dyad
# Generates a linearly increasing signal from an offset to a target value over a specified duration.
#
# The ramp component produces an output signal that starts at the `offset` value, then increases
# linearly to reach `offset`+`height` over the specified `duration`. After the `duration` elapses, the
# output remains constant at the final value.
#
# ```math
# y = \begin{cases}
# \text{offset}, & \text{if } t < \text{start\_time} \\
# \text{offset} + (t - \text{start\_time}) \cdot \frac{\text{height}}{\text{duration}}, & \text{if } \text{start\_time} \leq t < \text{start\_time} + \text{duration} \\
# \text{offset} + \text{height}, & \text{if } t \geq \text{start\_time} + \text{duration}
# \end{cases}
# ```
component Ramp
  # Real-valued output connector for the component
  y = RealOutput() [{"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 1050, "y2": 550}}}}]
  # Time at which the signal starts changing from its offset value
  parameter start_time::Time = 0.0
  # Constant value added to the signal output
  parameter offset::Real = 0.0
  # Duration of the ramp transition
  parameter duration::Time
  # Total height (amplitude) of the ramp
  parameter height::Real
relations
  y = if start_time<time then if time<start_time+duration then offset+(time-start_time)*height/duration else offset+height else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Ramp.svg"}}}
end


Test Cases

This is setup code, that must be run before each test case.

julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"