2017-08-18 05:58:08 -03:00
|
|
|
#pragma once
|
|
|
|
|
2018-04-04 02:49:56 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
|
|
|
|
2017-08-18 05:58:08 -03:00
|
|
|
/*
|
|
|
|
compass learning using magnetic field tables from AP_Declination
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CompassLearn {
|
|
|
|
public:
|
2018-10-19 02:07:53 -03:00
|
|
|
CompassLearn(Compass &compass);
|
2017-08-18 05:58:08 -03:00
|
|
|
|
|
|
|
// called on each compass read
|
|
|
|
void update(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Compass &compass;
|
|
|
|
bool have_earth_field;
|
|
|
|
|
|
|
|
// 5 degree resolution
|
|
|
|
static const uint16_t num_sectors = 72;
|
|
|
|
|
|
|
|
Vector3f predicted_offsets[num_sectors];
|
|
|
|
float errors[num_sectors];
|
|
|
|
uint32_t num_samples;
|
|
|
|
|
|
|
|
// earth field
|
|
|
|
Vector3f mag_ef;
|
|
|
|
|
|
|
|
// semaphore for access to shared data with IO thread
|
2018-10-11 20:35:03 -03:00
|
|
|
HAL_Semaphore sem;
|
2017-08-18 05:58:08 -03:00
|
|
|
|
|
|
|
struct sample {
|
|
|
|
// milliGauss body field and offsets
|
|
|
|
Vector3f field;
|
|
|
|
Vector3f offsets;
|
|
|
|
|
|
|
|
// euler radians attitude
|
|
|
|
Vector3f attitude;
|
|
|
|
};
|
|
|
|
|
|
|
|
Matrix3f mat;
|
|
|
|
|
|
|
|
struct sample new_sample;
|
|
|
|
bool sample_available;
|
|
|
|
Vector3f last_field;
|
|
|
|
static const uint32_t min_field_change = 60;
|
|
|
|
|
|
|
|
Vector3f best_offsets;
|
|
|
|
float best_error;
|
|
|
|
float best_yaw_deg;
|
|
|
|
float worst_error;
|
|
|
|
bool converged;
|
|
|
|
|
|
|
|
void io_timer(void);
|
|
|
|
void process_sample(const struct sample &s);
|
|
|
|
};
|