Transforms — Sim, EKF, UKF, INS, 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 scheduled simulation-truth Module.
Measurements with the same declared positive rate are emitted as one
sample_group_* entry and omitted from the plant step outputs.
Backends can therefore schedule the kernel without evaluating its
symbolic dependencies on every physics tick. Measurements with no
rate remain inline and are evaluated every tick.
Source code in manta/sim.py
inline_module ¶
The all-inline simulation oracle for smooth/batched callers.
Every measurement is returned by step regardless of declared
rate. Rate metadata remains present, but this artifact deliberately
performs no acquisition scheduling.
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 ¶
Bases: _FilterBase
Error-state EKF over a World — symbolic recursion + typed Module.
The analysis surface (module, n_blocks, observability,
sigma_horizon) is the shared _FilterBase tail.
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.
gates: optional normalized-innovation-squared threshold: one
positive scalar for every sensor, or a mapping from
sensor name/suffix to threshold. Rejected updates leave
both state and covariance unchanged while still
returning their innovation diagnostics.
Source code in manta/estimation/ekf.py
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 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 | |
UKF¶
manta.UKF ¶
UKF(world, *, track=None, sensors=None, inputs=None, alpha=None, beta=2.0, kappa=0.0, mean_iters=1, jitter=1e-12, gates=None)
Bases: _FilterBase
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. The analysis surface
(module, n_blocks, observability, sigma_horizon) is the shared
_FilterBase tail.
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). None (default)
resolves to min(1, √(3/n)) for tangent dim n, which
pins the spread at γ = √(n+λ) = √3 — i.e. sigma
points at ~1.7σ — independent of state size. The two
failure modes this dodges are both real: α=1 spreads
points at √n·σ, which at robotics-sized n wraps
rotation offsets past π and corrupts the re-summarized
covariance; the textbook "small α" (1e-3) drives the
central covariance weight to ≈ −n/α² (−10⁶ at n=13,
the classic indefinite-P failure) while shrinking the
spread until the transform is a noisy finite
difference of the EKF.
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 suffices for the default spread; raise it for a
wide spread on a strongly-curved manifold).
jitter: variance floor (added as jitter·I, and as a pivot
floor) when factoring P into sigma points. P is an
iterated covariance, so roundoff can leave it
marginally indefinite; the jitter turns the NaN cliff
into a regularized factor. 0 disables.
gates: optional normalized-innovation-squared threshold: one
positive scalar for every sensor, or a mapping from
sensor name/suffix to threshold. Rejection preserves
the prior state and covariance.
An explicit tuning that produces a negative central covariance
weight (w_c[0] < 0) is accepted but warns: the covariance sums
lose their PSD guarantee and rely on the jitter backstop. The auto
default produces a mildly negative w_c[0] once the tangent
dimension exceeds n ≈ 11 (w_c[0] = 3−n)/3 + 3 − 3/n; the price
of the bounded √3·σ spread), which the sigma-point Joseph update
form and the jitter absorb. Either way the dependency is explicit:
a negative w_c[0] REQUIRES jitter > 0 (construction refuses
jitter=0 in that regime) and the resolved weights are published
as UKF.sigma_weights and in the Module metadata under
"unscented" so the tuning the artifact was built with is
inspectable.
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
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 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 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
INS¶
manta.INS ¶
INS(world, *, imu, track=None, sensors=None, inputs=None, discretization='exact', gates=None, propagation='raw', navigation_frame=None, covariance='linearized', expand=False)
Bases: _FilterBase
Error-state strapdown inertial navigation transform.
Args mirror EKF where their meanings agree. imu identifies the
physical IMU whose accelerometer and gyro become required prediction
inputs in u. Its own outputs are removed from the ordinary update set.
A selected, colocated ModelForce.specific_force is automatically
sourced from that IMU's accelerometer by analysis tools. Such a part
must carry accepted fit evidence (ModelForce(evidence=...)):
construction refuses one without evidence, or whose evidence failed
its acceptance criteria, naming what is missing.
propagation="raw" consumes one accelerometer/gyro pair per predict.
propagation="preintegrated" consumes packets emitted by
:class:~manta.estimation.imu_preintegrator.IMUPreintegrator; the
high-rate recurrence and the lower-rate INS can both be lowered to
generated C/C++.
navigation_frame supplies fixed planet-attached Cartesian kinematics.
The caller resolves its anchor and rotation vector; the IMU remains
inertial. Its gravity convention is explicit. See
docs/explanation/earth-relative-ins.md for equations, packet schema,
and qualification scope. covariance="geometric" uses analytic prediction
and bias-mean transport in a gravity/Earth-referenced finite error chart.
covariance="nonlinear" instead uses augmented sigma-point prediction in
that chart. Both map physical priors and apply the coupled covariance reset.
The default "linearized" retains the existing covariance recursion.
expand=True expands the hot filter kernels to scalar expressions before
lowering; this preserves equations but changes code size and evaluation cost.
Initialization quadrature is kept separate. Unsupported scalar operations
fail explicitly. See docs/explanation/nonlinear-ins-covariance.md.
Source code in manta/estimation/ins.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 | |
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
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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
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.