2010-10-24 15:37:56 -03:00
|
|
|
#ifndef AP_IMU_h
|
|
|
|
#define AP_IMU_h
|
|
|
|
|
2010-11-17 17:20:20 -04:00
|
|
|
#include <FastSerial.h>
|
2010-10-24 15:37:56 -03:00
|
|
|
#include <AP_Math.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "WProgram.h"
|
2010-11-27 00:45:29 -04:00
|
|
|
#include <AP_ADC.h>
|
2010-11-14 22:15:16 -04:00
|
|
|
#include <avr/eeprom.h>
|
2010-10-24 15:37:56 -03:00
|
|
|
|
|
|
|
|
|
|
|
class AP_IMU
|
|
|
|
{
|
2010-12-01 03:57:30 -04:00
|
|
|
|
2010-10-24 15:37:56 -03:00
|
|
|
public:
|
|
|
|
// Constructors
|
2010-12-01 03:57:30 -04:00
|
|
|
AP_IMU(AP_ADC *adc, uint16_t address) :
|
|
|
|
_adc(adc),
|
|
|
|
_address(address)
|
|
|
|
{}
|
2010-10-24 15:37:56 -03:00
|
|
|
|
|
|
|
// Methods
|
2010-12-01 03:57:30 -04:00
|
|
|
void init(void); // inits both
|
|
|
|
void init_accel(void); // just Accels
|
|
|
|
void init_gyro(void); // just gyros
|
2010-12-12 23:57:42 -04:00
|
|
|
void zero_accel(void);
|
2010-12-01 03:57:30 -04:00
|
|
|
|
|
|
|
void load_gyro_eeprom(void);
|
|
|
|
void save_gyro_eeprom(void);
|
|
|
|
void load_accel_eeprom(void);
|
2010-12-02 18:09:25 -04:00
|
|
|
void save_accel_eeprom(void);
|
|
|
|
void print_accel_offsets(void);
|
|
|
|
void print_gyro_offsets(void);
|
2010-12-18 23:21:38 -04:00
|
|
|
|
|
|
|
void ax(const int v) { _adc_offset[3] = v; }
|
|
|
|
void ay(const int v) { _adc_offset[4] = v; }
|
|
|
|
void az(const int v) { _adc_offset[5] = v; }
|
|
|
|
|
2010-10-24 15:37:56 -03:00
|
|
|
|
2010-12-01 03:57:30 -04:00
|
|
|
// raw ADC values - called by DCM
|
|
|
|
Vector3f get_gyro(void); // Radians/second
|
|
|
|
Vector3f get_accel(void); // meters/seconds squared
|
|
|
|
|
2010-10-24 15:37:56 -03:00
|
|
|
// Members
|
2010-12-01 03:57:30 -04:00
|
|
|
uint8_t adc_constraints; // a check of how many times we get non-sensical values
|
2010-10-24 15:37:56 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Methods
|
2010-11-17 17:20:20 -04:00
|
|
|
void read_offsets(void);
|
2010-11-14 22:15:16 -04:00
|
|
|
float gyro_temp_comp(int i, int temp) const;
|
2010-10-24 15:37:56 -03:00
|
|
|
|
|
|
|
// members
|
2010-12-01 03:57:30 -04:00
|
|
|
uint16_t _address; // EEPROM start address for saving/retrieving offsets
|
2010-10-24 15:37:56 -03:00
|
|
|
float _adc_in[6]; // array that store the 6 ADC channels used by IMU
|
|
|
|
float _adc_offset[6]; // Array that store the Offset of the gyros and accelerometers
|
|
|
|
Vector3f _accel_vector; // Store the acceleration in a vector
|
2010-10-30 13:17:16 -03:00
|
|
|
Vector3f _gyro_vector; // Store the gyros turn rate in a vector
|
2010-12-01 03:57:30 -04:00
|
|
|
AP_ADC * _adc; // Analog to digital converter pointer
|
|
|
|
|
|
|
|
float read_EE_float(int address);
|
|
|
|
void write_EE_float(float value, int address);
|
2010-10-24 15:37:56 -03:00
|
|
|
|
|
|
|
// constants
|
|
|
|
static const uint8_t _sensors[6];
|
|
|
|
static const int _sensor_signs[9];
|
|
|
|
static const uint8_t _gyro_temp_ch = 3; // The ADC channel reading the gyro temperature
|
|
|
|
static const float _gyro_temp_curve[3][3];
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|