smc_init
Builtin index · Signal processing
smc_init(K, [lambda=], [phi=0.1], [dt=1])
Input: K, lambda, phi, dt · Output: no output
What it is
A first-order sliding-mode controller's initial state. K (number, positive): the reaching-law gain, which also bounds the output (
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
smc_init(K, [lambda=], [phi=0.1], [dt=1]) | K numberK (number, positive): the reaching-law gain, which also bounds the output (.lambda optionalnot documented yetphi optional (default 0.1)not documented yetdt optional (default 1)not documented yet | not documented yet | A first-order sliding-mode controller's initial state. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
dt = 0.01
s = smc_init(2, phi = 0.05, dt = dt)
y = 0
for i = 0 to 1999
s = s.update(1 - y) # setpoint 1
y = y + (s.u - y) * dt
end for
print("y = {y}") # y = 0.97561 (= 40/41)
y = 0.97561
from signal-processing
How it works
A first-order sliding-mode controller (SMC), same immutable state convention as kalman_init/lms_init above: thread the value returned by .update(...) through successive calls, never mutate in place. smc_init(K, lambda=, phi=0.1, dt=1). SLIDING SURFACE — two cases, chosen by whether lambda= is given, because the useful minimal case genuinely differs by plant order and guessing wrong is silent: * no lambda= -> s = e. This is the right minimal case for a FIRST-order plant (one state, tau*y' = K_p*u - y): driving e to zero IS the whole control objective, there is no second state to stabilise, and an e_dot term would only add derivative noise for nothing. * lambda= given (must be > 0) -> s = e_dot + lambda*e, the textbook Slotine surface for a SECOND-order plant. Once s = 0 is reached, e decays as exp(-lambda*t), so lambda sets the sliding-phase time constant 1/lambda. The choice is recorded in the state's surface field ("e" or "e_dot+lambda*e") so it is visible on inspection rather than inferred from whether lambda happens to be 0. CONTROL LAW — u = u_eq + K * sat(s/phi), with u_eq = 0 here. u_eq (the "equivalent control") is by definition the input that holds s_dot = 0 given a PLANT MODEL; this controller is deliberately model-free, so there is no model to compute it from and the honest value is 0. That leaves the reaching law u = K*sat(s/phi), which is the standard model-free SMC and is what makes K the gain that must dominate the unmodelled dynamics. BOUNDARY LAYER — textbook SMC uses sign(s), which switches at infinite frequency the instant s crosses zero. On real hardware that is "chattering": it excites unmodelled high-frequency modes and destroys actuators. The standard fix, and the reason phi exists, is to replace sign(s) with sat(s/phi) — linear inside a boundary layer of width phi around the surface, saturating to +/-1 outside. That trades the ideal-sliding guarantee for convergence to a |s| <= phi neighbourhood instead of exactly s = 0, and in exchange u becomes CONTINUOUS in s and bounded by |u| <= K. phi = 0 is still accepted and gives literal sign(s) (with sign(0) = 0), for callers who want to see the chattering the boundary layer removes.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.