tpt-control

Rust

Pure-Rust, AI-native control systems library — state-space modeling, classical/optimal control, state estimation, and MPC, with zero C/C++ FFI and zero external solver dependencies. MIT OR Apache-2.0.

0 stars0 forks0 watchersApache License 2.0

Languages

Rust96.6%HTML2.0%Python0.8%Just0.6%
README

tpt-control

A pure-Rust, AI-native control systems theory library. State-space modeling, classical control, optimal control, state estimation, and model predictive control — with zero C/C++ FFI and zero external solver dependencies.

Part of the TPT Solutions tpt-* ecosystem. Dual-licensed MIT / Apache-2.0.

Why

Every numerical algorithm in this workspace is implemented from scratch: LU, Cholesky, QR, real Schur (Francis double-shift QR), Padé scaling-and- squaring matrix exponential, Bartels–Stewart Lyapunov, structured-doubling DARE, Newton–Kleinman CARE, an active-set QP solver for MPC, and KF/EKF/UKF. No LAPACK, no OSQP, no Apache-2.0-only crates (enforced by cargo-deny).

Design principles (see spec.txt):

  • Dimensional safety — Mat<T, R, C> carries matrix shapes in const generics, so multiplying a 3×1 state by a 2×2 gain is a compile error.
  • no_std + alloc core — tpt-ctrl-core builds for thumbv6m-none-eabi.
  • Mathematically rigorous — property-based tests (proptest) for control invariants, Kani bounded model checking for panic-freedom in solver loops, Lyapunov contracts as checked numerical code.
  • AI-native — cost functions and state transitions expose finite-difference Jacobian/gradient hooks (tpt_ctrl_core::fd) for gradient-based policy optimization.

Layout

CrateContents
tpt-ctrl-coreStateSpace<N, M, P>, dimensioned matrices, LU/Cholesky/QR/Schur/expm, Lyapunov, exact ZOH + Tustin, RK4
tpt-ctrl-classictransfer functions, PID (anti-windup), lead/lag/notch, Bode/Nyquist, gain & phase margins
tpt-ctrl-optimalCARE/DARE from scratch, LQR/DLQR, Kalman gain, LQG/dLQG
tpt-ctrl-estimationdiscrete KF (Joseph form), EKF (user Jacobians), UKF
tpt-ctrl-mpchorizon condensing, active-set QP, constrained MPC, explicit-MPC tables
tpt-ctrl-verifyproptest strategies, Lyapunov contract checks, Kani harnesses
tpt-controlumbrella crate (feature-gated re-exports)
tpt-control-clitpt command: design and certify a gain from a TOML plant
tpt-control-wasmWebAssembly bindings and browser playground (playground/)
bindings/pythonPython package tpt_control (PyO3; see docs/MATLAB.md too)

Quick start

use tpt_control::prelude::*;

let a = DMat::from_rows(&[&[0.0, 1.0], &[0.0, 0.0]]);
let b = DMat::from_rows(&[&[0.0], &[1.0]]);
let sol = tpt_control::optimal::lqr(&a, &b, &DMat::identity(2), &DMat::from_rows(&[&[1.0]]))
    .unwrap();
// sol.k = [1, sqrt(3)] for Q = I, R = 1 — the classic textbook result.

Run the worked examples:

cargo run -p tpt-ctrl-optimal --example inverted_pendulum
cargo run -p tpt-ctrl-estimation --example kf_sensor_fusion
cargo run -p tpt-ctrl-mpc --example constrained_mpc

Development

just ci      # fmt + build + test + clippy + deny + doc
just no-std  # build the core for thumbv6m-none-eabi
just kani    # bounded model checking (Linux only)

Toolchain pinned in rust-toolchain.toml. Benchmarks (criterion) cover the solver hot paths: cargo bench -p tpt-ctrl-core -p tpt-ctrl-optimal -p tpt-ctrl-mpc.

Status

Phases 0–4 of todo.md are implemented; Phase 5 (release chores) is in progress. The publish target (crates.io vs internal path dependencies) is a pending decision — see todo.md.