Skip to main content

flight_solver/cls/
types.rs

1//! Types for the constrained least-squares solver.
2
3use nalgebra::{Const, OMatrix, OVector};
4
5/// Constraint feasibility tolerance for f32 (matches C `AS_CONSTR_TOL` with `AS_SINGLE_FLOAT`).
6pub const CONSTR_TOL: f32 = 1e-4;
7
8/// Solver exit status.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[repr(u8)]
11pub enum ExitCode {
12    /// Optimal feasible solution found.
13    Success = 0,
14    /// Maximum iteration count reached without convergence.
15    IterLimit = 1,
16    // CostBelowTol (2) and CostPlateau (3) are not implemented — they only
17    // applied to the Cholesky solver's optional cost-truncation mode, which
18    // this crate does not port.
19    /// NaN detected in QR solve (indicates singular or near-singular subproblem).
20    NanFoundQ = 4,
21    /// NaN detected in solution update.
22    NanFoundUs = 5,
23}
24
25/// Statistics returned by the solver alongside the solution.
26#[derive(Debug, Clone, Copy)]
27pub struct SolverStats {
28    /// How the solver terminated.
29    pub exit_code: ExitCode,
30    /// Number of active-set iterations performed.
31    pub iterations: usize,
32    /// Number of free (unconstrained) actuators at the solution.
33    pub n_free: usize,
34}
35
36/// Convenience alias for an `NC × NU` coefficient matrix (column-major, f32).
37pub type Mat<const NC: usize, const NU: usize> = OMatrix<f32, Const<NC>, Const<NU>>;
38
39/// Convenience alias for an `N`-element column vector (f32).
40pub type VecN<const N: usize> = OVector<f32, Const<N>>;