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.
This component extends from Signal
Usage
Ramp(start_time=0.0, offset=0.0, duration, height)
Parameters:
Name | Description | Units | Default value |
---|---|---|---|
start_time | Time at which the signal starts changing from its offset value | s | 0 |
offset | Constant value added to the signal output | – | 0 |
duration | Duration of the ramp transition | s | |
height | Total height (amplitude) of the ramp | – |
Connectors
y
- This connector represents a real signal as an output from a component (RealOutput
)
Behavior
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"
Related
Examples
Experiments
Analyses
Tests