2011-02-14 00:42:37 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2010-12-28 19:41:00 -04:00
|
|
|
|
|
|
|
/// @file AP_IMU_Oilpan.h
|
|
|
|
/// @brief IMU driver for the APM oilpan
|
|
|
|
|
|
|
|
#ifndef AP_IMU_Oilpan_h
|
|
|
|
#define AP_IMU_Oilpan_h
|
|
|
|
|
|
|
|
|
2011-04-30 23:05:17 -03:00
|
|
|
#include "../AP_Common/AP_Common.h"
|
|
|
|
#include "../AP_Math/AP_Math.h"
|
|
|
|
#include "../AP_ADC/AP_ADC.h"
|
2010-12-28 19:41:00 -04:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2011-02-14 00:42:37 -04:00
|
|
|
#include "IMU.h"
|
|
|
|
|
2010-12-28 19:41:00 -04:00
|
|
|
class AP_IMU_Oilpan : public IMU
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2011-02-14 00:42:37 -04:00
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
/// Saves the ADC pointer and constructs the calibration data variable.
|
|
|
|
///
|
|
|
|
/// @param adc Pointer to the AP_ADC instance that is connected to the gyro and accelerometer.
|
|
|
|
/// @param key The AP_Var::key value we will use when loading/saving calibration data.
|
|
|
|
///
|
|
|
|
AP_IMU_Oilpan(AP_ADC *adc, AP_Var::Key key) :
|
|
|
|
_adc(adc),
|
2011-02-20 19:10:18 -04:00
|
|
|
_sensor_cal(key, PSTR("IMU_SENSOR_CAL"))
|
|
|
|
// _sensor_cal(key, PSTR("IMU_SENSOR_CAL"), AP_Var::k_flag_no_auto_load)
|
2010-12-28 19:41:00 -04:00
|
|
|
{}
|
|
|
|
|
2011-02-14 00:42:37 -04:00
|
|
|
/// Do warm or cold start.
|
|
|
|
///
|
|
|
|
/// @note For a partial-warmstart where e.g. the accelerometer calibration should be preserved
|
|
|
|
/// but the gyro cal needs to be re-performed, start with ::init(WARM_START) to load the
|
|
|
|
/// previous calibration settings, then force a re-calibration of the gyro with ::init_gyro.
|
|
|
|
///
|
|
|
|
/// @param style Selects the initialisation style.
|
|
|
|
/// COLD_START performs calibration of both the accelerometer and gyro.
|
|
|
|
/// WARM_START loads accelerometer and gyro calibration from a previous cold start.
|
|
|
|
///
|
2011-07-31 19:34:25 -03:00
|
|
|
virtual void init(Start_style style = COLD_START, void (*callback)(unsigned long t) = delay);
|
2011-02-20 19:10:18 -04:00
|
|
|
|
2011-02-18 23:57:19 -04:00
|
|
|
virtual void save();
|
2011-07-31 19:34:25 -03:00
|
|
|
virtual void init_accel(void (*callback)(unsigned long t) = delay);
|
|
|
|
virtual void init_gyro(void (*callback)(unsigned long t) = delay);
|
2011-02-14 00:42:37 -04:00
|
|
|
virtual bool update(void);
|
2011-02-20 19:10:18 -04:00
|
|
|
|
2011-02-18 23:57:19 -04:00
|
|
|
// for jason
|
2011-02-20 19:10:18 -04:00
|
|
|
float gx() { return _sensor_cal[0]; }
|
|
|
|
float gy() { return _sensor_cal[1]; }
|
|
|
|
float gz() { return _sensor_cal[2]; }
|
|
|
|
float ax() { return _sensor_cal[3]; }
|
|
|
|
float ay() { return _sensor_cal[4]; }
|
|
|
|
float az() { return _sensor_cal[5]; }
|
|
|
|
|
|
|
|
void ax(const float v) { _sensor_cal[3] = v; }
|
|
|
|
void ay(const float v) { _sensor_cal[4] = v; }
|
|
|
|
void az(const float v) { _sensor_cal[5] = v; }
|
|
|
|
|
|
|
|
|
2010-12-28 19:41:00 -04:00
|
|
|
private:
|
2011-02-14 00:42:37 -04:00
|
|
|
AP_ADC *_adc; ///< ADC that we use for reading sensors
|
|
|
|
AP_VarA<float,6> _sensor_cal; ///< Calibrated sensor offsets
|
2010-12-28 19:41:00 -04:00
|
|
|
|
2011-07-31 19:34:25 -03:00
|
|
|
virtual void _init_accel(void (*callback)(unsigned long t)); ///< no-save implementation
|
|
|
|
virtual void _init_gyro(void (*callback)(unsigned long t)); ///< no-save implementation
|
2010-12-28 19:41:00 -04:00
|
|
|
|
2011-02-14 00:42:37 -04:00
|
|
|
float _sensor_compensation(uint8_t channel, int temp) const;
|
|
|
|
float _sensor_in(uint8_t channel, int temperature);
|
2010-12-28 19:41:00 -04:00
|
|
|
|
|
|
|
// constants
|
2011-02-14 00:42:37 -04:00
|
|
|
static const uint8_t _sensors[6]; ///< ADC channel mappings for the sensors
|
|
|
|
static const int8_t _sensor_signs[6]; ///< ADC result sign adjustment for sensors
|
|
|
|
static const uint8_t _gyro_temp_ch = 3; ///< ADC channel reading the gyro temperature
|
|
|
|
static const float _gyro_temp_curve[3][3]; ///< Temperature compensation curve for the gyro
|
|
|
|
|
|
|
|
// ADC : Voltage reference 3.3v / 12bits(4096 steps) => 0.8mV/ADC step
|
|
|
|
// ADXL335 Sensitivity(from datasheet) => 330mV/g, 0.8mV/ADC step => 330/0.8 = 412
|
|
|
|
// Tested value : 418
|
|
|
|
//
|
2011-02-25 13:49:31 -04:00
|
|
|
static const float _gravity = 423.8; ///< 1G in the raw data coming from the accelerometer
|
|
|
|
// Value based on actual sample data from 20 boards
|
|
|
|
static const float _accel_scale = 9.80665 / 423.8; ///< would like to use _gravity here, but cannot
|
2011-02-14 00:42:37 -04:00
|
|
|
|
|
|
|
// IDG500 Sensitivity (from datasheet) => 2.0mV/degree/s, 0.8mV/ADC step => 0.8/3.33 = 0.4
|
|
|
|
// Tested values : 0.4026, ?, 0.4192
|
|
|
|
//
|
|
|
|
static const float _gyro_gain_x = 0.4; // X axis Gyro gain
|
|
|
|
static const float _gyro_gain_y = 0.41; // Y axis Gyro gain
|
|
|
|
static const float _gyro_gain_z = 0.41; // Z axis Gyro gain
|
|
|
|
|
|
|
|
// Maximum possible value returned by an offset-corrected sensor channel
|
|
|
|
//
|
|
|
|
static const float _adc_constraint = 900;
|
2011-06-26 03:23:22 -03:00
|
|
|
|
2011-02-25 13:49:31 -04:00
|
|
|
// Gyro and Accelerometer calibration criterial
|
|
|
|
//
|
|
|
|
static const float _gyro_total_cal_change = 4.0; // Experimentally derived - allows for some minor motion
|
2011-06-26 03:23:22 -03:00
|
|
|
static const float _gyro_max_cal_offset = 320.0;
|
2011-02-25 13:49:31 -04:00
|
|
|
static const float _accel_total_cal_change = 4.0;
|
|
|
|
static const float _accel_max_cal_offset = 250.0;
|
2011-06-26 03:23:22 -03:00
|
|
|
|
2010-12-28 19:41:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|