ModelingToolkitStandardLibrary: Blocks

Utility Blocks

ModelingToolkitStandardLibrary.Blocks.RealInputFunction
RealInput(;name, nin, u_start)

Connector with one input signal of type Real.

Parameters:

  • nin=1: Number of inputs
  • u_start=0: Initial value for u

States:

  • u: Value of of the connector; if nin=1 this is a scalar
ModelingToolkitStandardLibrary.Blocks.RealOutputFunction
RealOutput(;name, nout, u_start)

Connector with one output signal of type Real.

Parameters:

  • nout=1: Number of inputs
  • u_start=0: Initial value for u

States:

  • u: Value of of the connector; if nout=1 this is a scalar
ModelingToolkitStandardLibrary.Blocks.SISOFunction
SISO(;name, u_start=0.0, y_start=0.0)

Single Input Single Output continuous control block.

Parameters:

  • u_start: Initial value for the input
  • y_start: Initial value for the output

Math Blocks

ModelingToolkitStandardLibrary.Blocks.AddFunction
Add(;name, k1=1, k2=1)

Output the sum of the two scalar inputs.

Parameters:

  • k1: Gain for first input
  • k2: Gain for second input

Connectors:

  • input1
  • input2
  • output
ModelingToolkitStandardLibrary.Blocks.Add3Function
Add(;name, k1=1, k2=1,k3=1)

Output the sum of the three scalar inputs.

Parameters:

  • k1: Gain for first input
  • k2: Gain for second input
  • k3: Gain for third input

Connectors:

  • input1
  • input2
  • input3
  • output
ModelingToolkitStandardLibrary.Blocks.StaticNonLinearityFunction
StaticNonLinearity(func ;name)

Applies the given function to the input.

If the given function is not composed of simple core methods (e.g. sin, abs, ...), it has to be registered via @register_symbolic func(u)

Connectors:

  • input
  • output

Source Blocks

ModelingToolkitStandardLibrary.Blocks.SineFunction

Generate sine signal.

Parameters:

  • frequency: [Hz] Frequency of sine wave
  • amplitude: Amplitude of sine wave
  • phase: [rad] Phase of sine wave
  • offset: Offset of output signal
  • start_time: [s] Output y = offset for t < start_time
  • smooth: If true, returns a smooth wave. Defaults to false It uses a smoothing factor of δ=1e-5

Connectors:

  • output
Missing docstring.

Missing docstring for Cosine. Check Documenter's build log for details.

ModelingToolkitStandardLibrary.Blocks.RampFunction

Generate ramp signal.

Parameters:

  • height: Height of ramp
  • duration: [s] Duration of ramp (= 0.0 gives a Step)
  • offset: Offset of output signal
  • start_time: [s] Output y = offset for t < start_time
  • smooth: If true, returns a smooth wave. Defaults to false It uses a smoothing factor of δ=1e-5

Connectors:

  • output
ModelingToolkitStandardLibrary.Blocks.StepFunction
Step(;name, height=1, offset=0, start_time=0, duration=Inf, smooth=true)

Generate step signal.

Parameters:

  • height: Height of step
  • offset: Offset of output signal
  • start_time: [s] Output y = offset for t < start_time and thereafter offset+height.
  • duration: [s] If duration < Inf is supplied, the output will revert to offset after duration seconds.
  • smooth: If true, returns a smooth wave. Defaults to false It uses a smoothing factor of δ=1e-5

Connectors:

  • output
ModelingToolkitStandardLibrary.Blocks.ExpSineFunction

Generate exponentially damped sine signal.

Parameters:

  • frequency: [Hz] Frequency of sine wave
  • amplitude: Amplitude of sine wave
  • damping: [1/s] Damping coefficient of sine wave
  • phase: [rad] Phase of sine wave
  • offset: Offset of output signal
  • start_time: [s] Output y = offset for t < start_time
  • smooth: If true, returns a smooth wave. Defaults to false It uses a smoothing factor of δ=1e-5

Connectors:

  • output

Nonlinear Blocks

ModelingToolkitStandardLibrary.Blocks.LimiterFunction
Limiter(;name, y_max, y_min=y_max > 0 ? -y_max : -Inf)

Limit the range of a signal.

Parameters:

  • y_max: Maximum of output signal
  • y_min: Minimum of output signal

Connectors:

  • input
  • output
ModelingToolkitStandardLibrary.Blocks.DeadZoneFunction
DeadZone(; name, u_max, u_min=-u_max)

The DeadZone block defines a region of zero output. If the input is within u_min ... u_max, the output is zero. Outside of this zone, the output is a linear function of the input with a slope of 1.

       y▲
        │     /
        │    /
  u_min │   /
─────|──┼──|───────► u
    /   │   u_max
   /    │
  /     │

Parameters:

  • u_max: Upper limit of dead zone
  • u_min: Lower limit of dead zone

Connectors:

  • input
  • output
ModelingToolkitStandardLibrary.Blocks.SlewRateLimiterFunction
SlewRateLimiter(;name, rising=1, falling=-rising, Td=0.001, y_start=0.0)

Limits the slew rate of a signal.

Parameters:

  • rising: Maximum rising slew rate
  • falling: Maximum falling slew rate
  • Td: [s] Derivative time constant

Connectors:

  • input
  • output

Continuous Blocks

ModelingToolkitStandardLibrary.Blocks.IntegratorFunction
Integrator(;name, k=1, x_start=0.0)

Outputs y = ∫k*u dt, corresponding to the transfer function 1/s.

Connectors:

  • input
  • output

Parameters:

  • k: Gain of integrator
  • x_start: Initial value of integrator
ModelingToolkitStandardLibrary.Blocks.DerivativeFunction
Derivative(; name, k=1, T, x_start=0.0)

Outputs an approximate derivative of the input. The transfer function of this block is

k       k     
─ - ──────────
T    2 ⎛    1⎞
    T ⋅⎜s + ─⎟
       ⎝    T⎠

and a state-space realization is given by ss(-1/T, 1/T, -k/T, k/T) where T is the time constant of the filter. A smaller T leads to a more ideal approximation of the derivative.

Parameters:

  • k: Gain
  • T: [s] Time constants (T>0 required; T=0 is ideal derivative block)
  • x_start: Initial value of state

Connectors:

  • input
  • output
ModelingToolkitStandardLibrary.Blocks.FirstOrderFunction
FirstOrder(; name, k=1, T, x_start=0.0)

A first-order filter with a single real pole in s = -T and gain k. The transfer function is given by Y(s)/U(s) =

   k   
───────
sT + 1

Parameters:

  • k: Gain
  • T: [s] Time constants (T>0 required)
  • x_start: Initial value of state

Connectors:

  • input
  • output

See also SecondOrder

ModelingToolkitStandardLibrary.Blocks.SecondOrderFunction
SecondOrder(; name, k=1, w, d, x_start=0.0, xd_start=0.0)

A second-order filter with gain k, a bandwidth of w rad/s and relative damping d. The transfer function is given by Y(s)/U(s) =

      k*w^2   
─────────────────
s² + 2d*w*s + w^2

Critical damping corresponds to d=1, which yields the fastest step response without overshoot, d < 1results in an under-damped filter whiled > 1results in an over-damped filter.d = 1/√2` corresponds to a Butterworth filter of order 2 (maximally flat frequency response).

Parameters:

  • k: Gain
  • w: Angular frequency
  • d: Damping
  • x_start: Initial value of state (output)
  • xd_start: Initial value of derivative of state (output)

Connectors:

  • input
  • output
ModelingToolkitStandardLibrary.Blocks.StateSpaceFunction
StateSpace(A, B, C, D=0; x_start=zeros(size(A,1)), name)

A linear, time-invariant state-space system on the form.

ẋ = Ax + Bu
y = Cx + Du

Transfer functions can also be simulated by converting them to a StateSpace form.

ModelingToolkitStandardLibrary.Blocks.PIFunction
PI(;name, k=1, T, x_start=0.0)

Textbook version of a PI-controller without actuator saturation and anti-windup measure.

Parameters:

  • k: Gain
  • T: [s] Integrator time constant (T>0 required)
  • x_start: Initial value for the integrator

Connectors:

  • err_input
  • ctr_output

See also LimPI

ModelingToolkitStandardLibrary.Blocks.LimPIFunction
LimPI(;name, k=1, T, u_max=1, u_min=-u_max, Ta)

Text-book version of a PI-controller with actuator saturation and anti-windup measure.

Parameters:

  • k: Gain
  • T: [s] Integrator time constant (T>0 required)
  • Ta: [s] Tracking time constant (Ta>0 required)
  • x_start: Initial value for the integrator

Connectors:

  • err_input
  • ctr_output
ModelingToolkitStandardLibrary.Blocks.PIDFunction
PID(;name, k=1, Ti=false, Td=false, Nd=10, xi_start=0, xd_start=0)

Text-book version of a PID-controller without actuator saturation and anti-windup measure.

Parameters:

  • k: Gain
  • Ti: [s] Integrator time constant (Ti>0 required). If set to false no integral action is used.
  • Td: [s] Derivative time constant (Td>0 required). If set to false no derivative action is used.
  • Nd: [s] Time constant for the derivative approximation (Nd>0 required; Nd=0 is ideal derivative).
  • x_start: Initial value for the integrator.
  • xd_start: Initial value for the derivative state.

Connectors:

  • err_input
  • ctr_output

See also LimPID

ModelingToolkitStandardLibrary.Blocks.LimPIDFunction
LimPID(; k, Ti=false, Td=false, wp=1, wd=1, Ni, Nd=12, u_max=Inf, u_min=-u_max, gains = false, name)

Proportional-Integral-Derivative (PID) controller with output saturation, set-point weighting and integrator anti-windup.

The equation for the control signal is roughly

k(ep + 1/Ti * ∫e + 1/Td * d/dt(ed))
e = u_r - u_y
ep = wp*u_r - u_y
ed = wd*u_r - u_y

where the transfer function for the derivative includes additional filtering, see ? Derivative for more details.

Parameters:

  • k: Proportional gain
  • Ti: [s] Integrator time constant. Set to false to turn off integral action.
  • Td: [s] Derivative time constant. Set to false to turn off derivative action.
  • wp: [0,1] Set-point weighting in the proportional part.
  • wd: [0,1] Set-point weighting in the derivative part.
  • Nd: [1/s] Derivative limit, limits the derivative gain to Nd/Td. Reasonable values are ∈ [8, 20]. A higher value gives a better approximation of an ideal derivative at the expense of higher noise amplification.
  • Ni: Ni*Ti controls the time constant Ta of anti-windup tracking. A common (default) choice is Ta = √(Ti*Td) which is realized by Ni = √(Td / Ti). Anti-windup can be effectively turned off by setting Ni = Inf.

gains: Ifgains = true,TiandTdwill be interpreted as gains with a fundamental PID transfer function on parallel formki=Ti, kd=Td, k + ki/s + kd*s`

Connectors:

  • reference
  • measurement
  • ctr_output