2010-12-28 19:41:00 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
/// @file IMU.h
|
|
|
|
/// @brief Abstract class defining the interface to a real or virtual
|
|
|
|
/// Inertial Measurement Unit.
|
|
|
|
|
|
|
|
#ifndef IMU_h
|
|
|
|
#define IMU_h
|
|
|
|
|
2011-04-30 23:05:17 -03:00
|
|
|
#include "../AP_Math/AP_Math.h"
|
2011-11-12 23:24:03 -04:00
|
|
|
#include "../AP_PeriodicProcess/AP_PeriodicProcess.h"
|
2010-12-28 19:41:00 -04:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
class IMU
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Constructor
|
2011-11-12 23:24:03 -04:00
|
|
|
IMU();
|
2011-02-14 00:42:37 -04:00
|
|
|
|
2010-12-28 19:41:00 -04:00
|
|
|
enum Start_style {
|
|
|
|
COLD_START = 0,
|
|
|
|
WARM_START
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Perform startup initialisation.
|
|
|
|
///
|
2011-02-14 00:42:37 -04:00
|
|
|
/// Called to initialise the state of the IMU.
|
2010-12-28 19:41:00 -04:00
|
|
|
///
|
|
|
|
/// For COLD_START, implementations using real sensors can assume
|
|
|
|
/// that the airframe is stationary and nominally oriented.
|
|
|
|
///
|
|
|
|
/// For WARM_START, no assumptions should be made about the
|
|
|
|
/// orientation or motion of the airframe. Calibration should be
|
|
|
|
/// as for the previous COLD_START call.
|
|
|
|
///
|
|
|
|
/// @param style The initialisation startup style.
|
|
|
|
///
|
2011-11-12 23:24:03 -04:00
|
|
|
virtual void init( Start_style style,
|
|
|
|
void (*delay_cb)(unsigned long t),
|
|
|
|
AP_PeriodicProcess * scheduler );
|
2011-02-14 00:42:37 -04:00
|
|
|
|
|
|
|
/// Perform cold startup initialisation for just the accelerometers.
|
2010-12-28 19:41:00 -04:00
|
|
|
///
|
|
|
|
/// @note This should not be called unless ::init has previously
|
|
|
|
/// been called, as ::init may perform other work.
|
|
|
|
///
|
2011-11-12 23:24:03 -04:00
|
|
|
virtual void init_accel(void (*callback)(unsigned long t));
|
2010-12-28 19:41:00 -04:00
|
|
|
|
2011-02-14 00:42:37 -04:00
|
|
|
/// Perform cold-start initialisation for just the gyros.
|
2010-12-28 19:41:00 -04:00
|
|
|
///
|
|
|
|
/// @note This should not be called unless ::init has previously
|
|
|
|
/// been called, as ::init may perform other work
|
|
|
|
///
|
2011-11-12 23:24:03 -04:00
|
|
|
virtual void init_gyro(void (*callback)(unsigned long t));
|
2010-12-28 19:41:00 -04:00
|
|
|
|
|
|
|
/// Give the IMU some cycles to perform/fetch an update from its
|
|
|
|
/// sensors.
|
|
|
|
///
|
|
|
|
/// @returns True if some state was updated.
|
|
|
|
///
|
2011-11-12 23:24:03 -04:00
|
|
|
virtual bool update(void);
|
2010-12-28 19:41:00 -04:00
|
|
|
|
|
|
|
/// Fetch the current gyro values
|
|
|
|
///
|
|
|
|
/// @returns vector of rotational rates in radians/sec
|
2011-02-14 00:42:37 -04:00
|
|
|
///
|
2010-12-28 19:41:00 -04:00
|
|
|
Vector3f get_gyro(void) { return _gyro; }
|
|
|
|
|
|
|
|
/// Fetch the current accelerometer values
|
|
|
|
///
|
|
|
|
/// @returns vector of current accelerations in m/s/s
|
|
|
|
///
|
|
|
|
Vector3f get_accel(void) { return _accel; }
|
|
|
|
|
2011-09-15 00:03:18 -03:00
|
|
|
|
2011-07-08 00:58:19 -03:00
|
|
|
/// Fetch the current accelerometer values
|
|
|
|
///
|
|
|
|
/// @returns vector of current accelerations in m/s/s
|
|
|
|
///
|
|
|
|
Vector3f get_accel_filtered(void) { return _accel_filtered; }
|
|
|
|
|
2011-09-15 00:03:18 -03:00
|
|
|
/// return the number of seconds that the last update represents
|
|
|
|
///
|
|
|
|
/// @returns number of seconds
|
|
|
|
///
|
2011-09-15 05:45:51 -03:00
|
|
|
float get_delta_time(void) { return _sample_time * 1.0e-6; }
|
2011-09-15 00:03:18 -03:00
|
|
|
|
2010-12-28 19:41:00 -04:00
|
|
|
/// A count of bad sensor readings
|
|
|
|
///
|
|
|
|
/// @todo This should be renamed, as there's no guarantee that sensors
|
|
|
|
/// are using ADCs, etc.
|
|
|
|
///
|
|
|
|
uint8_t adc_constraints;
|
|
|
|
|
2011-11-12 23:24:03 -04:00
|
|
|
virtual float gx(void);
|
|
|
|
virtual float gy(void);
|
|
|
|
virtual float gz(void);
|
|
|
|
virtual float ax(void);
|
|
|
|
virtual float ay(void);
|
|
|
|
virtual float az(void);
|
|
|
|
virtual void ax(const float v);
|
|
|
|
virtual void ay(const float v);
|
|
|
|
virtual void az(const float v);
|
|
|
|
|
2010-12-28 19:41:00 -04:00
|
|
|
protected:
|
|
|
|
/// Most recent accelerometer reading obtained by ::update
|
|
|
|
Vector3f _accel;
|
2011-07-08 00:58:19 -03:00
|
|
|
Vector3f _accel_filtered;
|
2010-12-28 19:41:00 -04:00
|
|
|
|
|
|
|
/// Most recent gyro reading obtained by ::update
|
|
|
|
Vector3f _gyro;
|
2011-09-15 00:03:18 -03:00
|
|
|
|
2011-09-15 05:45:51 -03:00
|
|
|
/// number of microseconds that the accel and gyro values
|
|
|
|
/// were sampled over
|
|
|
|
uint32_t _sample_time;
|
2010-12-28 19:41:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|