Skip to main content

kinavis_kernel/
lib.rs

1//! Value types of the KINAVIS crates.
2//!
3//! The kernel holds what has exactly one correct implementation: units, angles,
4//! positions, time, the error type. Anything with a choice of method (sailing,
5//! interpolation, fix) lives in `kinavis`; every satellite crate (parsers,
6//! magnetic model, INS) depends on the kernel alone. This is the workspace
7//! dependency rule: adapters change without touching the core.
8//!
9//! Most users should depend on `kinavis`, which re-exports these modules.
10//! Depend on `kinavis-kernel` directly for an adapter that must not pull in the
11//! algorithms.
12//!
13//! # Type guarantees
14//!
15//! Angles carry their reference frame: [`CompassCourse`], [`MagneticCourse`],
16//! [`TrueCourse`], [`GyroCourse`], [`Variation`], [`Deviation`],
17//! [`RelativeBearing`]. Passing a magnetic course where a true one is expected
18//! does not compile. [`Distance`] and [`Speed`] are types, so knots cannot be
19//! passed as m/s.
20//!
21//! Each type enforces its range: a [`Direction`] is always finite and in `[0°,
22//! 360°)`, a [`Latitude`] in `[-90°, 90°]`. Existence implies validity, so
23//! corrections built on them return values, not `Result`. Invalid input is
24//! rejected at construction with a [`KernelError`]; nothing panics on caller
25//! data.
26//!
27//! # Modules
28//!
29//! - [`angle`] — frame-tagged angles.
30//! - [`units`] — angles, distances, speeds, rate of turn.
31//! - [`position`] — latitude, longitude, notation.
32//! - [`error`] — the error type and validation helpers.
33//! - [`time`] — instants with the time scale in the type, calendar, leap-second
34//!   port.
35//! - [`observation`] — a value with its time and quality; age is computed.
36//! - [`geodesy`] — ellipsoids, heights with datum, ECEF, chart datums and their
37//!   transformation to WGS 84.
38//! - [`local`] — NED and other local frames; vectors typed by frame and unit; a
39//!   frame anchored at a point.
40//! - [`gnss`] — a satellite fix, independent of the sentence format.
41//! - [`state`] — navigation state aggregate behind invariants, projected to the
42//!   read model.
43//! - [`estimation`] — estimator ports: process model and observation.
44//! - [`environment`] — environment ports (magnetic field, current, wind, tide,
45//!   leeway, deviation) and the sample they return.
46//! - [`snapshot`] — read model: position, motion, uncertainty and age, for
47//!   displays and alarms.
48//! - [`event`] — events returned as values in a fixed-capacity list, never via
49//!   callbacks.
50//! - [`matrix`] — small dense matrices with checked access and Cholesky
51//!   factorisation.
52//! - [`math`] — floating-point primitives routed to `std` or `libm`. Every
53//!   transcendental call in the crate family goes through here, for
54//!   reproducibility across targets.
55//! - [`inline`] — fixed-capacity storage; no allocator required.
56//!
57//! # Feature flags
58//!
59//! - `std` *(default)* — standard library floating-point maths.
60//! - `libm` — for `no_std` targets: `--no-default-features --features libm`.
61//! - `serde` — serialisation of the value types; deserialisation applies the
62//!   same validation as construction.
63//! - `alloc` — unused here; lets dependent crates name one flag for the whole
64//!   family.
65//!
66//! No dependencies in the default configuration.
67//!
68//! # Hidden items
69//!
70//! Some public items are `#[doc(hidden)]`: constructors that accept a raw value
71//! unchecked (`from_degrees_unchecked`, `from_knots_unchecked`,
72//! `from_degrees_wrapped`, `relabel`) and accessors exposing internal
73//! representation (`NavigationState` vector, covariance and `from_parts`, the
74//! state dimension, Jacobian entries). The algorithm crates need them — a
75//! solver wrapping an already-bounded angle should not pay for a check, an
76//! estimator must see the covariance — and Rust has no visibility between
77//! crates other than `pub`. They form an internal contract of the crate family:
78//! not covered by the stability guarantee, may change in a minor release, and
79//! marked as such in their docs. Use them only from crates released together
80//! with the kernel.
81
82#![cfg_attr(not(feature = "std"), no_std)]
83
84// The crate does not allocate; test modules use `format!`, hence `test`. The
85// bare-metal CI build enables neither.
86#[cfg(any(feature = "alloc", test))]
87extern crate alloc;
88
89pub mod angle;
90pub mod environment;
91pub mod error;
92pub mod estimation;
93pub mod event;
94pub mod geodesy;
95pub mod gnss;
96pub mod inline;
97pub mod local;
98pub mod math;
99pub mod matrix;
100pub mod observation;
101mod parse;
102pub mod position;
103pub mod snapshot;
104pub mod state;
105pub mod time;
106pub mod units;
107
108pub use angle::{
109    wrap180, wrap360, CardinalPoint, Compass, CompassBearing, CompassCourse, Deviation, Direction,
110    Frame, Gyro, GyroBearing, GyroCourse, Magnetic, MagneticBearing, MagneticCourse,
111    RelativeBearing, Side, True, TrueBearing, TrueCourse, Variation, MAX_DEVIATION_DEG,
112    MAX_VARIATION_DEG,
113};
114pub use environment::{
115    CompassModel, Current, CurrentModel, EnvironmentSample, LeewayModel, MagneticField,
116    MagneticModel, TideModel, VesselMotion, Wind, WindModel, MAX_FIELD_NANOTESLA,
117};
118pub use error::{Excerpt, KernelError, Result, EXCERPT_BYTES};
119pub use estimation::{
120    GatingPolicy, JacobianRow, Observation, ObservationJacobian, ObservationNoise,
121    ObservationVector, ProcessModel, ProcessNoise, StateJacobian, MAX_OBSERVATION_DIM,
122};
123pub use event::{
124    Event, EventList, NavigationEvent, NavigationIntegrity, PositionSource, RejectionReason,
125    SensorHealth, SensorId, TargetId, MAX_EVENTS, SENSOR_NAME_BYTES,
126};
127pub use geodesy::{Datum, EcefPoint, Ellipsoid, GeodeticPoint, Height, Helmert, VerticalDatum};
128pub use gnss::{Dop, FixType, GnssFix, GnssFixBuilder, GnssQuality};
129pub use inline::InlineStr;
130pub use local::{Body, Enu, LocalFrame, Ned, Vector3, VectorFrame, VectorUnit};
131pub use observation::{ObservationStatus, Observed, Quality};
132pub use position::{EastWest, GeocentricUnit, Latitude, Longitude, NorthSouth, Position};
133pub use snapshot::{ErrorEllipse, GroundTrack, NavigationSnapshot};
134pub use state::{NavigationState, StateComponent, StatePriors};
135pub use time::{Civil, Gps, Instant, LeapSeconds, Tai, TimeScale, Utc};
136pub use units::{Angle, Distance, RateOfTurn, Speed};