Reference Generators
Reference generators produce a reference signal \(r_k\) that encodes the desired system behaviour.
h always returns \(r_k\) so the output can be fed directly into a controller block.
Stateless
Constant
Generates a constant reference signal. \(r_k = r\)
import numpy as np
import matplotlib.pyplot as plt
from dynamicalnodes import DynamicalSystem
def constant_h(r: float) -> float:
return r
Sinusoid
Generates a sinusoidal reference signal with amplitude \(A\) and angular frequency \(\omega\) (rad/s). \(r_k = A \sin(\omega\, t_k)\), where \(t_k\) is elapsed time in seconds.
def sin_wave_h(tk: float, A: float, omega: float) -> float:
return A * np.sin(omega * tk)
Square Wave
Generates a square wave reference signal with amplitude \(A\) and period \(T\) (seconds). \(r_k = A \operatorname{sgn}\!\left(\sin\!\left(\tfrac{2\pi}{T} t_k\right)\right)\)
def square_wave_h(tk: float, A: float, T: float) -> float:
return A * np.sign(np.sin(2 * np.pi / T * tk))
Ramp
Generates a linearly increasing reference signal with slope \(m\) (units/s). \(r_k = m\, t_k\)
def ramp_h(tk: float, m: float) -> float:
return m * tk
Step
Generates a step reference signal that jumps from \(0\) to \(A\) at \(t = t_{\text{step}}\). \(r_k = \begin{cases} A & t_k \ge t_{\text{step}} \\ 0 & \text{otherwise} \end{cases}\)
def step_h(tk: float, A: float, t_step: float) -> float:
return A if tk >= t_step else 0.0
Stateful
Latch
Holds the last captured value until a boolean trigger goes high, at which point it latches the new input u.
$\(x_{k+1} = \begin{cases} u_k & \text{trigger}_k \\ x_k & \text{otherwise} \end{cases}, \qquad r_k = x_k\)$
def latch_f(x_k: float, u: float, trigger: bool) -> float:
return u if trigger else x_k
def latch_h(x_k: float) -> float:
return x_k
Setpoint
Holds a setpoint value and updates it whenever a new one is provided.
Pass setpoint=value to update; omit it to hold the current value.
$\(x_{k+1} = \begin{cases} \text{setpoint}_k & \text{if provided} \\ x_k & \text{otherwise} \end{cases}, \qquad r_k = x_k\)$
def setpoint_f(x_k: float, setpoint: float = None) -> float:
return setpoint if setpoint is not None else x_k
def setpoint_h(x_k: float) -> float:
return x_k