AHRS based on MatrixPilot DCM algorithm; ported from Pololu MinIMU-9 example code in turn based on ArduPilot 1.5

Embed: (wiki syntax)

« Back to documentation index

DCM Class Reference

DCM Class Reference

DCM AHRS algorithm ported to mbed from Pololu MinIMU-9 in turn ported from ArduPilot 1.5 revised in a more OO style, though no done yet. More...

#include <DCM.h>

Public Member Functions

 DCM (void)
 Creates a new DCM AHRS algorithm object.
void Update_step (void)
 A single update cycle for the algorithm; updates the matrix, normalizes it, corrects for gyro drift on 3 axes, (does not yet adjust for acceleration).

Data Fields

float roll
 Output: Euler angle: roll.
float pitch
 Output: Euler angle: pitch.
float yaw
 Output: Euler angle: yaw.
int gyro_x
 Input gyro sensor reading X-axis.
int gyro_y
 Input gyro sensor reading Y-axis.
int gyro_z
 Input gyro sensor reading Z-axis.
int accel_x
 Input accelerometer sensor reading X-axis.
int accel_y
 Input accelerometer sensor reading Y-axis.
int accel_z
 Input accelerometer sensor reading Z-axis.
float c_magnetom_x
 Input for the offset corrected & scaled magnetometer reading, X-axis.
float c_magnetom_y
 Input for the offset corrected & scaled magnetometer reading, Y-axis.
float c_magnetom_z
 Input for the offset corrected & scaled magnetometer reading, Z-axis.
float MAG_Heading
 Input for the calculated magnetic heading.
float speed_3d
 Input for the speed (ie, the magnitude of the 3d velocity vector.
float G_Dt
 Input for the integration time (DCM algorithm)

Detailed Description

DCM AHRS algorithm ported to mbed from Pololu MinIMU-9 in turn ported from ArduPilot 1.5 revised in a more OO style, though no done yet.

Early version. There's more to do here but it's a start, at least.

Warning: Interface will most likely change.

Expects to see a Sensors.h in your project, as follows, with functions that read sensors and set the appropriate "input" member variables below. Eventually I'll change this to a better encapsulated OOP approach.

This approach of an external Sensors.* is an abstraction layer that makes it much, much easier to swap in a different sensor suite versus the original code. You can use Serial, I2C, SPI, Analog, whatever you want, whatever it takes as long as you populate the gyro, accel, and mag vectors before calling Update_step()

 #ifndef __SENSORS_H
 #define __SENSORS_H

 void Gyro_Init(void);
 void Read_Gyro(void);
 void Accel_Init(void);
 void Read_Accel(void);
 void Compass_Init(void);
 void Read_Compass(void);
 void Calculate_Offsets(void);
 void Compass_Heading(void);
 
 #endif

Definition at line 96 of file DCM.h.


Constructor & Destructor Documentation

DCM ( void   )

Creates a new DCM AHRS algorithm object.

Definition at line 53 of file DCM.cpp.


Member Function Documentation

void Update_step ( void   )

A single update cycle for the algorithm; updates the matrix, normalizes it, corrects for gyro drift on 3 axes, (does not yet adjust for acceleration).

Magnetometer update is run less often than gyro/accelerometer-based update

Definition at line 245 of file DCM.cpp.


Field Documentation

int accel_x

Input accelerometer sensor reading X-axis.

Definition at line 112 of file DCM.h.

int accel_y

Input accelerometer sensor reading Y-axis.

Definition at line 114 of file DCM.h.

int accel_z

Input accelerometer sensor reading Z-axis.

Definition at line 116 of file DCM.h.

float c_magnetom_x

Input for the offset corrected & scaled magnetometer reading, X-axis.

Definition at line 123 of file DCM.h.

float c_magnetom_y

Input for the offset corrected & scaled magnetometer reading, Y-axis.

Definition at line 125 of file DCM.h.

float c_magnetom_z

Input for the offset corrected & scaled magnetometer reading, Z-axis.

Definition at line 127 of file DCM.h.

float G_Dt

Input for the integration time (DCM algorithm)

Definition at line 133 of file DCM.h.

int gyro_x

Input gyro sensor reading X-axis.

Definition at line 106 of file DCM.h.

int gyro_y

Input gyro sensor reading Y-axis.

Definition at line 108 of file DCM.h.

int gyro_z

Input gyro sensor reading Z-axis.

Definition at line 110 of file DCM.h.

float MAG_Heading

Input for the calculated magnetic heading.

Definition at line 129 of file DCM.h.

float pitch

Output: Euler angle: pitch.

Definition at line 101 of file DCM.h.

float roll

Output: Euler angle: roll.

Definition at line 99 of file DCM.h.

float speed_3d

Input for the speed (ie, the magnitude of the 3d velocity vector.

Definition at line 131 of file DCM.h.

float yaw

Output: Euler angle: yaw.

Definition at line 103 of file DCM.h.