mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-26 01:33:56 -04:00
AP_Compass: enable in-flight compass learning system
using COMPASS_LEARN=3
This commit is contained in:
parent
7e790a04d2
commit
5ac6309848
@ -23,6 +23,7 @@
|
|||||||
#include "AP_Compass_MMC3416.h"
|
#include "AP_Compass_MMC3416.h"
|
||||||
#include "AP_Compass_MAG3110.h"
|
#include "AP_Compass_MAG3110.h"
|
||||||
#include "AP_Compass.h"
|
#include "AP_Compass.h"
|
||||||
|
#include "Compass_learn.h"
|
||||||
|
|
||||||
extern AP_HAL::HAL& hal;
|
extern AP_HAL::HAL& hal;
|
||||||
|
|
||||||
@ -968,6 +969,13 @@ Compass::read(void)
|
|||||||
for (uint8_t i=0; i < COMPASS_MAX_INSTANCES; i++) {
|
for (uint8_t i=0; i < COMPASS_MAX_INSTANCES; i++) {
|
||||||
_state[i].healthy = (time - _state[i].last_update_ms < 500);
|
_state[i].healthy = (time - _state[i].last_update_ms < 500);
|
||||||
}
|
}
|
||||||
|
if (_learn == LEARN_INFLIGHT && !learn_allocated) {
|
||||||
|
learn_allocated = true;
|
||||||
|
learn = new CompassLearn(*this);
|
||||||
|
}
|
||||||
|
if (_learn == LEARN_INFLIGHT && learn != nullptr) {
|
||||||
|
learn->update();
|
||||||
|
}
|
||||||
return healthy();
|
return healthy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
#define COMPASS_MAX_INSTANCES 3
|
#define COMPASS_MAX_INSTANCES 3
|
||||||
#define COMPASS_MAX_BACKEND 3
|
#define COMPASS_MAX_BACKEND 3
|
||||||
|
|
||||||
|
class CompassLearn;
|
||||||
|
|
||||||
class Compass
|
class Compass
|
||||||
{
|
{
|
||||||
friend class AP_Compass_Backend;
|
friend class AP_Compass_Backend;
|
||||||
@ -187,7 +189,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// learn offsets accessor
|
// learn offsets accessor
|
||||||
bool learn_offsets_enabled() const { return _learn; }
|
bool learn_offsets_enabled() const { return _learn == LEARN_INFLIGHT; }
|
||||||
|
|
||||||
/// return true if the compass should be used for yaw calculations
|
/// return true if the compass should be used for yaw calculations
|
||||||
bool use_for_yaw(uint8_t i) const;
|
bool use_for_yaw(uint8_t i) const;
|
||||||
@ -476,6 +478,9 @@ private:
|
|||||||
AP_Int32 _driver_type_mask;
|
AP_Int32 _driver_type_mask;
|
||||||
|
|
||||||
AP_Int8 _filter_range;
|
AP_Int8 _filter_range;
|
||||||
|
|
||||||
|
CompassLearn *learn;
|
||||||
|
bool learn_allocated;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace AP {
|
namespace AP {
|
||||||
|
@ -6,16 +6,17 @@
|
|||||||
#include <DataFlash/DataFlash.h>
|
#include <DataFlash/DataFlash.h>
|
||||||
|
|
||||||
#include "Compass_learn.h"
|
#include "Compass_learn.h"
|
||||||
|
#include <GCS_MAVLink/GCS.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern const AP_HAL::HAL &hal;
|
extern const AP_HAL::HAL &hal;
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
CompassLearn::CompassLearn(AP_AHRS &_ahrs, Compass &_compass) :
|
CompassLearn::CompassLearn(Compass &_compass) :
|
||||||
ahrs(_ahrs),
|
|
||||||
compass(_compass)
|
compass(_compass)
|
||||||
{
|
{
|
||||||
|
gcs().send_text(MAV_SEVERITY_INFO, "CompassLearn: Initialised");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -23,6 +24,7 @@ CompassLearn::CompassLearn(AP_AHRS &_ahrs, Compass &_compass) :
|
|||||||
*/
|
*/
|
||||||
void CompassLearn::update(void)
|
void CompassLearn::update(void)
|
||||||
{
|
{
|
||||||
|
const AP_AHRS &ahrs = AP::ahrs();
|
||||||
if (converged || compass.get_learn_type() != Compass::LEARN_INFLIGHT ||
|
if (converged || compass.get_learn_type() != Compass::LEARN_INFLIGHT ||
|
||||||
!hal.util->get_soft_armed() || ahrs.get_time_flying_ms() < 3000) {
|
!hal.util->get_soft_armed() || ahrs.get_time_flying_ms() < 3000) {
|
||||||
// only learn when flying and with enough time to be clear of
|
// only learn when flying and with enough time to be clear of
|
||||||
@ -70,6 +72,7 @@ void CompassLearn::update(void)
|
|||||||
errors[i] = intensity_gauss*1000;
|
errors[i] = intensity_gauss*1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcs().send_text(MAV_SEVERITY_INFO, "CompassLearn: have earth field");
|
||||||
hal.scheduler->register_io_process(FUNCTOR_BIND_MEMBER(&CompassLearn::io_timer, void));
|
hal.scheduler->register_io_process(FUNCTOR_BIND_MEMBER(&CompassLearn::io_timer, void));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +122,7 @@ void CompassLearn::update(void)
|
|||||||
compass.set_use_for_yaw(0, true);
|
compass.set_use_for_yaw(0, true);
|
||||||
compass.set_learn_type(Compass::LEARN_EKF, true);
|
compass.set_learn_type(Compass::LEARN_EKF, true);
|
||||||
converged = true;
|
converged = true;
|
||||||
|
gcs().send_text(MAV_SEVERITY_INFO, "CompassLearn: finished");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,12 @@
|
|||||||
|
|
||||||
class CompassLearn {
|
class CompassLearn {
|
||||||
public:
|
public:
|
||||||
CompassLearn(AP_AHRS &ahrs, Compass &compass);
|
CompassLearn(Compass &compass);
|
||||||
|
|
||||||
// called on each compass read
|
// called on each compass read
|
||||||
void update(void);
|
void update(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// reference to AHRS library. Needed for attitude, position and compass
|
|
||||||
const AP_AHRS &ahrs;
|
|
||||||
Compass &compass;
|
Compass &compass;
|
||||||
bool have_earth_field;
|
bool have_earth_field;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user