estimator-1.1.0.0: State-space estimation algorithms such as Kalman Filters

Safe HaskellNone
LanguageHaskell2010

Numeric.Estimator.Model.SensorFusion

Contents

Description

Many kinds of vehicles have a collection of sensors for measuring where they are and where they're going, which may include these sensors and others:

  • accelerometers
  • gyroscopes
  • GPS receiver
  • pressure altimeter
  • 3D magnetometer

Each of these sensors provides some useful information about the current physical state of the vehicle, but they all have two obnoxious problems:

  1. No one sensor provides all the information you want at the update rate you need. GPS gives you absolute position, but at best only ten times per second. Accelerometers can report measurements at high speeds, hundreds to thousands of times per second, but to get position you have to double-integrate the measurement samples.
  2. Every sensor is lying to you. They measure some aspect of the physical state, plus some random error. If you have to integrate these measurements, as with acceleration for instance, then the error accumulates over time. If you take the derivative, perhaps because you have position but you need velocity, the derivative amplifies the noise.

This is an ideal case for a state-space estimation algorithm. Once you've specified the kinetic model of the physical system, and modeled each of your sensors, and identified the noise parameters for everything, the estimation algorithm is responsible for combining all the measurements. The estimator will decide how much to trust each sensor based on how much confidence it has in its current state estimate, and how well that state agrees with the current measurement.

This module implements a system model for sensor fusion. With appropriate noise parameters, it should work for a wide variety of vehicle types and sensor platforms, whether on land, sea, air, or space. However, it has been implemented specifically for quad-copter autopilots. As a result the state vector may have components your system does not need, or be missing ones you do need.

Synopsis

Documentation

data StateVector a Source

A collection of all the state variables needed for this model.

Constructors

StateVector 

Fields

stateOrient :: !(Quaternion a)

quaternions defining attitude of body axes relative to local NED

stateVel :: !(NED a)

NED velocity - m/sec

statePos :: !(NED a)

NED position - m

stateGyroBias :: !(XYZ a)

delta angle bias - rad

stateWind :: !(NED a)

NED wind velocity - m/sec

stateMagNED :: !(NED a)

NED earth fixed magnetic field components - milligauss

stateMagXYZ :: !(XYZ a)

XYZ body fixed magnetic field measurements - milligauss

data DisturbanceVector a Source

Define the control (disturbance) vector. Error growth in the inertial solution is assumed to be driven by noise in the delta angles and velocities, after bias effects have been removed. This is OK becasue we have sensor bias accounted for in the state equations.

Constructors

DisturbanceVector 

Fields

disturbanceGyro :: !(XYZ a)

XYZ body rotation rate in rad/second

disturbanceAccel :: !(XYZ a)

XYZ body acceleration in meters/second/second

Model initialization

initCovariance :: Fractional a => StateVector (StateVector a) Source

Initial covariance for this model.

initAttitude Source

Arguments

:: (Floating a, HasAtan2 a) 
=> XYZ a

initial accelerometer reading

-> XYZ a

initial magnetometer reading

-> a

local magnetic declination from true North

-> Quaternion a

computed initial attitude

When the sensor platform is not moving, a three-axis accelerometer will sense an approximately 1g acceleration in the direction of gravity, which gives us the platform's orientation aside from not knowing the current rotation around the gravity vector.

At the same time, a 3D magnetometer will sense the platform's orientation with respect to the local magnetic field, aside from not knowing the current rotation around the magnetic field line.

Putting these two together gives the platform's complete orientation since the gravity vector and magnetic field line aren't collinear.

initDynamic Source

Arguments

:: (Floating a, HasAtan2 a) 
=> XYZ a

initial accelerometer reading

-> XYZ a

initial magnetometer reading

-> XYZ a

initial magnetometer bias

-> a

local magnetic declination from true North

-> NED a

initial velocity

-> NED a

initial position

-> StateVector a

computed initial state

Compute an initial filter state from an assortment of initial measurements.

Model equations

processModel Source

Arguments

:: Fractional a 
=> a

time since last process model update

-> AugmentState StateVector DisturbanceVector a

prior (augmented) state

-> AugmentState StateVector DisturbanceVector a

posterior (augmented) state

This is the kinematic sensor fusion process model, driven by accelerometer and gyro measurements.

statePressure :: Floating a => StateVector a -> a Source

Compute the local air pressure from the state vector. Useful as a measurement model for a pressure sensor.

stateTAS :: Floating a => StateVector a -> a Source

Compute the true air-speed of the sensor platform. Useful as a measurement model for a true air-speed sensor.

stateMag :: Num a => StateVector a -> XYZ a Source

Compute the expected body-frame magnetic field strength and direction, given the hard-iron correction and local declination-adjusted field from the state vector. Useful as a measurement model for a 3D magnetometer.

Helpers

body2nav :: Num a => StateVector a -> XYZ a -> NED a Source

Convert body-frame to navigation-frame given the orientation from this state vector.

nav2body :: Num a => StateVector a -> NED a -> XYZ a Source

Convert navigation-frame to body-frame given the orientation from this state vector.