wls_alloc/lib.rs
1//! Weighted least-squares (WLS) constrained control allocator.
2//!
3//! Solves `min ‖Au − b‖²` subject to `umin ≤ u ≤ umax` using an active-set
4//! method with incremental QR updates. Designed for real-time motor mixing on
5//! flight controllers: `no_std`, fully stack-allocated, const-generic over
6//! problem dimensions.
7//!
8//! # Quick start
9//!
10//! ```no_run
11//! use wls_alloc::{setup_a, setup_b, solve, ExitCode, VecN, MatA};
12//!
13//! // Effectiveness matrix G (6 pseudo-controls × 4 motors)
14//! let g: MatA<6, 4> = MatA::zeros(); // replace with real data
15//! let wv: VecN<6> = VecN::from_column_slice(&[10.0, 10.0, 10.0, 1.0, 0.5, 0.5]);
16//! let mut wu: VecN<4> = VecN::from_column_slice(&[1.0; 4]);
17//!
18//! // Build LS problem
19//! let (a, gamma) = setup_a::<4, 6, 10>(&g, &wv, &mut wu, 2e-9, 4e5);
20//! let v: VecN<6> = VecN::zeros();
21//! let ud: VecN<4> = VecN::from_column_slice(&[0.5; 4]);
22//! let b = setup_b::<4, 6, 10>(&v, &ud, &wv, &wu, gamma);
23//!
24//! // Solve
25//! let umin: VecN<4> = VecN::from_column_slice(&[0.0; 4]);
26//! let umax: VecN<4> = VecN::from_column_slice(&[1.0; 4]);
27//! let mut us: VecN<4> = VecN::from_column_slice(&[0.5; 4]);
28//! let mut ws = [0i8; 4];
29//! let stats = solve::<4, 6, 10>(&a, &b, &umin, &umax, &mut us, &mut ws, 100);
30//! assert_eq!(stats.exit_code, ExitCode::Success);
31//! ```
32
33#![no_std]
34#![warn(missing_docs)]
35
36/// Low-level linear algebra: Householder QR, back-substitution, constraint checking.
37pub mod linalg;
38/// Problem setup: convert WLS control-allocation parameters into LS form.
39pub mod setup;
40/// Active-set constrained least-squares solver.
41pub mod solver;
42/// Core types, constants, and nalgebra type aliases.
43pub mod types;
44
45pub use setup::{setup_a, setup_b};
46pub use solver::solve;
47pub use types::{ExitCode, MatA, SolverStats, VecN};