2016-03-10 20:41:18 -04:00
|
|
|
#pragma once
|
2010-12-02 01:13:12 -04:00
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Declination/AP_Declination.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2018-03-01 17:42:31 -04:00
|
|
|
#include <AP_BattMonitor/AP_BattMonitor.h>
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
#include "CompassCalibrator.h"
|
|
|
|
#include "AP_Compass_Backend.h"
|
2018-01-05 06:08:04 -04:00
|
|
|
#include "Compass_PerMotor.h"
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
// motor compensation types (for use with motor_comp_enabled)
|
|
|
|
#define AP_COMPASS_MOT_COMP_DISABLED 0x00
|
|
|
|
#define AP_COMPASS_MOT_COMP_THROTTLE 0x01
|
|
|
|
#define AP_COMPASS_MOT_COMP_CURRENT 0x02
|
2018-01-05 06:08:04 -04:00
|
|
|
#define AP_COMPASS_MOT_COMP_PER_MOTOR 0x03
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
// setup default mag orientation for some board types
|
2018-02-15 02:22:19 -04:00
|
|
|
#ifndef MAG_BOARD_ORIENTATION
|
2017-09-08 02:42:14 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
2016-03-10 20:41:18 -04:00
|
|
|
# define MAG_BOARD_ORIENTATION ROTATION_YAW_90
|
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI)
|
|
|
|
# define MAG_BOARD_ORIENTATION ROTATION_YAW_270
|
|
|
|
#else
|
|
|
|
# define MAG_BOARD_ORIENTATION ROTATION_NONE
|
|
|
|
#endif
|
2018-02-15 02:22:19 -04:00
|
|
|
#endif
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
|
2017-01-20 23:08:35 -04:00
|
|
|
// define default compass calibration fitness and consistency checks
|
2017-01-25 04:27:53 -04:00
|
|
|
#define AP_COMPASS_CALIBRATION_FITNESS_DEFAULT 16.0f
|
|
|
|
#define AP_COMPASS_MAX_XYZ_ANG_DIFF radians(90.0f)
|
|
|
|
#define AP_COMPASS_MAX_XY_ANG_DIFF radians(60.0f)
|
|
|
|
#define AP_COMPASS_MAX_XY_LENGTH_DIFF 200.0f
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
/**
|
|
|
|
maximum number of compass instances available on this platform. If more
|
|
|
|
than 1 then redundant sensors may be available
|
|
|
|
*/
|
|
|
|
#define COMPASS_MAX_INSTANCES 3
|
|
|
|
#define COMPASS_MAX_BACKEND 3
|
|
|
|
|
2018-10-19 02:07:53 -03:00
|
|
|
class CompassLearn;
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
class Compass
|
|
|
|
{
|
|
|
|
friend class AP_Compass_Backend;
|
|
|
|
public:
|
2017-12-12 21:06:12 -04:00
|
|
|
Compass();
|
2017-08-08 04:52:41 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
Compass(const Compass &other) = delete;
|
|
|
|
Compass &operator=(const Compass&) = delete;
|
2016-03-10 20:41:18 -04:00
|
|
|
|
2018-03-29 01:13:55 -03:00
|
|
|
// get singleton instance
|
|
|
|
static Compass *get_singleton() {
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:58:08 -03:00
|
|
|
friend class CompassLearn;
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
/// Initialize the compass device.
|
|
|
|
///
|
|
|
|
/// @returns True if the compass was initialized OK, false if it was not
|
|
|
|
/// found or is not functioning.
|
|
|
|
///
|
2018-07-03 04:36:32 -03:00
|
|
|
void init();
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
/// Read the compass and update the mag_ variables.
|
|
|
|
///
|
|
|
|
bool read();
|
|
|
|
|
2019-03-24 00:24:56 -03:00
|
|
|
bool enabled() const { return _enabled; }
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
/// Calculate the tilt-compensated heading_ variables.
|
|
|
|
///
|
|
|
|
/// @param dcm_matrix The current orientation rotation matrix
|
|
|
|
///
|
|
|
|
/// @returns heading in radians
|
|
|
|
///
|
|
|
|
float calculate_heading(const Matrix3f &dcm_matrix) const {
|
|
|
|
return calculate_heading(dcm_matrix, get_primary());
|
|
|
|
}
|
|
|
|
float calculate_heading(const Matrix3f &dcm_matrix, uint8_t i) const;
|
|
|
|
|
|
|
|
/// Sets offset x/y/z values.
|
|
|
|
///
|
|
|
|
/// @param i compass instance
|
|
|
|
/// @param offsets Offsets to the raw mag_ values in milligauss.
|
|
|
|
///
|
|
|
|
void set_offsets(uint8_t i, const Vector3f &offsets);
|
|
|
|
|
|
|
|
/// Sets and saves the compass offset x/y/z values.
|
|
|
|
///
|
|
|
|
/// @param i compass instance
|
|
|
|
/// @param offsets Offsets to the raw mag_ values in milligauss.
|
|
|
|
///
|
|
|
|
void set_and_save_offsets(uint8_t i, const Vector3f &offsets);
|
|
|
|
void set_and_save_diagonals(uint8_t i, const Vector3f &diagonals);
|
|
|
|
void set_and_save_offdiagonals(uint8_t i, const Vector3f &diagonals);
|
|
|
|
|
|
|
|
/// Saves the current offset x/y/z values for one or all compasses
|
|
|
|
///
|
|
|
|
/// @param i compass instance
|
|
|
|
///
|
|
|
|
/// This should be invoked periodically to save the offset values maintained by
|
|
|
|
/// ::learn_offsets.
|
|
|
|
///
|
|
|
|
void save_offsets(uint8_t i);
|
|
|
|
void save_offsets(void);
|
|
|
|
|
|
|
|
// return the number of compass instances
|
|
|
|
uint8_t get_count(void) const { return _compass_count; }
|
|
|
|
|
|
|
|
/// Return the current field as a Vector3f in milligauss
|
|
|
|
const Vector3f &get_field(uint8_t i) const { return _state[i].field; }
|
|
|
|
const Vector3f &get_field(void) const { return get_field(get_primary()); }
|
|
|
|
|
|
|
|
// compass calibrator interface
|
2019-03-25 06:06:34 -03:00
|
|
|
void cal_update();
|
2016-03-10 20:41:18 -04:00
|
|
|
|
2018-01-05 06:08:04 -04:00
|
|
|
// per-motor calibration access
|
|
|
|
void per_motor_calibration_start(void) {
|
|
|
|
_per_motor.calibration_start();
|
|
|
|
}
|
|
|
|
void per_motor_calibration_update(void) {
|
|
|
|
_per_motor.calibration_update();
|
|
|
|
}
|
|
|
|
void per_motor_calibration_end(void) {
|
|
|
|
_per_motor.calibration_end();
|
|
|
|
}
|
|
|
|
|
2016-10-25 02:16:11 -03:00
|
|
|
void start_calibration_all(bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot = false);
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
void cancel_calibration_all();
|
|
|
|
|
2018-06-25 02:26:53 -03:00
|
|
|
bool compass_cal_requires_reboot() const { return _cal_complete_requires_reboot; }
|
2016-03-10 20:41:18 -04:00
|
|
|
bool is_calibrating() const;
|
|
|
|
|
2019-03-25 09:42:34 -03:00
|
|
|
// indicate which bit in LOG_BITMASK indicates we should log compass readings
|
|
|
|
void set_log_bit(uint32_t log_bit) { _log_bit = log_bit; }
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
/*
|
|
|
|
handle an incoming MAG_CAL command
|
|
|
|
*/
|
2017-07-16 21:45:40 -03:00
|
|
|
MAV_RESULT handle_mag_cal_command(const mavlink_command_long_t &packet);
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
void send_mag_cal_progress(mavlink_channel_t chan);
|
|
|
|
void send_mag_cal_report(mavlink_channel_t chan);
|
|
|
|
|
|
|
|
// check if the compasses are pointing in the same direction
|
|
|
|
bool consistent() const;
|
|
|
|
|
|
|
|
/// Return the health of a compass
|
|
|
|
bool healthy(uint8_t i) const { return _state[i].healthy; }
|
|
|
|
bool healthy(void) const { return healthy(get_primary()); }
|
|
|
|
uint8_t get_healthy_mask() const;
|
|
|
|
|
|
|
|
/// Returns the current offset values
|
|
|
|
///
|
|
|
|
/// @returns The current compass offsets in milligauss.
|
|
|
|
///
|
|
|
|
const Vector3f &get_offsets(uint8_t i) const { return _state[i].offset; }
|
|
|
|
const Vector3f &get_offsets(void) const { return get_offsets(get_primary()); }
|
|
|
|
|
2018-01-05 06:08:04 -04:00
|
|
|
const Vector3f &get_diagonals(uint8_t i) const { return _state[i].diagonals; }
|
|
|
|
const Vector3f &get_diagonals(void) const { return get_diagonals(get_primary()); }
|
|
|
|
|
|
|
|
const Vector3f &get_offdiagonals(uint8_t i) const { return _state[i].offdiagonals; }
|
|
|
|
const Vector3f &get_offdiagonals(void) const { return get_offdiagonals(get_primary()); }
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
/// Sets the initial location used to get declination
|
|
|
|
///
|
|
|
|
/// @param latitude GPS Latitude.
|
|
|
|
/// @param longitude GPS Longitude.
|
|
|
|
///
|
|
|
|
void set_initial_location(int32_t latitude, int32_t longitude);
|
|
|
|
|
|
|
|
// learn offsets accessor
|
2018-10-19 02:07:53 -03:00
|
|
|
bool learn_offsets_enabled() const { return _learn == LEARN_INFLIGHT; }
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
/// return true if the compass should be used for yaw calculations
|
|
|
|
bool use_for_yaw(uint8_t i) const;
|
|
|
|
bool use_for_yaw(void) const;
|
|
|
|
|
2017-08-18 05:58:08 -03:00
|
|
|
void set_use_for_yaw(uint8_t i, bool use) {
|
|
|
|
_state[i].use_for_yaw.set(use);
|
|
|
|
}
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
/// Sets the local magnetic field declination.
|
|
|
|
///
|
|
|
|
/// @param radians Local field declination.
|
|
|
|
/// @param save_to_eeprom true to save to eeprom (false saves only to memory)
|
|
|
|
///
|
|
|
|
void set_declination(float radians, bool save_to_eeprom = true);
|
|
|
|
float get_declination() const;
|
|
|
|
|
|
|
|
// set overall board orientation
|
2018-03-08 22:26:18 -04:00
|
|
|
void set_board_orientation(enum Rotation orientation, Matrix3f* custom_rotation = nullptr) {
|
2016-03-10 20:41:18 -04:00
|
|
|
_board_orientation = orientation;
|
2018-03-08 22:26:18 -04:00
|
|
|
_custom_rotation = custom_rotation;
|
2016-03-10 20:41:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the motor compensation type
|
|
|
|
///
|
|
|
|
/// @param comp_type 0 = disabled, 1 = enabled use throttle, 2 = enabled use current
|
|
|
|
///
|
|
|
|
void motor_compensation_type(const uint8_t comp_type);
|
|
|
|
|
|
|
|
/// get the motor compensation value.
|
|
|
|
uint8_t get_motor_compensation_type() const {
|
|
|
|
return _motor_comp_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the motor compensation factor x/y/z values.
|
|
|
|
///
|
|
|
|
/// @param i instance of compass
|
|
|
|
/// @param offsets Offsets multiplied by the throttle value and added to the raw mag_ values.
|
|
|
|
///
|
|
|
|
void set_motor_compensation(uint8_t i, const Vector3f &motor_comp_factor);
|
|
|
|
|
|
|
|
/// get motor compensation factors as a vector
|
|
|
|
const Vector3f& get_motor_compensation(uint8_t i) const { return _state[i].motor_compensation; }
|
|
|
|
const Vector3f& get_motor_compensation(void) const { return get_motor_compensation(get_primary()); }
|
|
|
|
|
|
|
|
/// Saves the current motor compensation x/y/z values.
|
|
|
|
///
|
|
|
|
/// This should be invoked periodically to save the offset values calculated by the motor compensation auto learning
|
|
|
|
///
|
|
|
|
void save_motor_compensation();
|
|
|
|
|
|
|
|
/// Returns the current motor compensation offset values
|
|
|
|
///
|
|
|
|
/// @returns The current compass offsets in milligauss.
|
|
|
|
///
|
|
|
|
const Vector3f &get_motor_offsets(uint8_t i) const { return _state[i].motor_offset; }
|
|
|
|
const Vector3f &get_motor_offsets(void) const { return get_motor_offsets(get_primary()); }
|
|
|
|
|
|
|
|
/// Set the throttle as a percentage from 0.0 to 1.0
|
|
|
|
/// @param thr_pct throttle expressed as a percentage from 0 to 1.0
|
|
|
|
void set_throttle(float thr_pct) {
|
|
|
|
if (_motor_comp_type == AP_COMPASS_MOT_COMP_THROTTLE) {
|
2018-03-01 17:42:31 -04:00
|
|
|
_thr = thr_pct;
|
2016-03-10 20:41:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 06:08:04 -04:00
|
|
|
/// Set the battery voltage for per-motor compensation
|
|
|
|
void set_voltage(float voltage) {
|
|
|
|
_per_motor.set_voltage(voltage);
|
|
|
|
}
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
/// Returns True if the compasses have been configured (i.e. offsets saved)
|
|
|
|
///
|
|
|
|
/// @returns True if compass has been configured
|
|
|
|
///
|
|
|
|
bool configured(uint8_t i);
|
|
|
|
bool configured(void);
|
|
|
|
|
|
|
|
/// Returns the instance of the primary compass
|
|
|
|
///
|
|
|
|
/// @returns the instance number of the primary compass
|
|
|
|
///
|
|
|
|
uint8_t get_primary(void) const { return _primary; }
|
|
|
|
|
|
|
|
// HIL methods
|
|
|
|
void setHIL(uint8_t instance, float roll, float pitch, float yaw);
|
2016-05-04 04:11:02 -03:00
|
|
|
void setHIL(uint8_t instance, const Vector3f &mag, uint32_t last_update_usec);
|
2016-03-10 20:41:18 -04:00
|
|
|
const Vector3f& getHIL(uint8_t instance) const;
|
|
|
|
void _setup_earth_field();
|
|
|
|
|
|
|
|
// enable HIL mode
|
|
|
|
void set_hil_mode(void) { _hil_mode = true; }
|
|
|
|
|
|
|
|
// return last update time in microseconds
|
|
|
|
uint32_t last_update_usec(void) const { return _state[get_primary()].last_update_usec; }
|
|
|
|
uint32_t last_update_usec(uint8_t i) const { return _state[i].last_update_usec; }
|
|
|
|
|
2017-06-21 14:39:07 -03:00
|
|
|
uint32_t last_update_ms(void) const { return _state[get_primary()].last_update_ms; }
|
|
|
|
uint32_t last_update_ms(uint8_t i) const { return _state[i].last_update_ms; }
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
// HIL variables
|
|
|
|
struct {
|
|
|
|
Vector3f Bearth;
|
|
|
|
float last_declination;
|
|
|
|
bool healthy[COMPASS_MAX_INSTANCES];
|
|
|
|
Vector3f field[COMPASS_MAX_INSTANCES];
|
|
|
|
} _hil;
|
|
|
|
|
2016-04-28 05:51:06 -03:00
|
|
|
enum LearnType {
|
|
|
|
LEARN_NONE=0,
|
|
|
|
LEARN_INTERNAL=1,
|
2017-08-18 05:58:08 -03:00
|
|
|
LEARN_EKF=2,
|
|
|
|
LEARN_INFLIGHT=3
|
2016-04-28 05:51:06 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// return the chosen learning type
|
|
|
|
enum LearnType get_learn_type(void) const {
|
|
|
|
return (enum LearnType)_learn.get();
|
|
|
|
}
|
2017-04-03 19:38:14 -03:00
|
|
|
|
2017-08-18 05:58:08 -03:00
|
|
|
// set the learning type
|
|
|
|
void set_learn_type(enum LearnType type, bool save) {
|
|
|
|
if (save) {
|
|
|
|
_learn.set_and_save((int8_t)type);
|
|
|
|
} else {
|
|
|
|
_learn.set((int8_t)type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-03 19:38:14 -03:00
|
|
|
// return maximum allowed compass offsets
|
|
|
|
uint16_t get_offsets_max(void) const {
|
|
|
|
return (uint16_t)_offset_max.get();
|
|
|
|
}
|
2017-06-21 14:39:07 -03:00
|
|
|
|
2018-03-12 04:59:32 -03:00
|
|
|
uint8_t get_filter_range() const { return uint8_t(_filter_range.get()); }
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
private:
|
2018-03-29 01:13:55 -03:00
|
|
|
static Compass *_singleton;
|
2016-03-10 20:41:18 -04:00
|
|
|
/// Register a new compas driver, allocating an instance number
|
|
|
|
///
|
|
|
|
/// @return number of compass instances
|
|
|
|
uint8_t register_compass(void);
|
|
|
|
|
|
|
|
// load backend drivers
|
2018-08-06 20:08:09 -03:00
|
|
|
bool _add_backend(AP_Compass_Backend *backend);
|
2018-07-13 06:56:24 -03:00
|
|
|
void _probe_external_i2c_compasses(void);
|
2016-03-10 20:41:18 -04:00
|
|
|
void _detect_backends(void);
|
|
|
|
|
2016-10-25 02:16:11 -03:00
|
|
|
// compass cal
|
|
|
|
bool _accept_calibration(uint8_t i);
|
|
|
|
bool _accept_calibration_mask(uint8_t mask);
|
|
|
|
void _cancel_calibration(uint8_t i);
|
|
|
|
void _cancel_calibration_mask(uint8_t mask);
|
|
|
|
uint8_t _get_cal_mask() const;
|
|
|
|
bool _start_calibration(uint8_t i, bool retry=false, float delay_sec=0.0f);
|
|
|
|
bool _start_calibration_mask(uint8_t mask, bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot=false);
|
|
|
|
bool _auto_reboot() { return _compass_cal_autoreboot; }
|
|
|
|
|
2018-07-13 06:56:24 -03:00
|
|
|
// see if we already have probed a i2c driver by bus number and address
|
|
|
|
bool _have_i2c_driver(uint8_t bus_num, uint8_t address) const;
|
2016-10-25 02:16:11 -03:00
|
|
|
|
|
|
|
//keep track of which calibrators have been saved
|
|
|
|
bool _cal_saved[COMPASS_MAX_INSTANCES];
|
|
|
|
bool _cal_autosave;
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
//autoreboot after compass calibration
|
|
|
|
bool _compass_cal_autoreboot;
|
|
|
|
bool _cal_complete_requires_reboot;
|
|
|
|
bool _cal_has_run;
|
|
|
|
|
2017-06-18 04:26:25 -03:00
|
|
|
// enum of drivers for COMPASS_TYPEMASK
|
|
|
|
enum DriverType {
|
2019-05-29 07:57:28 -03:00
|
|
|
DRIVER_HMC5843 =0,
|
2017-06-18 04:26:25 -03:00
|
|
|
DRIVER_LSM303D =1,
|
|
|
|
DRIVER_AK8963 =2,
|
|
|
|
DRIVER_BMM150 =3,
|
|
|
|
DRIVER_LSM9DS1 =4,
|
|
|
|
DRIVER_LIS3MDL =5,
|
|
|
|
DRIVER_AK09916 =6,
|
|
|
|
DRIVER_IST8310 =7,
|
|
|
|
DRIVER_ICM20948 =8,
|
|
|
|
DRIVER_MMC3416 =9,
|
|
|
|
DRIVER_UAVCAN =11,
|
|
|
|
DRIVER_QMC5883 =12,
|
|
|
|
DRIVER_SITL =13,
|
2018-02-02 05:25:24 -04:00
|
|
|
DRIVER_MAG3110 =14,
|
2018-08-14 15:01:05 -03:00
|
|
|
DRIVER_IST8308 = 15,
|
2019-02-01 11:13:28 -04:00
|
|
|
DRIVER_RM3100 =16,
|
2017-06-18 04:26:25 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
bool _driver_enabled(enum DriverType driver_type);
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
// backend objects
|
|
|
|
AP_Compass_Backend *_backends[COMPASS_MAX_BACKEND];
|
|
|
|
uint8_t _backend_count;
|
|
|
|
|
2019-03-24 00:24:56 -03:00
|
|
|
// whether to enable the compass drivers at all
|
|
|
|
AP_Int8 _enabled;
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
// number of registered compasses.
|
|
|
|
uint8_t _compass_count;
|
|
|
|
|
|
|
|
// settable parameters
|
|
|
|
AP_Int8 _learn;
|
|
|
|
|
|
|
|
// board orientation from AHRS
|
2018-03-28 20:57:17 -03:00
|
|
|
enum Rotation _board_orientation = ROTATION_NONE;
|
2018-03-08 22:26:18 -04:00
|
|
|
Matrix3f* _custom_rotation;
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
// primary instance
|
|
|
|
AP_Int8 _primary;
|
|
|
|
|
|
|
|
// declination in radians
|
|
|
|
AP_Float _declination;
|
|
|
|
|
|
|
|
// enable automatic declination code
|
|
|
|
AP_Int8 _auto_declination;
|
|
|
|
|
|
|
|
// first-time-around flag used by offset nulling
|
|
|
|
bool _null_init_done;
|
|
|
|
|
2019-03-25 09:42:34 -03:00
|
|
|
// stores which bit is used to indicate we should log compass readings
|
|
|
|
uint32_t _log_bit = -1;
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
// used by offset correction
|
|
|
|
static const uint8_t _mag_history_size = 20;
|
|
|
|
|
|
|
|
// motor compensation type
|
|
|
|
// 0 = disabled, 1 = enabled for throttle, 2 = enabled for current
|
|
|
|
AP_Int8 _motor_comp_type;
|
|
|
|
|
2018-07-16 05:21:53 -03:00
|
|
|
// automatic compass orientation on calibration
|
|
|
|
AP_Int8 _rotate_auto;
|
|
|
|
|
2018-03-01 17:42:31 -04:00
|
|
|
// throttle expressed as a percentage from 0 ~ 1.0, used for motor compensation
|
|
|
|
float _thr;
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
struct mag_state {
|
|
|
|
AP_Int8 external;
|
|
|
|
bool healthy;
|
|
|
|
AP_Int8 orientation;
|
|
|
|
AP_Vector3f offset;
|
|
|
|
AP_Vector3f diagonals;
|
|
|
|
AP_Vector3f offdiagonals;
|
|
|
|
|
|
|
|
// device id detected at init.
|
|
|
|
// saved to eeprom when offsets are saved allowing ram &
|
|
|
|
// eeprom values to be compared as consistency check
|
|
|
|
AP_Int32 dev_id;
|
2018-07-10 15:28:32 -03:00
|
|
|
AP_Int32 expected_dev_id;
|
2018-03-19 20:58:40 -03:00
|
|
|
int32_t detected_dev_id;
|
2016-03-10 20:41:18 -04:00
|
|
|
|
|
|
|
AP_Int8 use_for_yaw;
|
|
|
|
|
|
|
|
uint8_t mag_history_index;
|
|
|
|
Vector3i mag_history[_mag_history_size];
|
|
|
|
|
|
|
|
// factors multiplied by throttle and added to compass outputs
|
|
|
|
AP_Vector3f motor_compensation;
|
|
|
|
|
|
|
|
// latest compensation added to compass
|
|
|
|
Vector3f motor_offset;
|
|
|
|
|
|
|
|
// corrected magnetic field strength
|
|
|
|
Vector3f field;
|
|
|
|
|
|
|
|
// when we last got data
|
|
|
|
uint32_t last_update_ms;
|
|
|
|
uint32_t last_update_usec;
|
2016-11-06 06:04:48 -04:00
|
|
|
|
|
|
|
// board specific orientation
|
|
|
|
enum Rotation rotation;
|
2018-10-16 05:59:51 -03:00
|
|
|
|
|
|
|
// accumulated samples, protected by _sem, used by AP_Compass_Backend
|
|
|
|
Vector3f accum;
|
|
|
|
uint32_t accum_count;
|
2016-03-10 20:41:18 -04:00
|
|
|
} _state[COMPASS_MAX_INSTANCES];
|
|
|
|
|
2017-04-03 19:38:14 -03:00
|
|
|
AP_Int16 _offset_max;
|
2017-06-21 14:39:07 -03:00
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
CompassCalibrator _calibrator[COMPASS_MAX_INSTANCES];
|
|
|
|
|
2018-01-05 06:08:04 -04:00
|
|
|
// per-motor compass compensation
|
|
|
|
Compass_PerMotor _per_motor{*this};
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
// if we want HIL only
|
|
|
|
bool _hil_mode:1;
|
|
|
|
|
|
|
|
AP_Float _calibration_threshold;
|
2017-06-18 04:26:25 -03:00
|
|
|
|
|
|
|
// mask of driver types to not load. Bit positions match DEVTYPE_ in backend
|
|
|
|
AP_Int32 _driver_type_mask;
|
2018-03-12 04:59:32 -03:00
|
|
|
|
|
|
|
AP_Int8 _filter_range;
|
2018-10-19 02:07:53 -03:00
|
|
|
|
|
|
|
CompassLearn *learn;
|
|
|
|
bool learn_allocated;
|
2016-03-10 20:41:18 -04:00
|
|
|
};
|
2018-03-29 01:13:55 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
Compass &compass();
|
|
|
|
};
|