S0 — Sensor & Calibration Models
The mathematical foundation upon which the entire pipeline is built. S0 is not an algorithmic step — it is the collection of physical and geometric measurement functions that map the 3D continuous world into the discrete pixels and inertial samples the filter consumes. Every residual, state propagation step, and EKF update Jacobian in the system is built on top of S0.
A bug in S0 (such as a coordinate system flip or a sign error in the Jacobian) does not fail loudly with an exception. Instead, it quietly poisons every downstream stage, manifesting as mysterious, untraceable quadratic drift or immediate filter divergence.
1. Camera Projection Models
Section titled “1. Camera Projection Models”A camera model defines the mapping:
where is a 3D point in the camera-frame coordinate system. Cortex supports both the standard Pinhole-RadTan model (for rectilinear lenses) and the Kannala-Brandt model (for wide-angle fisheye lenses).
A. Pinhole Projection (The Core Perspective)
Section titled “A. Pinhole Projection (The Core Perspective)”The ideal pinhole camera projects the 3D camera-frame coordinate to the normalized image plane coordinates :
These are then mapped to pixel coordinates via focal lengths () and principal points ():
Understanding the Model Parameters:
Section titled “Understanding the Model Parameters:”- Focal Lengths (): Represent the distance between the lens optical center and the image sensor plane, expressed in pixel units. These scale the normalized coordinates to match the physical pixel spacing on the silicon wafer.
- Principal Points (): Represent the exact pixel coordinate where the camera’s optical axis physically pierces the image sensor. Because the lens assembly is never perfectly centered on the silicon during manufacturing, the principal point is almost never exactly at the geometric center of the pixel grid.
B. Distortion Models (Modeling Lens Curvature)
Section titled “B. Distortion Models (Modeling Lens Curvature)”Real lenses bend light, introducing distortion. Before mapping to pixels, the normalized coordinates are warped to distorted coordinates .
1. Radial-Tangential (RadTan) Distortion (5-Lens / 4-Intrinsic Parameters)
Section titled “1. Radial-Tangential (RadTan) Distortion (5-Lens / 4-Intrinsic Parameters)”The complete camera projection model combines 5 lens distortion parameters () and 4 intrinsic calibration parameters ():
- Radial Distortion (): Models barrel/pincushion lens symmetry. Glass lenses curve more aggressively near their outer borders. This pulls or pushes pixels along radial lines emerging from the optical center:
- Tangential Distortion (): Models “decentering” or “thin prism” distortion. This is caused by individual lens elements being slightly tilted relative to each other or misaligned relative to the image sensor plane during assembly, creating a slight physical warp:
2. Kannala-Brandt (KB) Fisheye Distortion (4-Parameters)
Section titled “2. Kannala-Brandt (KB) Fisheye Distortion (4-Parameters)”Wide-angle fisheye lenses cannot be modeled by simple rectilinear perspective because their field of view often exceeds (light rays can literally bend around behind the camera origin).
Instead of assuming light travels in straight lines to a flat plane, the Kannala-Brandt model maps the angular direction of the incoming light ray () relative to the optical axis using an odd-power polynomial series:
The distorted coordinates are then mapped:
- Optical Center Limit (r = 0): When (the principal ray), the angle , and the ratio is mathematically defined as its limit: . Thus, at the principal point, and with zero distortion, preventing any division-by-zero NaN values.
C. The Analytical Projection Jacobian
Section titled “C. The Analytical Projection Jacobian”To perform the EKF Measurement Update (where we update our state estimate using the visual tracking error), we need to write the derivative of pixel coordinates w.r.t the 3D camera-frame point . This Jacobian, , is computed via the chain rule:
- Pinhole Quotient Rule: The normalized image coordinate is a quotient of coordinates: . Under the standard quotient rule, its derivatives w.r.t the 3D coordinate vector are given by:
- $\partial x_n/\partial x = 1/z
- $\partial x_n/\partial y = 0
- $\partial x_n/\partial z = -x / z^2 This forms the linear perspective term:
Cortex checks the rank of (which must be strictly 2) and validates its analytic derivatives against numerical finite differences during unit testing down to machine precision ().
2. Inertial Sensor (IMU) Physics
Section titled “2. Inertial Sensor (IMU) Physics”An Inertial Measurement Unit (IMU) consists of a 3-axis gyroscope and a 3-axis accelerometer. The continuous-time physical models are:
Where:
- : The raw gyro and accelerometer measurements.
- : The true angular velocity and true world-frame acceleration of the IMU.
- : The slow-varying sensor biases (modeled as random walks).
- : White Gaussian measurement noise.
- : The global gravity vector.
Why an IMU Resting on a Table Reads
Section titled “Why an IMU Resting on a Table Reads +9.81 m/s2+9.81\text{ m/s}^2+9.81 m/s2”This is a common point of confusion for beginners. Accelerometers measure specific force (the reaction force relative to free-fall), not true acceleration. When an IMU is stationary on a flat table:
- Its true world acceleration is .
- The world gravity is .
- Thus, the accelerometer reads:
- This registers as a upward acceleration. A VIO pipeline must subtract gravity during propagation to prevent the drone from quadratically shooting off into the sky in its state estimate.
3. Space-Time Calibration
Section titled “3. Space-Time Calibration”Sensors do not live at the same physical point, nor do they capture data at the exact same instant. We must calibrate both spatial and temporal offsets.
A. Spatial Extrinsics (6-DoF Calibration)
Section titled “A. Spatial Extrinsics (6-DoF Calibration)”The camera is offset from the IMU center by a translation and a rotation (or ). A point in the world frame is mapped to the camera frame via the intermediate IMU frame :
Under dynamic motion, omitting even a offset introduces massive unmodeled centripetal and Euler accelerations into the camera’s visual track:
B. Temporal Extrinsics (Time-Offset Calibration)
Section titled “B. Temporal Extrinsics (Time-Offset Calibration)”Due to transmission latency, clock drift, or rolling shutters, there is a time delay between the camera clock and the IMU clock:
If the drone is rotating at a moderate angular velocity of (common in maneuvers), a tiny unmodeled time offset () introduces a alignment error. This is equivalent to several pixels of visual tracking error, causing the EKF update to inject false corrections.
The S0 Contract
Section titled “The S0 Contract”The contract defines the required behavior of the sensor and calibration mathematical block:
| Element | Contract Specification |
|---|---|
| Signature | |
| Pre-conditions | Focal lengths ; distortion parameters are within stable convergence bounds; gravity vector orientation is frame-consistent. |
| Post-conditions & Invariants | 1. Round-Trip consistency: down to machine precision for all depth . 2. Jacobian rank: Projection Jacobian is strictly rank-2 and matches numerical finite-differences. 3. Cheirality: Points behind the lens () are rejected, never projected. 4. Inertial Identity: A zero-noise, gravity-compensated stationary IMU integrates to exactly zero velocity and zero translation over time. |
Real-Data Validation via s0_inspect
Section titled “Real-Data Validation via s0_inspect”Cortex provides a generalized static release tool, s0_inspect, which can be invoked directly on actual EuRoC sensor streams to verify physical calibration.
# Execute the real-data sensor inspector on EuRoC V1_01_easys0_inspect --dataset /path/to/V1_01_easy/mav0 --out build/s0 --frame 0This generates two critical diagnostic overlays:
A. Camera Model Overlay (distortion.svg)
Section titled “A. Camera Model Overlay (distortion.svg)”Superimposes an ideal, distortion-free rectilinear grid (grey) against the actual lens-warped grid (green) calculated from the distortion coefficients. It draws lens displacement vectors and verifies the round-trip projection error across every node of the grid. This allows you to visually inspect and confirm that the lens model is perfectly inverting the camera’s physical barrel distortion.
B. IMU Allan Deviation Curve (imu_allan.svg)
Section titled “B. IMU Allan Deviation Curve (imu_allan.svg)”Computes the Allan Deviation of the gyroscope and accelerometer streams under static conditions. The Allan deviation curve (plotted on a log-log scale) allows you to extract:
- White Noise Density (N): Sourced from the slope of at . This represents the continuous-time noise parameters used in the process noise covariance .
- Bias Instability (B): Sourced from the flat bottom of the curve.
- Random Walk (K): Sourced from the slope of at long integration times.
Running s0_inspect on the physical drone rig allows you to verify that your configured process noises exactly match the true physical noise profile of the sensor, protecting the filter from initial over-confidence.