Transforms — Sim, EKF, UKF, LQR¶
The compile-time siblings. Each takes a World, writes its math
symbolically over the shared linearized system, and emits a typed
Module. Lower one with a target to get a callable runtime.
Sim¶
manta.Sim ¶
Forward-dynamics transform: model validation + the linearized tick, emitting oracle/deploy Modules.
Source code in manta/sim.py
module ¶
The oracle Module (simulation truth): one step entry —
the full forward tick, one live noise draw → state + readings.
Source code in manta/sim.py
deploy_module ¶
The deploy Module (runs on a robot against real sensors): noiseless forward map + per-sensor measurement models + Jacobians.
Source code in manta/sim.py
EKF¶
manta.EKF ¶
Error-state EKF over a World — symbolic recursion + typed Module.
Args:
track: {craft_name: SlotSet} lower bound of what to estimate
(closed under the dynamics; the rest freezes). None
keeps the full state.
sensors: measurement full-names (or unambiguous suffixes).
None keeps every output (of tracked crafts).
inputs: known control inputs; None keeps all, excluded ones
freeze at their default.
discretization: how F discretizes the dynamics — "exact"
(default; jacobian of the full discrete tick) or
"euler" (F = I + dt·∂ẋ/∂δ; O(dt²) from exact, much
smaller generated deploy code). See LinearizedSystem.
Source code in manta/estimation/ekf.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
module ¶
observability ¶
Local observability of the chosen sensor set at an operating
point (see manta.estimation.observability).
sigma_horizon ¶
Per-slot σ attainable after a horizon — the covariance
recursion run open-loop, resolving the weak/slow observability the
rank test can't (see manta.estimation.observability).
Source code in manta/estimation/ekf.py
UKF¶
manta.UKF ¶
UKF(world, *, track=None, sensors=None, inputs=None, alpha=0.001, beta=2.0, kappa=0.0, mean_iters=1)
Error-state UKF over a World — symbolic sigma-point recursion +
typed Module. Drop-in alternative to EKF with the same constructor,
runtime surface, and emitted Module shape.
Args:
track: {craft_name: SlotSet} lower bound of what to estimate
(closed under the dynamics; the rest freezes). None
keeps the full state.
sensors: measurement full-names (or unambiguous suffixes).
None keeps every output (of tracked crafts).
inputs: known control inputs; None keeps all, excluded ones
freeze at their default.
alpha: sigma-point spread (0 < α ≤ 1). Small (default 1e-3)
keeps the points near the mean — the canonical scaled
UT, which matches the EKF in the linear limit.
beta: prior-knowledge term (2.0 is optimal for a Gaussian).
kappa: secondary scaling (0.0 by default).
mean_iters: retraction steps for the predict's manifold mean
(1 is plenty for the default spread; raise it for a
wide spread on a strongly-curved manifold).
Unlike the EKF there is no discretization knob: the UKF pushes
sigma points through the exact nonlinear discrete tick f, so the
Euler/exact distinction (which only shapes the EKF's linearized F)
does not arise.
Source code in manta/estimation/ukf.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
module ¶
observability ¶
Local observability of the chosen sensor set at an operating
point (the linearized analysis shared with the EKF — see
manta.estimation.observability).
Source code in manta/estimation/ukf.py
sigma_horizon ¶
Per-slot σ attainable after a horizon — the linearized covariance
recursion run open-loop (see manta.estimation.observability).
Source code in manta/estimation/ukf.py
LQR¶
manta.LQR ¶
Infinite-horizon discrete LQR about an operating point.
Args:
world — the model.
x_ref — target state (nested {owner: {slot: value}} or flat
{"owner.slot": value}), merged over the world's
initial state for any unspecified slot.
u_ref — trim inputs ({input_name: value}), merged over each
Part Input's default. The equilibrium command.
Q, R — LQR cost weights (regulated-tangent², n_inputs²). Default
to identity. R must be positive-definite.
dt — the discrete step the controller will run at.
regulate — slot full-names to regulate, taken verbatim (e.g.
["c.position", "c.velocity"]); the rest are frozen at
x_ref. None regulates the full state (fully-actuated
systems only).
tol, max_iter — Riccati-iteration convergence: relative fixpoint
tolerance (‖ΔP‖ ≤ tol·max(1, ‖P‖)) and iteration cap.
Attributes:
spec (full), regulated (regulated slot names), input_names,
K (n_u × tracked_tangent), A, B, P, Q, R, dt,
x_ref/u_ref (vectors), solution (the built solve as data),
control_fn (u(x_full, x_ref_full, K, u_ff) ca.Function;
runtimes default every argument but the live state to the built
operating point — see NumpyRegulator.retarget / reprogram).
Source code in manta/control/lqr.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
solution
property
¶
The built solve as data — what every Port defaults to, and the
identity element for reprogram().
closed_loop_eigs
property
¶
Eigenvalues of the closed-loop tangent map A − B·K (over the
tracked subspace). All inside the unit circle ⇒ stable.
module ¶
resolve_at ¶
Re-solve the gain about a NEW operating point.
Evaluates A, B at the moved reference and re-runs the Riccati
iteration — the symbolic linearization is already compiled, so
this is a matrix evaluation plus a small dense DARE (µs + ms on a
~12-dim tangent), not a rebuild. Returns an LQRSolution;
install it on a live regulator with reprogram(), or ship it as
data. self is untouched.
This is the correct way to move a setpoint whenever the dynamics
are not invariant along the move — most importantly a heading
change, where retarget() alone leaves the world-frame position
feedback rotated with the reference (⊥ at 90°, positive feedback
at 180°).
Args:
x_ref — reference overrides (nested or flat), merged over the
built reference. Every named slot must be one this
LQR regulates: the complement is frozen at the
built point and baked into A/B as a constant, so
no re-evaluation can honour a move there.
u_ref — trim overrides, merged over the built trim. The
equilibrium command at the new point (attitude-
dependent in general — solving for it is a root-solve
and stays yours).
Q, R — cost overrides; default to the built weights.
Raises: ValueError — a named slot is unregulated (frozen) or unknown, or the moved point is not stabilizable.
Source code in manta/control/lqr.py
LQRSolution¶
One Riccati solve as plain data — what LQR.resolve_at returns and a
regulator's reprogram() installs. See
moving the operating point.
manta.LQRSolution
dataclass
¶
One Riccati solve at one operating point, as plain data.
The affine control law is u = u_ff − K·(x ⊟ x_ref); these three
fields are the whole of it. LQR.resolve_at returns one and a
runtime regulator's reprogram() installs it — all three together,
because a gain is only valid about the point it was solved at.
Everything here is a plain array, so a retarget service can hand a compiled regulator (numpy, wasm, C++) a new setpoint over JSON with no CasADi on the other side.
Attrs: K — n_u × regulated-tangent feedback gain. u_ff — n_u feed-forward: the trim command at this point. x_ref — full ambient reference the law regulates to. A, B — the tangent linearization it was solved from. P — the Riccati fixpoint.
closed_loop_eigs
property
¶
Eigenvalues of A − B·K. All inside the unit circle ⇒ stable.
PID¶
manta.PID ¶
Bases: RecurrenceBlock
Scalar PID controller as a recurrence block.
Args:
kp, ki, kd — proportional / integral / derivative gains.
integral_limit — symmetric clamp on the integral accumulator
(anti-windup). None disables it.
output_limit — symmetric clamp on the command. None disables.
name — codegen basename / default C++ class stem.
Ports: inputs setpoint + measurement (scalars); output
command. State: integral, prev_measurement, primed.