TrajectoryLimiter Icon
TrajectoryLimiter
Trajectory limiter: a nonlinear filter that converts an arbitrary reference signal into a trajectory whose first and second time derivatives are bounded.
The block implements the discrete-time nonlinear filter of Zanasi, Guarino Lo Bianco and Tonielli, "Nonlinear filters for the generation of smooth trajectories", Automatica 36 (2000), as implemented in TrajectoryLimiter of the Julia package TrajectoryLimiters.jl. When the reference is a position, the outputs yd and ydd are the velocity and the acceleration of the limited trajectory; when the reference is a velocity, they are the acceleration and the jerk.
The output $x = y$ is the output of a double integrator $\ddot x = a$ whose input $a$ is computed by a discrete-time sliding-mode control law that drives $x$ toward the reference $r = u$, subject to $|\dot x| \le \dot x_M$ and $|a| \le \ddot x_M$, where $\dot x_M$ is yd_max and $\ddot x_M$ is ydd_max. The derivative of the reference is estimated by the backward difference $\dot r_k = (r_k - r_{k-1}) / T_s$. With $e = x - r$, $\dot e = \dot x - \dot r$ and $U = \ddot x_M$, the control law is
\[\begin{aligned} z &= \frac{1}{T_s U}\left(\frac{e}{T_s} + \frac{\dot e}{2}\right), \qquad \dot z = \frac{\dot e}{T_s U}, \qquad m = \left\lfloor \frac{1 + \sqrt{1 + 8|z|}}{2} \right\rfloor, \\ \sigma &= \dot z + \frac{z}{m} + \frac{m - 1}{2}\operatorname{sign}(z), \\ a &= -U \operatorname{sat}(\sigma) \, \frac{1 + \operatorname{sign}\left(\dot x \operatorname{sign}(\sigma) + \dot x_M - T_s U\right)}{2}, \end{aligned}\]
where $\operatorname{sat}$ denotes saturation to $[-1, 1]$. The state is propagated by
\[\dot x_{k+1} = \dot x_k + T_s a_k, \qquad x_{k+1} = x_k + \frac{T_s}{2}\left(\dot x_k + \dot x_{k+1}\right).\]
When the reference changes faster than the bounds permit, the output deviates from it and converges back to it once the bounds permit; for a step in the reference, the transient is approximately time-optimal under the bounds. After the transient, a reference with constant first time derivative is tracked without error. A reference with nonzero second time derivative $\ddot r$ is tracked with an error proportional to $T_s^2 \ddot r$, also when it satisfies both bounds.
The parameters must satisfy $T_s \ddot x_M < \dot x_M$. Otherwise the factor in the control law that enforces the bound on $\dot x$ is zero at $\dot x = 0$, and an output that starts at rest does not move.
With bounds_as_inputs = true, the bounds $\dot x_M$ and $\ddot x_M$ are the values of the inputs yd_max_in and ydd_max_in at the current sample, and the parameters yd_max and ydd_max are not used. The state of the limiter does not depend on the bounds, so a change of the bounds leaves y and yd continuous, and ydd satisfies the bound of the current sample. The inputs must satisfy the same conditions as the parameters at every sample. When $\dot x_M$ decreases below the current $|\dot x|$, the control law only prevents a further increase of $|\dot x|$; $|\dot x|$ is not reduced to the new bound until the deceleration toward the reference begins.
The outputs y and yd at sample $k$ are the state $x_k, \dot x_k$, which depends only on the reference samples before $k$, while ydd is the value $a_k$ applied from sample $k$ to sample $k+1$, which depends on the current reference sample. The outputs y and yd therefore have no direct feedthrough from the input, and the three outputs are mutually consistent, which makes them suitable as references and feedforward signals for a tracking controller.
The state of the limiter at the first sample consists of $x$ and $\dot x$, which equal the first samples of the outputs y and yd. The estimate of the reference derivative at the first sample is zero under every initialization variant. The scalar variants specify $x$ only and set $\dot x = 0$:
InitialOutput(y0=...): the first sample ofyequalsy0.SteadyState: the first sample ofyequals the first reference sample, so a constant reference produces no transient.InitialState(x0=...): the first sample ofyequalsx0.
The array variants specify both $x$ and $\dot x$:
InitialStateArray(x0=[x, xd])andInitialOutputArray(y0=[x, xd]): the first samples ofyandydequalxandxd. The two variants are equivalent, since the outputsyandydequal the state.
Usage
DiscreteComponents.TrajectoryLimiter(yd_max=1.0, ydd_max=1.0)
Parameters:
| Name | Description | Units | Default value |
|---|---|---|---|
Ts | Sample interval [s] | – | SampleTime() |
bounds_as_inputs | Whether the bounds are given by the inputs yd_max_in and ydd_max_in instead of the parameters yd_max and ydd_max | – | false |
initialization | Initial-condition specification | – | DiscreteCom...t(; y0=0.0) |
yd_max | Upper bound on the magnitude of the first time derivative [units of u per second]. Must exceed Ts*yddmax (only used if `boundsas_inputs = false`) | – | 1.0 |
ydd_max | Upper bound on the magnitude of the second time derivative [units of u per second squared]. Must be positive and less than ydmax/Ts (only used if `boundsas_inputs = false`) | – | 1.0 |
Connectors
u- This connector represents a real signal as an input to a component (RealInput)y- This connector represents a real signal as an output from a component (RealOutput)yd- This connector represents a real signal as an output from a component (RealOutput)ydd- This connector represents a real signal as an output from a component (RealOutput)yd_max_in- This connector represents a real signal as an input to a component (RealInput)ydd_max_in- This connector represents a real signal as an input to a component (RealInput)
Variables
| Name | Description | Units |
|---|---|---|
r_rate | Backward-difference estimate of the time derivative of the reference | – |
e | Error with respect to the reference | – |
e_rate | Time derivative of the error | – |
z | Normalized error variable z | – |
z_rate | Normalized time derivative of the error | – |
m | Integer-valued switching index m | – |
sigma | Sliding variable | – |
ydM | Active bound on the magnitude of the first time derivative | – |
yddM | Active bound on the magnitude of the second time derivative | – |
Behavior
12-element Vector{Symbolics.Equation}:
r_rate(t) ~ (-Shift(t, -1)(u(t)) + u(t)) / ModelingToolkitBase.SampleTime(ModelingToolkitBase.ShiftIndex(InferredClock.Inferred(Base.UUID("4e2a044e-1d98-4dcc-9363-c51144eca353")), 0), nothing)()
e(t) ~ -u(t) + y(t)
e_rate(t) ~ -r_rate(t) + yd(t)
z(t) ~ (e_rate(t) / 2 + e(t) / ModelingToolkitBase.SampleTime(ModelingToolkitBase.ShiftIndex(InferredClock.Inferred(Base.UUID("4e2a044e-1d98-4dcc-9363-c51144eca353")), 0), nothing)()) / (ModelingToolkitBase.SampleTime(ModelingToolkitBase.ShiftIndex(InferredClock.Inferred(Base.UUID("4e2a044e-1d98-4dcc-9363-c51144eca353")), 0), nothing)()*yddM(t))
z_rate(t) ~ e_rate(t) / (ModelingToolkitBase.SampleTime(ModelingToolkitBase.ShiftIndex(InferredClock.Inferred(Base.UUID("4e2a044e-1d98-4dcc-9363-c51144eca353")), 0), nothing)()*yddM(t))
m(t) ~ floor((1 + sqrt(1 + 8abs(z(t)))) / 2)
sigma(t) ~ z_rate(t) + z(t) / m(t) + (1//2)*(-1 + m(t))*sign(z(t))
ydd(t) ~ (-1//2)*clamp(sigma(t), -1, 1)*(1 + sign(ydM(t) - ModelingToolkitBase.SampleTime(ModelingToolkitBase.ShiftIndex(InferredClock.Inferred(Base.UUID("4e2a044e-1d98-4dcc-9363-c51144eca353")), 0), nothing)()*yddM(t) + sign(sigma(t))*yd(t)))*yddM(t)
yd(t) ~ Shift(t, -1)(yd(t)) + ModelingToolkitBase.SampleTime(ModelingToolkitBase.ShiftIndex(InferredClock.Inferred(Base.UUID("4e2a044e-1d98-4dcc-9363-c51144eca353")), 0), nothing)()*Shift(t, -1)(ydd(t))
y(t) ~ Shift(t, -1)(y(t)) + (1//2)*ModelingToolkitBase.SampleTime(ModelingToolkitBase.ShiftIndex(InferredClock.Inferred(Base.UUID("4e2a044e-1d98-4dcc-9363-c51144eca353")), 0), nothing)()*(Shift(t, -1)(yd(t)) + yd(t))
ydM(t) ~ yd_max
yddM(t) ~ ydd_maxSource
"""
Trajectory limiter: a nonlinear filter that converts an arbitrary reference signal into a trajectory whose first and second time derivatives are bounded.
The block implements the discrete-time nonlinear filter of Zanasi, Guarino Lo Bianco and Tonielli, "Nonlinear filters for the generation of smooth trajectories", Automatica 36 (2000), as implemented in `TrajectoryLimiter` of the Julia package [TrajectoryLimiters.jl](https://github.com/baggepinnen/TrajectoryLimiters.jl). When the reference is a position, the outputs `yd` and `ydd` are the velocity and the acceleration of the limited trajectory; when the reference is a velocity, they are the acceleration and the jerk.
The output ``x = y`` is the output of a double integrator ``\ddot x = a`` whose input ``a`` is computed by a discrete-time sliding-mode control law that drives ``x`` toward the reference ``r = u``, subject to ``|\dot x| \le \dot x_M`` and ``|a| \le \ddot x_M``, where ``\dot x_M`` is `yd_max` and ``\ddot x_M`` is `ydd_max`. The derivative of the reference is estimated by the backward difference ``\dot r_k = (r_k - r_{k-1}) / T_s``. With ``e = x - r``, ``\dot e = \dot x - \dot r`` and ``U = \ddot x_M``, the control law is
```math
\begin{aligned}
z &= \frac{1}{T_s U}\left(\frac{e}{T_s} + \frac{\dot e}{2}\right), \qquad \dot z = \frac{\dot e}{T_s U}, \qquad m = \left\lfloor \frac{1 + \sqrt{1 + 8|z|}}{2} \right\rfloor, \\
\sigma &= \dot z + \frac{z}{m} + \frac{m - 1}{2}\operatorname{sign}(z), \\
a &= -U \operatorname{sat}(\sigma) \, \frac{1 + \operatorname{sign}\left(\dot x \operatorname{sign}(\sigma) + \dot x_M - T_s U\right)}{2},
\end{aligned}
```
where ``\operatorname{sat}`` denotes saturation to ``[-1, 1]``. The state is propagated by
```math
\dot x_{k+1} = \dot x_k + T_s a_k, \qquad x_{k+1} = x_k + \frac{T_s}{2}\left(\dot x_k + \dot x_{k+1}\right).
```
When the reference changes faster than the bounds permit, the output deviates from it and converges back to it once the bounds permit; for a step in the reference, the transient is approximately time-optimal under the bounds. After the transient, a reference with constant first time derivative is tracked without error. A reference with nonzero second time derivative ``\ddot r`` is tracked with an error proportional to ``T_s^2 \ddot r``, also when it satisfies both bounds.
The parameters must satisfy ``T_s \ddot x_M < \dot x_M``. Otherwise the factor in the control law that enforces the bound on ``\dot x`` is zero at ``\dot x = 0``, and an output that starts at rest does not move.
With `bounds_as_inputs = true`, the bounds ``\dot x_M`` and ``\ddot x_M`` are the values of the inputs `yd_max_in` and `ydd_max_in` at the current sample, and the parameters `yd_max` and `ydd_max` are not used. The state of the limiter does not depend on the bounds, so a change of the bounds leaves `y` and `yd` continuous, and `ydd` satisfies the bound of the current sample. The inputs must satisfy the same conditions as the parameters at every sample. When ``\dot x_M`` decreases below the current ``|\dot x|``, the control law only prevents a further increase of ``|\dot x|``; ``|\dot x|`` is not reduced to the new bound until the deceleration toward the reference begins.
The outputs `y` and `yd` at sample ``k`` are the state ``x_k, \dot x_k``, which depends only on the reference samples before ``k``, while `ydd` is the value ``a_k`` applied from sample ``k`` to sample ``k+1``, which depends on the current reference sample. The outputs `y` and `yd` therefore have no direct feedthrough from the input, and the three outputs are mutually consistent, which makes them suitable as references and feedforward signals for a tracking controller.
The state of the limiter at the first sample consists of ``x`` and ``\dot x``, which equal the first samples of the outputs `y` and `yd`. The estimate of the reference derivative at the first sample is zero under every `initialization` variant. The scalar variants specify ``x`` only and set ``\dot x = 0``:
- `InitialOutput(y0=...)`: the first sample of `y` equals `y0`.
- `SteadyState`: the first sample of `y` equals the first reference sample, so a constant reference produces no transient.
- `InitialState(x0=...)`: the first sample of `y` equals `x0`.
The array variants specify both ``x`` and ``\dot x``:
- `InitialStateArray(x0=[x, xd])` and `InitialOutputArray(y0=[x, xd])`: the first samples of `y` and `yd` equal `x` and `xd`. The two variants are equivalent, since the outputs `y` and `yd` equal the state.
"""
component TrajectoryLimiter@[input clk extends Discrete]
"Reference"
u = RealInput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 150, "x2": 0, "y2": 250, "rot": 0}
},
"tags": []
}
}
"Limited trajectory"
y = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 150, "x2": 1100, "y2": 250, "rot": 0}
},
"tags": []
}
}
"First time derivative of the limited trajectory [units of u per second]"
yd = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Second time derivative of the limited trajectory [units of u per second squared]"
ydd = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 750, "x2": 1100, "y2": 850, "rot": 0}
},
"tags": []
}
}
"Upper bound on the magnitude of the first time derivative [units of u per second] (only active if `bounds_as_inputs = true`)"
yd_max_in = RealInput@[clk]() if bounds_as_inputs {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Upper bound on the magnitude of the second time derivative [units of u per second squared] (only active if `bounds_as_inputs = true`)"
ydd_max_in = RealInput@[clk]() if bounds_as_inputs {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 750, "x2": 0, "y2": 850, "rot": 0}
},
"tags": []
}
}
"Sample interval [s]"
structural parameter Ts::Real = SampleTime()
"Whether the bounds are given by the inputs `yd_max_in` and `ydd_max_in` instead of the parameters `yd_max` and `ydd_max`"
structural parameter bounds_as_inputs::Boolean = false
"Upper bound on the magnitude of the first time derivative [units of u per second]. Must exceed Ts*ydd_max (only used if `bounds_as_inputs = false`)"
parameter yd_max::Real = 1.0
"Upper bound on the magnitude of the second time derivative [units of u per second squared]. Must be positive and less than yd_max/Ts (only used if `bounds_as_inputs = false`)"
parameter ydd_max::Real = 1.0
"Initial-condition specification"
structural parameter initialization::InitialCondition = DiscreteComponents.InitialCondition.InitialOutput(y0 = 0.0)
"Backward-difference estimate of the time derivative of the reference"
variable r_rate::Real
"Error with respect to the reference"
variable e::Real
"Time derivative of the error"
variable e_rate::Real
"Normalized error variable z"
variable z::Real
"Normalized time derivative of the error"
variable z_rate::Real
"Integer-valued switching index m"
variable m::Real
"Sliding variable"
variable sigma::Real
"Active bound on the magnitude of the first time derivative"
variable ydM::Real
"Active bound on the magnitude of the second time derivative"
variable yddM::Real
relations
if bounds_as_inputs
ydM = yd_max_in
yddM = ydd_max_in
else
ydM = yd_max
yddM = ydd_max
end
r_rate = (u - u@(clk-1)) / Ts
e = y - u
e_rate = yd - r_rate
z = (e / Ts + e_rate / 2) / (Ts * yddM)
z_rate = e_rate / (Ts * yddM)
m = floor((1 + sqrt(1 + 8 * abs(z))) / 2)
sigma = z_rate + z / m + (m - 1) / 2 * sign(z)
ydd = -yddM * clamp(sigma, -1, 1) * (1 + sign(yd * sign(sigma) + ydM - Ts * yddM)) / 2
yd = yd@(clk-1) + Ts * ydd@(clk-1)
y = y@(clk-1) + Ts / 2 * (yd + yd@(clk-1))
initial ydd@(clk-1) = 0
initial u@(clk-1) = u
switch initialization
case InitialOutput
initial yd@(clk-1) = 0
initial y@(clk-1) = initialization.y0
case SteadyState
initial yd@(clk-1) = 0
initial y@(clk-1) = u
case InitialState
initial yd@(clk-1) = 0
initial y@(clk-1) = initialization.x0
case InitialStateArray
initial yd@(clk-1) = initialization.x0[2]
initial y@(clk-1) = initialization.x0[1] - Ts * initialization.x0[2]
case InitialOutputArray
initial yd@(clk-1) = initialization.y0[2]
initial y@(clk-1) = initialization.y0[1] - Ts * initialization.y0[2]
end
metadata {
"Dyad": {"icons": {"default": "dyad://DiscreteComponents/TrajectoryLimiter.svg"}}
}
end
Flattened Source
"""
Trajectory limiter: a nonlinear filter that converts an arbitrary reference signal into a trajectory whose first and second time derivatives are bounded.
The block implements the discrete-time nonlinear filter of Zanasi, Guarino Lo Bianco and Tonielli, "Nonlinear filters for the generation of smooth trajectories", Automatica 36 (2000), as implemented in `TrajectoryLimiter` of the Julia package [TrajectoryLimiters.jl](https://github.com/baggepinnen/TrajectoryLimiters.jl). When the reference is a position, the outputs `yd` and `ydd` are the velocity and the acceleration of the limited trajectory; when the reference is a velocity, they are the acceleration and the jerk.
The output ``x = y`` is the output of a double integrator ``\ddot x = a`` whose input ``a`` is computed by a discrete-time sliding-mode control law that drives ``x`` toward the reference ``r = u``, subject to ``|\dot x| \le \dot x_M`` and ``|a| \le \ddot x_M``, where ``\dot x_M`` is `yd_max` and ``\ddot x_M`` is `ydd_max`. The derivative of the reference is estimated by the backward difference ``\dot r_k = (r_k - r_{k-1}) / T_s``. With ``e = x - r``, ``\dot e = \dot x - \dot r`` and ``U = \ddot x_M``, the control law is
```math
\begin{aligned}
z &= \frac{1}{T_s U}\left(\frac{e}{T_s} + \frac{\dot e}{2}\right), \qquad \dot z = \frac{\dot e}{T_s U}, \qquad m = \left\lfloor \frac{1 + \sqrt{1 + 8|z|}}{2} \right\rfloor, \\
\sigma &= \dot z + \frac{z}{m} + \frac{m - 1}{2}\operatorname{sign}(z), \\
a &= -U \operatorname{sat}(\sigma) \, \frac{1 + \operatorname{sign}\left(\dot x \operatorname{sign}(\sigma) + \dot x_M - T_s U\right)}{2},
\end{aligned}
```
where ``\operatorname{sat}`` denotes saturation to ``[-1, 1]``. The state is propagated by
```math
\dot x_{k+1} = \dot x_k + T_s a_k, \qquad x_{k+1} = x_k + \frac{T_s}{2}\left(\dot x_k + \dot x_{k+1}\right).
```
When the reference changes faster than the bounds permit, the output deviates from it and converges back to it once the bounds permit; for a step in the reference, the transient is approximately time-optimal under the bounds. After the transient, a reference with constant first time derivative is tracked without error. A reference with nonzero second time derivative ``\ddot r`` is tracked with an error proportional to ``T_s^2 \ddot r``, also when it satisfies both bounds.
The parameters must satisfy ``T_s \ddot x_M < \dot x_M``. Otherwise the factor in the control law that enforces the bound on ``\dot x`` is zero at ``\dot x = 0``, and an output that starts at rest does not move.
With `bounds_as_inputs = true`, the bounds ``\dot x_M`` and ``\ddot x_M`` are the values of the inputs `yd_max_in` and `ydd_max_in` at the current sample, and the parameters `yd_max` and `ydd_max` are not used. The state of the limiter does not depend on the bounds, so a change of the bounds leaves `y` and `yd` continuous, and `ydd` satisfies the bound of the current sample. The inputs must satisfy the same conditions as the parameters at every sample. When ``\dot x_M`` decreases below the current ``|\dot x|``, the control law only prevents a further increase of ``|\dot x|``; ``|\dot x|`` is not reduced to the new bound until the deceleration toward the reference begins.
The outputs `y` and `yd` at sample ``k`` are the state ``x_k, \dot x_k``, which depends only on the reference samples before ``k``, while `ydd` is the value ``a_k`` applied from sample ``k`` to sample ``k+1``, which depends on the current reference sample. The outputs `y` and `yd` therefore have no direct feedthrough from the input, and the three outputs are mutually consistent, which makes them suitable as references and feedforward signals for a tracking controller.
The state of the limiter at the first sample consists of ``x`` and ``\dot x``, which equal the first samples of the outputs `y` and `yd`. The estimate of the reference derivative at the first sample is zero under every `initialization` variant. The scalar variants specify ``x`` only and set ``\dot x = 0``:
- `InitialOutput(y0=...)`: the first sample of `y` equals `y0`.
- `SteadyState`: the first sample of `y` equals the first reference sample, so a constant reference produces no transient.
- `InitialState(x0=...)`: the first sample of `y` equals `x0`.
The array variants specify both ``x`` and ``\dot x``:
- `InitialStateArray(x0=[x, xd])` and `InitialOutputArray(y0=[x, xd])`: the first samples of `y` and `yd` equal `x` and `xd`. The two variants are equivalent, since the outputs `y` and `yd` equal the state.
"""
component TrajectoryLimiter
"Reference"
u = RealInput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 150, "x2": 0, "y2": 250, "rot": 0}
},
"tags": []
}
}
"Limited trajectory"
y = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 150, "x2": 1100, "y2": 250, "rot": 0}
},
"tags": []
}
}
"First time derivative of the limited trajectory [units of u per second]"
yd = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Second time derivative of the limited trajectory [units of u per second squared]"
ydd = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 750, "x2": 1100, "y2": 850, "rot": 0}
},
"tags": []
}
}
"Upper bound on the magnitude of the first time derivative [units of u per second] (only active if `bounds_as_inputs = true`)"
yd_max_in = RealInput@[clk]() if bounds_as_inputs {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Upper bound on the magnitude of the second time derivative [units of u per second squared] (only active if `bounds_as_inputs = true`)"
ydd_max_in = RealInput@[clk]() if bounds_as_inputs {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 750, "x2": 0, "y2": 850, "rot": 0}
},
"tags": []
}
}
"Sample interval [s]"
structural parameter Ts::Real = SampleTime()
"Whether the bounds are given by the inputs `yd_max_in` and `ydd_max_in` instead of the parameters `yd_max` and `ydd_max`"
structural parameter bounds_as_inputs::Boolean = false
"Upper bound on the magnitude of the first time derivative [units of u per second]. Must exceed Ts*ydd_max (only used if `bounds_as_inputs = false`)"
parameter yd_max::Real = 1.0
"Upper bound on the magnitude of the second time derivative [units of u per second squared]. Must be positive and less than yd_max/Ts (only used if `bounds_as_inputs = false`)"
parameter ydd_max::Real = 1.0
"Initial-condition specification"
structural parameter initialization::InitialCondition = DiscreteComponents.InitialCondition.InitialOutput(y0 = 0.0)
"Backward-difference estimate of the time derivative of the reference"
variable r_rate::Real
"Error with respect to the reference"
variable e::Real
"Time derivative of the error"
variable e_rate::Real
"Normalized error variable z"
variable z::Real
"Normalized time derivative of the error"
variable z_rate::Real
"Integer-valued switching index m"
variable m::Real
"Sliding variable"
variable sigma::Real
"Active bound on the magnitude of the first time derivative"
variable ydM::Real
"Active bound on the magnitude of the second time derivative"
variable yddM::Real
relations
if bounds_as_inputs
ydM = yd_max_in
yddM = ydd_max_in
else
ydM = yd_max
yddM = ydd_max
end
r_rate = (u - u@(clk-1)) / Ts
e = y - u
e_rate = yd - r_rate
z = (e / Ts + e_rate / 2) / (Ts * yddM)
z_rate = e_rate / (Ts * yddM)
m = floor((1 + sqrt(1 + 8 * abs(z))) / 2)
sigma = z_rate + z / m + (m - 1) / 2 * sign(z)
ydd = -yddM * clamp(sigma, -1, 1) * (1 + sign(yd * sign(sigma) + ydM - Ts * yddM)) / 2
yd = yd@(clk-1) + Ts * ydd@(clk-1)
y = y@(clk-1) + Ts / 2 * (yd + yd@(clk-1))
initial ydd@(clk-1) = 0
initial u@(clk-1) = u
switch initialization
case InitialOutput
initial yd@(clk-1) = 0
initial y@(clk-1) = initialization.y0
case SteadyState
initial yd@(clk-1) = 0
initial y@(clk-1) = u
case InitialState
initial yd@(clk-1) = 0
initial y@(clk-1) = initialization.x0
case InitialStateArray
initial yd@(clk-1) = initialization.x0[2]
initial y@(clk-1) = initialization.x0[1] - Ts * initialization.x0[2]
case InitialOutputArray
initial yd@(clk-1) = initialization.y0[2]
initial y@(clk-1) = initialization.y0[1] - Ts * initialization.y0[2]
end
metadata {
"Dyad": {"icons": {"default": "dyad://DiscreteComponents/TrajectoryLimiter.svg"}}
}
endTest Cases
No test cases defined.
Related
- Examples
- Experiments
- Analyses