2012-03-19 03:34:12 -03:00
|
|
|
#ifndef AP_AHRS_H
|
|
|
|
#define AP_AHRS_H
|
|
|
|
/*
|
2012-08-21 23:19:51 -03:00
|
|
|
* AHRS (Attitude Heading Reference System) interface for ArduPilot
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*/
|
2012-03-19 03:34:12 -03:00
|
|
|
|
|
|
|
#include <AP_Math.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <AP_Compass.h>
|
2012-08-10 19:57:32 -03:00
|
|
|
#include <AP_Airspeed.h>
|
2012-03-19 03:34:12 -03:00
|
|
|
#include <AP_GPS.h>
|
2012-11-05 00:29:00 -04:00
|
|
|
#include <AP_InertialSensor.h>
|
2012-06-19 01:47:09 -03:00
|
|
|
#include <AP_Baro.h>
|
2012-03-19 03:34:12 -03:00
|
|
|
|
|
|
|
#if defined(ARDUINO) && ARDUINO >= 100
|
2012-08-21 23:19:51 -03:00
|
|
|
#include "Arduino.h"
|
2012-03-19 03:34:12 -03:00
|
|
|
#else
|
2012-08-21 23:19:51 -03:00
|
|
|
#include "WProgram.h"
|
2012-03-19 03:34:12 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
class AP_AHRS
|
|
|
|
{
|
|
|
|
public:
|
2012-08-21 23:19:51 -03:00
|
|
|
// Constructor
|
2012-11-05 00:29:00 -04:00
|
|
|
AP_AHRS(AP_InertialSensor *ins, GPS *&gps) :
|
|
|
|
_ins(ins),
|
2012-08-21 23:19:51 -03:00
|
|
|
_gps(gps),
|
|
|
|
_barometer(NULL)
|
|
|
|
{
|
|
|
|
// base the ki values by the sensors maximum drift
|
|
|
|
// rate. The APM2 has gyros which are much less drift
|
|
|
|
// prone than the APM1, so we should have a lower ki,
|
|
|
|
// which will make us less prone to increasing omegaI
|
|
|
|
// incorrectly due to sensor noise
|
2012-11-05 00:29:00 -04:00
|
|
|
_gyro_drift_limit = ins->get_gyro_drift_rate();
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// empty init
|
2012-09-29 01:51:21 -03:00
|
|
|
virtual void init( AP_PeriodicProcess * scheduler = NULL ) {
|
2012-08-21 23:19:51 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
void set_fly_forward(bool b) {
|
|
|
|
_fly_forward = b;
|
|
|
|
}
|
|
|
|
void set_compass(Compass *compass) {
|
|
|
|
_compass = compass;
|
|
|
|
}
|
|
|
|
void set_barometer(AP_Baro *barometer) {
|
|
|
|
_barometer = barometer;
|
|
|
|
}
|
|
|
|
void set_airspeed(AP_Airspeed *airspeed) {
|
|
|
|
_airspeed = airspeed;
|
|
|
|
}
|
|
|
|
|
2012-11-05 00:29:00 -04:00
|
|
|
AP_InertialSensor* get_ins() {
|
|
|
|
return _ins;
|
2012-08-21 23:14:39 -03:00
|
|
|
}
|
|
|
|
|
2012-12-12 03:22:56 -04:00
|
|
|
// accelerometer values in the earth frame in m/s/s
|
|
|
|
Vector3f get_accel_ef(void) { return _accel_ef; }
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// Methods
|
|
|
|
virtual void update(void) = 0;
|
|
|
|
|
|
|
|
// Euler angles (radians)
|
|
|
|
float roll;
|
|
|
|
float pitch;
|
|
|
|
float yaw;
|
|
|
|
|
|
|
|
// integer Euler angles (Degrees * 100)
|
|
|
|
int32_t roll_sensor;
|
|
|
|
int32_t pitch_sensor;
|
|
|
|
int32_t yaw_sensor;
|
|
|
|
|
2012-08-24 08:22:58 -03:00
|
|
|
// roll and pitch rates in earth frame, in radians/s
|
|
|
|
float get_pitch_rate_earth(void);
|
|
|
|
float get_roll_rate_earth(void);
|
2012-08-21 23:14:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// return a smoothed and corrected gyro vector
|
|
|
|
virtual Vector3f get_gyro(void) = 0;
|
|
|
|
|
|
|
|
// return the current estimate of the gyro drift
|
|
|
|
virtual Vector3f get_gyro_drift(void) = 0;
|
|
|
|
|
|
|
|
// reset the current attitude, used on new IMU calibration
|
|
|
|
virtual void reset(bool recover_eulers=false) = 0;
|
|
|
|
|
|
|
|
// how often our attitude representation has gone out of range
|
|
|
|
uint8_t renorm_range_count;
|
|
|
|
|
|
|
|
// how often our attitude representation has blown up completely
|
|
|
|
uint8_t renorm_blowup_count;
|
|
|
|
|
|
|
|
// return the average size of the roll/pitch error estimate
|
|
|
|
// since last call
|
|
|
|
virtual float get_error_rp(void) = 0;
|
|
|
|
|
|
|
|
// return the average size of the yaw error estimate
|
|
|
|
// since last call
|
|
|
|
virtual float get_error_yaw(void) = 0;
|
|
|
|
|
|
|
|
// return a DCM rotation matrix representing our current
|
|
|
|
// attitude
|
|
|
|
virtual Matrix3f get_dcm_matrix(void) = 0;
|
|
|
|
|
|
|
|
// get our current position, either from GPS or via
|
|
|
|
// dead-reckoning. Return true if a position is available,
|
|
|
|
// otherwise false. This only updates the lat and lng fields
|
|
|
|
// of the Location
|
|
|
|
bool get_position(struct Location *loc) {
|
|
|
|
if (!_gps || _gps->status() != GPS::GPS_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
loc->lat = _gps->latitude;
|
|
|
|
loc->lng = _gps->longitude;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return a wind estimation vector, in m/s
|
|
|
|
Vector3f wind_estimate(void) {
|
|
|
|
return Vector3f(0,0,0);
|
|
|
|
}
|
|
|
|
|
2012-08-24 08:22:58 -03:00
|
|
|
// return an airspeed estimate if available. return true
|
|
|
|
// if we have an estimate
|
|
|
|
bool airspeed_estimate(float *airspeed_ret);
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// return true if yaw has been initialised
|
|
|
|
bool yaw_initialised(void) {
|
|
|
|
return _have_initial_yaw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the fast gains flag
|
|
|
|
void set_fast_gains(bool setting) {
|
|
|
|
_fast_ground_gains = setting;
|
|
|
|
}
|
|
|
|
|
2012-11-05 00:29:00 -04:00
|
|
|
// get strim
|
|
|
|
Vector3f get_trim() { return _trim; }
|
|
|
|
|
|
|
|
// set_trim
|
2012-12-12 04:24:28 -04:00
|
|
|
virtual void set_trim(Vector3f new_trim) { _trim.set_and_save(new_trim); }
|
2012-11-05 00:29:00 -04:00
|
|
|
|
|
|
|
// add_trim - adjust the roll and pitch trim up to a total of 10 degrees
|
|
|
|
virtual void add_trim(float roll_in_radians, float pitch_in_radians);
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// settable parameters
|
|
|
|
AP_Float _kp_yaw;
|
|
|
|
AP_Float _kp;
|
|
|
|
AP_Float gps_gain;
|
|
|
|
AP_Int8 _gps_use;
|
2012-09-12 01:42:04 -03:00
|
|
|
AP_Int8 _baro_use;
|
2012-09-07 22:27:12 -03:00
|
|
|
AP_Int8 _wind_max;
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
// for holding parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2012-08-21 02:58:09 -03:00
|
|
|
|
2012-03-19 03:34:12 -03:00
|
|
|
protected:
|
2012-08-21 23:19:51 -03:00
|
|
|
// whether the yaw value has been intialised with a reference
|
|
|
|
bool _have_initial_yaw;
|
2012-08-12 22:08:10 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// pointer to compass object, if available
|
|
|
|
Compass * _compass;
|
2012-03-19 03:34:12 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// pointer to airspeed object, if available
|
|
|
|
AP_Airspeed * _airspeed;
|
2012-08-10 19:57:32 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// time in microseconds of last compass update
|
|
|
|
uint32_t _compass_last_update;
|
2012-03-19 03:34:12 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// note: we use ref-to-pointer here so that our caller can change the GPS without our noticing
|
|
|
|
// IMU under us without our noticing.
|
2012-11-05 00:29:00 -04:00
|
|
|
AP_InertialSensor *_ins;
|
|
|
|
GPS *&_gps;
|
|
|
|
AP_Baro *_barometer;
|
|
|
|
|
|
|
|
// a vector to capture the difference between the controller and body frames
|
|
|
|
AP_Vector3f _trim;
|
2012-03-19 03:34:12 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// should we raise the gain on the accelerometers for faster
|
|
|
|
// convergence, used when disarmed for ArduCopter
|
|
|
|
bool _fast_ground_gains;
|
2012-08-21 02:38:06 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// true if we can assume the aircraft will be flying forward
|
|
|
|
// on its X axis
|
|
|
|
bool _fly_forward;
|
2012-03-19 03:34:12 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// the limit of the gyro drift claimed by the sensors, in
|
|
|
|
// radians/s/s
|
|
|
|
float _gyro_drift_limit;
|
2012-04-15 21:26:16 -03:00
|
|
|
|
2012-12-12 03:22:56 -04:00
|
|
|
// accelerometer values in the earth frame in m/s/s
|
|
|
|
Vector3f _accel_ef;
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// acceleration due to gravity in m/s/s
|
|
|
|
static const float _gravity = 9.80665;
|
2012-11-05 00:29:00 -04:00
|
|
|
|
2012-03-19 03:34:12 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#include <AP_AHRS_DCM.h>
|
2012-07-28 02:16:56 -03:00
|
|
|
#include <AP_AHRS_MPU6000.h>
|
2012-03-19 03:34:12 -03:00
|
|
|
#include <AP_AHRS_HIL.h>
|
|
|
|
|
|
|
|
#endif // AP_AHRS_H
|