2010-12-01 03:58:04 -04:00
|
|
|
#ifndef AP_DCM_h
|
|
|
|
#define AP_DCM_h
|
|
|
|
|
2011-09-11 19:02:47 -03:00
|
|
|
// temporarily include all other classes here
|
2010-12-10 06:17:27 -04:00
|
|
|
// since this naming is a bit off from the
|
|
|
|
// convention and the AP_DCM should be the top
|
|
|
|
// header file
|
|
|
|
#include "AP_DCM_HIL.h"
|
|
|
|
|
2011-04-30 23:05:17 -03:00
|
|
|
#include "../FastSerial/FastSerial.h"
|
|
|
|
#include "../AP_Math/AP_Math.h"
|
2010-12-01 03:58:04 -04:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include "WProgram.h"
|
2011-04-30 23:05:17 -03:00
|
|
|
#include "../AP_Compass/AP_Compass.h"
|
|
|
|
#include "../AP_ADC/AP_ADC.h"
|
|
|
|
#include "../AP_GPS/AP_GPS.h"
|
|
|
|
#include "../AP_IMU/AP_IMU.h"
|
2010-12-01 03:58:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
class AP_DCM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructors
|
2011-02-16 03:54:48 -04:00
|
|
|
AP_DCM(IMU *imu, GPS *&gps, Compass *withCompass = NULL) :
|
2010-12-01 03:58:04 -04:00
|
|
|
_compass(withCompass),
|
2011-05-02 02:55:59 -03:00
|
|
|
_gps(gps),
|
|
|
|
_imu(imu),
|
2010-12-01 03:58:04 -04:00
|
|
|
_dcm_matrix(1, 0, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
0, 0, 1),
|
|
|
|
_course_over_ground_x(0),
|
2011-02-25 16:09:00 -04:00
|
|
|
_course_over_ground_y(1),
|
2011-06-12 20:49:01 -03:00
|
|
|
_health(1.),
|
|
|
|
_kp_roll_pitch(0.05967),
|
|
|
|
_ki_roll_pitch(0.00001278),
|
2011-07-08 00:57:12 -03:00
|
|
|
_kp_yaw(0.8), // .8
|
|
|
|
_ki_yaw(0.00004), // 0.00004
|
2011-06-26 19:54:08 -03:00
|
|
|
_toggle(0)
|
2010-12-01 03:58:04 -04:00
|
|
|
{}
|
|
|
|
|
|
|
|
// Accessors
|
2010-12-14 14:39:02 -04:00
|
|
|
Vector3f get_gyro(void) {return _omega_integ_corr; } // We return the raw gyro vector corrected for bias
|
|
|
|
Vector3f get_accel(void) { return _accel_vector; }
|
|
|
|
Matrix3f get_dcm_matrix(void) {return _dcm_matrix; }
|
|
|
|
Matrix3f get_dcm_transposed(void) {Matrix3f temp = _dcm_matrix; return temp.transpose();}
|
2011-11-05 12:02:23 -03:00
|
|
|
Vector3f get_integrator(void) {return _omega_I; } // We return the current drift correction integrator values
|
|
|
|
|
|
|
|
float get_health(void) {return _health;}
|
2011-03-07 21:47:43 -04:00
|
|
|
void set_centripetal(bool b) {_centripetal = b;}
|
|
|
|
bool get_centripetal(void) {return _centripetal;}
|
2010-12-04 02:24:21 -04:00
|
|
|
void set_compass(Compass *compass);
|
2010-12-01 15:53:40 -04:00
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
// Methods
|
2011-09-15 00:04:08 -03:00
|
|
|
void update_DCM(void);
|
|
|
|
void update_DCM_fast(void);
|
2010-12-01 03:58:04 -04:00
|
|
|
|
|
|
|
long roll_sensor; // Degrees * 100
|
|
|
|
long pitch_sensor; // Degrees * 100
|
|
|
|
long yaw_sensor; // Degrees * 100
|
|
|
|
|
|
|
|
float roll; // Radians
|
|
|
|
float pitch; // Radians
|
|
|
|
float yaw; // Radians
|
|
|
|
|
|
|
|
uint8_t gyro_sat_count;
|
|
|
|
uint8_t renorm_sqrt_count;
|
|
|
|
uint8_t renorm_blowup_count;
|
|
|
|
|
2011-06-12 20:49:01 -03:00
|
|
|
float kp_roll_pitch() { return _kp_roll_pitch; }
|
|
|
|
void kp_roll_pitch(float v) { _kp_roll_pitch = v; }
|
|
|
|
|
|
|
|
float ki_roll_pitch() { return _ki_roll_pitch; }
|
|
|
|
void ki_roll_pitch(float v) { _ki_roll_pitch = v; }
|
|
|
|
|
|
|
|
float kp_yaw() { return _kp_yaw; }
|
|
|
|
void kp_yaw(float v) { _kp_yaw = v; }
|
|
|
|
|
2011-07-08 00:57:12 -03:00
|
|
|
float ki_yaw() { return _ki_yaw; }
|
|
|
|
void ki_yaw(float v) { _ki_yaw = v; }
|
|
|
|
|
2011-06-12 20:49:01 -03:00
|
|
|
static const float kDCM_kp_rp_high = 0.15;
|
|
|
|
static const float kDCM_kp_rp_medium = 0.05967;
|
|
|
|
static const float kDCM_kp_rp_low = 0.01;
|
|
|
|
|
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
private:
|
2011-06-12 20:49:01 -03:00
|
|
|
float _kp_roll_pitch;
|
|
|
|
float _ki_roll_pitch;
|
|
|
|
float _kp_yaw;
|
2011-07-08 00:57:12 -03:00
|
|
|
float _ki_yaw;
|
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
// Methods
|
|
|
|
void read_adc_raw(void);
|
|
|
|
void accel_adjust(void);
|
|
|
|
float read_adc(int select);
|
|
|
|
void matrix_update(float _G_Dt);
|
|
|
|
void normalize(void);
|
|
|
|
Vector3f renorm(Vector3f const &a, int &problem);
|
|
|
|
void drift_correction(void);
|
|
|
|
void euler_angles(void);
|
|
|
|
|
2011-09-11 15:03:55 -03:00
|
|
|
void euler_rp(void);
|
|
|
|
void euler_yaw(void);
|
|
|
|
|
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
// members
|
2010-12-02 01:13:35 -04:00
|
|
|
Compass * _compass;
|
2011-02-16 03:54:48 -04: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.
|
|
|
|
GPS *&_gps; // note: this is a reference to a pointer owned by the caller
|
|
|
|
|
|
|
|
IMU *_imu;
|
2010-12-01 03:58:04 -04:00
|
|
|
|
|
|
|
Matrix3f _dcm_matrix;
|
|
|
|
|
|
|
|
Vector3f _accel_vector; // Store the acceleration in a vector
|
|
|
|
Vector3f _gyro_vector; // Store the gyros turn rate in a vector
|
|
|
|
Vector3f _omega_P; // Omega Proportional correction
|
|
|
|
Vector3f _omega_I; // Omega Integrator correction
|
2010-12-28 19:41:26 -04:00
|
|
|
Vector3f _omega_integ_corr; // Partially corrected Gyro_Vector data - used for centrepetal correction
|
2010-12-01 03:58:04 -04:00
|
|
|
Vector3f _omega; // Corrected Gyro_Vector data
|
|
|
|
Vector3f _error_roll_pitch;
|
|
|
|
Vector3f _error_yaw;
|
|
|
|
float _errorCourse;
|
|
|
|
float _course_over_ground_x; // Course overground X axis
|
|
|
|
float _course_over_ground_y; // Course overground Y axis
|
2010-12-01 18:52:11 -04:00
|
|
|
float _health;
|
|
|
|
bool _centripetal;
|
2011-09-11 15:03:55 -03:00
|
|
|
uint8_t _toggle;
|
2010-12-01 03:58:04 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|