2011-12-28 05:31:36 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-02-14 00:27:07 -04:00
|
|
|
#ifndef Compass_h
|
|
|
|
#define Compass_h
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2015-03-18 20:42:30 -03:00
|
|
|
#include "CompassCalibrator.h"
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Declination/AP_Declination.h> // ArduPilot Mega Declination Helper Library
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-11-15 21:58:23 -04:00
|
|
|
#include "AP_Compass_Backend.h"
|
|
|
|
|
2011-06-28 13:30:42 -03:00
|
|
|
// compass product id
|
2014-11-21 12:26:58 -04:00
|
|
|
#define AP_COMPASS_TYPE_UNKNOWN 0x00
|
|
|
|
#define AP_COMPASS_TYPE_HIL 0x01
|
|
|
|
#define AP_COMPASS_TYPE_HMC5843 0x02
|
|
|
|
#define AP_COMPASS_TYPE_HMC5883L 0x03
|
|
|
|
#define AP_COMPASS_TYPE_PX4 0x04
|
|
|
|
#define AP_COMPASS_TYPE_VRBRAIN 0x05
|
|
|
|
#define AP_COMPASS_TYPE_AK8963_MPU9250 0x06
|
2015-07-10 01:05:21 -03:00
|
|
|
#define AP_COMPASS_TYPE_AK8963_I2C 0x07
|
2015-08-17 21:09:52 -03:00
|
|
|
#define AP_COMPASS_TYPE_LSM303D 0x08
|
2011-06-28 13:30:42 -03:00
|
|
|
|
2013-03-03 10:02:12 -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
|
|
|
|
|
2015-03-13 17:57:04 -03:00
|
|
|
// setup default mag orientation for some board types
|
2015-11-03 09:46:29 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
2015-08-17 21:09:52 -03:00
|
|
|
# define MAG_BOARD_ORIENTATION ROTATION_ROLL_180
|
2015-09-14 10:49:15 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
|
|
|
|
# define MAG_BOARD_ORIENTATION ROTATION_YAW_90
|
2013-05-01 23:27:35 -03:00
|
|
|
#else
|
2015-03-13 17:57:04 -03:00
|
|
|
# define MAG_BOARD_ORIENTATION ROTATION_NONE
|
2013-05-01 23:27:35 -03:00
|
|
|
#endif
|
|
|
|
|
2013-12-09 01:05:57 -04:00
|
|
|
/**
|
|
|
|
maximum number of compass instances available on this platform. If more
|
2015-10-14 12:59:05 -03:00
|
|
|
than 1 then redundant sensors may be available
|
2013-12-09 01:05:57 -04:00
|
|
|
*/
|
2014-07-03 23:07:47 -03:00
|
|
|
#define COMPASS_MAX_INSTANCES 3
|
2015-10-14 12:59:05 -03:00
|
|
|
#define COMPASS_MAX_BACKEND 3
|
2013-12-09 01:05:57 -04:00
|
|
|
|
2015-08-27 23:44:33 -03:00
|
|
|
//MAXIMUM COMPASS REPORTS
|
|
|
|
#define MAX_CAL_REPORTS 10
|
|
|
|
#define CONTINUOUS_REPORTS 0
|
2015-08-14 21:27:23 -03:00
|
|
|
#define AP_COMPASS_MAX_XYZ_ANG_DIFF radians(50.0f)
|
|
|
|
#define AP_COMPASS_MAX_XY_ANG_DIFF radians(30.0f)
|
|
|
|
#define AP_COMPASS_MAX_XY_LENGTH_DIFF 100.0f
|
2015-08-27 23:44:33 -03:00
|
|
|
|
2011-02-14 00:27:07 -04:00
|
|
|
class Compass
|
|
|
|
{
|
2015-01-19 12:58:26 -04:00
|
|
|
friend class AP_Compass_Backend;
|
2011-02-14 00:27:07 -04:00
|
|
|
public:
|
2012-08-21 23:19:51 -03:00
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
Compass();
|
|
|
|
|
|
|
|
/// Initialize the compass device.
|
|
|
|
///
|
|
|
|
/// @returns True if the compass was initialized OK, false if it was not
|
|
|
|
/// found or is not functioning.
|
|
|
|
///
|
2014-11-15 21:58:23 -04:00
|
|
|
bool init();
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
/// Read the compass and update the mag_ variables.
|
|
|
|
///
|
2014-11-15 21:58:23 -04:00
|
|
|
bool read();
|
2013-12-08 23:09:34 -04:00
|
|
|
|
2012-08-26 00:42:00 -03:00
|
|
|
/// use spare CPU cycles to accumulate values from the compass if
|
2014-11-15 21:58:23 -04:00
|
|
|
/// possible (this method should also be implemented in the backends)
|
|
|
|
void accumulate();
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
/// Calculate the tilt-compensated heading_ variables.
|
|
|
|
///
|
|
|
|
/// @param dcm_matrix The current orientation rotation matrix
|
2012-06-20 06:30:30 -03:00
|
|
|
///
|
|
|
|
/// @returns heading in radians
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
2013-05-08 20:22:00 -03:00
|
|
|
float calculate_heading(const Matrix3f &dcm_matrix) const;
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2014-10-14 19:16:31 -03:00
|
|
|
/// Sets offset x/y/z values.
|
|
|
|
///
|
|
|
|
/// @param i compass instance
|
2015-09-29 16:51:21 -03:00
|
|
|
/// @param offsets Offsets to the raw mag_ values in milligauss.
|
2014-10-14 19:16:31 -03:00
|
|
|
///
|
|
|
|
void set_offsets(uint8_t i, const Vector3f &offsets);
|
|
|
|
|
2014-07-09 05:09:02 -03:00
|
|
|
/// Sets and saves the compass offset x/y/z values.
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
2014-07-09 05:09:02 -03:00
|
|
|
/// @param i compass instance
|
2015-09-29 16:51:21 -03:00
|
|
|
/// @param offsets Offsets to the raw mag_ values in milligauss.
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
2014-07-09 05:09:02 -03:00
|
|
|
void set_and_save_offsets(uint8_t i, const Vector3f &offsets);
|
2015-03-18 20:18:47 -03:00
|
|
|
void set_and_save_diagonals(uint8_t i, const Vector3f &diagonals);
|
|
|
|
void set_and_save_offdiagonals(uint8_t i, const Vector3f &diagonals);
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2014-07-09 05:07:30 -03:00
|
|
|
/// Saves the current offset x/y/z values for one or all compasses
|
|
|
|
///
|
|
|
|
/// @param i compass instance
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
|
|
|
/// This should be invoked periodically to save the offset values maintained by
|
2014-02-15 22:21:06 -04:00
|
|
|
/// ::learn_offsets.
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
2014-07-09 05:07:30 -03:00
|
|
|
void save_offsets(uint8_t i);
|
|
|
|
void save_offsets(void);
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2013-12-09 01:05:57 -04:00
|
|
|
// return the number of compass instances
|
2014-11-15 21:58:23 -04:00
|
|
|
uint8_t get_count(void) const { return _compass_count; }
|
2013-12-09 01:05:57 -04:00
|
|
|
|
2015-09-29 16:51:21 -03:00
|
|
|
/// Return the current field as a Vector3f in milligauss
|
2015-09-29 16:32:53 -03:00
|
|
|
const Vector3f &get_field(uint8_t i) const { return _state[i].field; }
|
2014-07-22 04:30:33 -03:00
|
|
|
const Vector3f &get_field(void) const { return get_field(get_primary()); }
|
2013-12-08 23:09:34 -04:00
|
|
|
|
2015-03-18 19:14:38 -03:00
|
|
|
// raw/unfiltered measurement interface
|
|
|
|
uint32_t raw_meas_time_us(uint8_t i) const { return _state[i].raw_meas_time_us; }
|
|
|
|
uint32_t raw_meas_time_us() const { return _state[get_primary()].raw_meas_time_us; }
|
|
|
|
uint32_t unfiltered_meas_time_us(uint8_t i) const { return _state[i].raw_meas_time_us; }
|
|
|
|
uint32_t unfiltered_meas_time_us() const { return _state[get_primary()].raw_meas_time_us; }
|
|
|
|
|
|
|
|
bool has_raw_field(uint8_t i) const { return _state[i].has_raw_field; }
|
|
|
|
bool has_raw_field() const { return has_raw_field(get_primary()); }
|
|
|
|
|
|
|
|
bool has_unfiltered_field(uint8_t i) const { return _state[i].has_unfiltered_field; }
|
|
|
|
bool has_unfiltered_field() const { return has_unfiltered_field(get_primary()); }
|
|
|
|
|
|
|
|
const Vector3f &get_raw_field(uint8_t i) const { return _state[i].raw_field; }
|
2015-09-04 14:27:23 -03:00
|
|
|
const Vector3f &get_raw_field(void) const { return get_raw_field(get_primary()); }
|
2015-03-18 19:14:38 -03:00
|
|
|
|
|
|
|
const Vector3f &get_unfiltered_field(uint8_t i) const { return _state[i].unfiltered_field; }
|
|
|
|
const Vector3f &get_unfiltered_field(void) const { return get_unfiltered_field(get_primary()); }
|
|
|
|
|
2015-03-18 20:42:30 -03:00
|
|
|
// compass calibrator interface
|
|
|
|
void compass_cal_update();
|
|
|
|
|
2015-08-27 23:44:33 -03:00
|
|
|
bool start_calibration(uint8_t i, bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot = false);
|
|
|
|
bool start_calibration_all(bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot = false);
|
|
|
|
bool start_calibration_mask(uint8_t mask, bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot=false);
|
2015-03-18 20:42:30 -03:00
|
|
|
|
|
|
|
void cancel_calibration(uint8_t i);
|
|
|
|
void cancel_calibration_all();
|
|
|
|
void cancel_calibration_mask(uint8_t mask);
|
|
|
|
|
|
|
|
bool accept_calibration(uint8_t i);
|
|
|
|
bool accept_calibration_all();
|
|
|
|
bool accept_calibration_mask(uint8_t mask);
|
|
|
|
|
2015-08-27 23:44:33 -03:00
|
|
|
bool compass_cal_requires_reboot() { return _cal_complete_requires_reboot; }
|
|
|
|
bool auto_reboot() { return _compass_cal_autoreboot; }
|
2015-03-18 20:42:30 -03:00
|
|
|
uint8_t get_cal_mask() const;
|
|
|
|
bool is_calibrating() const;
|
|
|
|
|
2015-08-23 07:23:38 -03:00
|
|
|
/*
|
|
|
|
handle an incoming MAG_CAL command
|
|
|
|
*/
|
|
|
|
uint8_t handle_mag_cal_command(const mavlink_command_long_t &packet);
|
|
|
|
|
2015-03-18 20:42:30 -03:00
|
|
|
void send_mag_cal_progress(mavlink_channel_t chan);
|
|
|
|
void send_mag_cal_report(mavlink_channel_t chan);
|
|
|
|
|
2015-09-15 03:54:26 -03:00
|
|
|
// check if the compasses are pointing in the same direction
|
|
|
|
bool consistent() const;
|
2015-08-14 21:27:23 -03:00
|
|
|
|
2013-12-09 02:46:41 -04:00
|
|
|
/// Return the health of a compass
|
2015-02-23 19:17:44 -04:00
|
|
|
bool healthy(uint8_t i) const { return _state[i].healthy; }
|
2014-07-22 04:30:33 -03:00
|
|
|
bool healthy(void) const { return healthy(get_primary()); }
|
2015-03-18 20:42:30 -03:00
|
|
|
uint8_t get_healthy_mask() const;
|
2013-12-09 02:46:41 -04:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
/// Returns the current offset values
|
|
|
|
///
|
2015-09-29 16:51:21 -03:00
|
|
|
/// @returns The current compass offsets in milligauss.
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
2015-09-29 16:32:53 -03:00
|
|
|
const Vector3f &get_offsets(uint8_t i) const { return _state[i].offset; }
|
2014-07-22 04:30:33 -03:00
|
|
|
const Vector3f &get_offsets(void) const { return get_offsets(get_primary()); }
|
2012-08-21 23:19:51 -03: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);
|
|
|
|
|
|
|
|
/// Program new offset values.
|
|
|
|
///
|
2014-07-09 05:09:02 -03:00
|
|
|
/// @param i compass instance
|
2015-09-29 16:51:21 -03:00
|
|
|
/// @param x Offset to the raw mag_x value in milligauss.
|
|
|
|
/// @param y Offset to the raw mag_y value in milligauss.
|
|
|
|
/// @param z Offset to the raw mag_z value in milligauss.
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
2014-07-09 05:09:02 -03:00
|
|
|
void set_and_save_offsets(uint8_t i, int x, int y, int z) {
|
|
|
|
set_and_save_offsets(i, Vector3f(x, y, z));
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
|
|
|
|
2014-07-09 05:09:32 -03:00
|
|
|
// learn offsets accessor
|
|
|
|
bool learn_offsets_enabled() const { return _learn; }
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
/// Perform automatic offset updates
|
|
|
|
///
|
2014-02-15 22:21:06 -04:00
|
|
|
void learn_offsets(void);
|
2011-02-14 00:27:07 -04:00
|
|
|
|
2012-02-24 23:11:07 -04:00
|
|
|
/// return true if the compass should be used for yaw calculations
|
2014-09-18 09:56:13 -03:00
|
|
|
bool use_for_yaw(uint8_t i) const;
|
|
|
|
bool use_for_yaw(void) const;
|
2012-01-12 17:43:39 -04:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
/// Sets the local magnetic field declination.
|
|
|
|
///
|
|
|
|
/// @param radians Local field declination.
|
2013-04-15 09:50:44 -03:00
|
|
|
/// @param save_to_eeprom true to save to eeprom (false saves only to memory)
|
2012-08-21 23:19:51 -03:00
|
|
|
///
|
2013-04-15 09:50:44 -03:00
|
|
|
void set_declination(float radians, bool save_to_eeprom = true);
|
2013-05-08 20:22:00 -03:00
|
|
|
float get_declination() const;
|
2011-02-14 00:27:07 -04:00
|
|
|
|
2013-01-13 01:02:49 -04:00
|
|
|
// set overall board orientation
|
|
|
|
void set_board_orientation(enum Rotation orientation) {
|
|
|
|
_board_orientation = orientation;
|
|
|
|
}
|
|
|
|
|
2013-03-03 10:02:12 -04:00
|
|
|
/// Set the motor compensation type
|
|
|
|
///
|
|
|
|
/// @param comp_type 0 = disabled, 1 = enabled use throttle, 2 = enabled use current
|
|
|
|
///
|
2015-02-23 19:17:44 -04:00
|
|
|
void motor_compensation_type(const uint8_t comp_type);
|
2013-03-03 10:02:12 -04:00
|
|
|
|
|
|
|
/// get the motor compensation value.
|
2015-02-23 19:17:44 -04:00
|
|
|
uint8_t get_motor_compensation_type() const {
|
2013-03-03 10:02:12 -04:00
|
|
|
return _motor_comp_type;
|
|
|
|
}
|
|
|
|
|
2013-02-27 03:57:04 -04:00
|
|
|
/// Set the motor compensation factor x/y/z values.
|
|
|
|
///
|
2014-07-22 04:29:43 -03:00
|
|
|
/// @param i instance of compass
|
2013-02-27 03:57:04 -04:00
|
|
|
/// @param offsets Offsets multiplied by the throttle value and added to the raw mag_ values.
|
|
|
|
///
|
2014-07-22 04:29:43 -03:00
|
|
|
void set_motor_compensation(uint8_t i, const Vector3f &motor_comp_factor);
|
2013-02-27 03:57:04 -04:00
|
|
|
|
2013-03-02 04:53:03 -04:00
|
|
|
/// get motor compensation factors as a vector
|
2015-02-23 19:17:44 -04:00
|
|
|
const Vector3f& get_motor_compensation(uint8_t i) const { return _state[i].motor_compensation; }
|
2014-07-22 04:30:33 -03:00
|
|
|
const Vector3f& get_motor_compensation(void) const { return get_motor_compensation(get_primary()); }
|
2013-02-27 03:57:04 -04:00
|
|
|
|
|
|
|
/// 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
|
|
|
|
///
|
2013-03-01 11:00:37 -04:00
|
|
|
void save_motor_compensation();
|
2013-02-27 03:57:04 -04:00
|
|
|
|
|
|
|
/// Returns the current motor compensation offset values
|
|
|
|
///
|
2015-09-29 16:51:21 -03:00
|
|
|
/// @returns The current compass offsets in milligauss.
|
2013-02-27 03:57:04 -04:00
|
|
|
///
|
2015-02-23 19:17:44 -04:00
|
|
|
const Vector3f &get_motor_offsets(uint8_t i) const { return _state[i].motor_offset; }
|
2014-07-22 04:30:33 -03:00
|
|
|
const Vector3f &get_motor_offsets(void) const { return get_motor_offsets(get_primary()); }
|
2013-02-27 03:57:04 -04:00
|
|
|
|
|
|
|
/// 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) {
|
2015-02-23 19:17:44 -04:00
|
|
|
if (_motor_comp_type == AP_COMPASS_MOT_COMP_THROTTLE) {
|
2013-03-03 10:02:12 -04:00
|
|
|
_thr_or_curr = thr_pct;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the current used by system in amps
|
|
|
|
/// @param amps current flowing to the motors expressed in amps
|
|
|
|
void set_current(float amps) {
|
2015-02-23 19:17:44 -04:00
|
|
|
if (_motor_comp_type == AP_COMPASS_MOT_COMP_CURRENT) {
|
2013-03-03 10:02:12 -04:00
|
|
|
_thr_or_curr = amps;
|
|
|
|
}
|
2013-02-27 03:57:04 -04:00
|
|
|
}
|
|
|
|
|
2014-07-07 09:24:18 -03: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);
|
|
|
|
|
2014-07-22 04:30:33 -03:00
|
|
|
/// Returns the instance of the primary compass
|
|
|
|
///
|
|
|
|
/// @returns the instance number of the primary compass
|
|
|
|
///
|
2015-02-23 19:17:44 -04:00
|
|
|
uint8_t get_primary(void) const { return _primary; }
|
2014-11-15 21:58:23 -04:00
|
|
|
|
|
|
|
// HIL methods
|
2015-05-15 01:04:00 -03:00
|
|
|
void setHIL(uint8_t instance, float roll, float pitch, float yaw);
|
|
|
|
void setHIL(uint8_t instance, const Vector3f &mag);
|
|
|
|
const Vector3f& getHIL(uint8_t instance) const;
|
2014-11-15 21:58:23 -04:00
|
|
|
void _setup_earth_field();
|
|
|
|
|
2015-03-13 08:32:35 -03:00
|
|
|
// enable HIL mode
|
|
|
|
void set_hil_mode(void) { _hil_mode = true; }
|
|
|
|
|
2015-03-13 22:31:23 -03:00
|
|
|
// return last update time in microseconds
|
2015-07-16 05:56:12 -03:00
|
|
|
uint32_t last_update_usec(void) const { return _state[get_primary()].last_update_usec; }
|
2015-11-08 22:40:37 -04:00
|
|
|
uint32_t last_update_usec(uint8_t i) const { return _state[i].last_update_usec; }
|
2014-07-22 04:30:33 -03:00
|
|
|
|
2013-02-27 03:57:04 -04:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// HIL variables
|
|
|
|
struct {
|
|
|
|
Vector3f Bearth;
|
|
|
|
float last_declination;
|
2015-05-15 01:04:00 -03:00
|
|
|
bool healthy[COMPASS_MAX_INSTANCES];
|
|
|
|
Vector3f field[COMPASS_MAX_INSTANCES];
|
2015-02-23 19:17:44 -04:00
|
|
|
} _hil;
|
2013-04-16 06:47:39 -03:00
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
private:
|
|
|
|
/// Register a new compas driver, allocating an instance number
|
2014-11-15 21:58:23 -04:00
|
|
|
///
|
2015-02-23 19:17:44 -04:00
|
|
|
/// @return number of compass instances
|
|
|
|
uint8_t register_compass(void);
|
|
|
|
|
|
|
|
// load backend drivers
|
2015-08-05 17:02:32 -03:00
|
|
|
void _add_backend(AP_Compass_Backend *backend);
|
2015-02-23 19:17:44 -04:00
|
|
|
void _detect_backends(void);
|
2014-11-15 21:58:23 -04:00
|
|
|
|
2015-08-27 23:44:33 -03:00
|
|
|
//keep track of number of calibration reports sent
|
|
|
|
uint8_t _reports_sent[COMPASS_MAX_INSTANCES];
|
|
|
|
|
|
|
|
//autoreboot after compass calibration
|
|
|
|
bool _compass_cal_autoreboot;
|
|
|
|
bool _cal_complete_requires_reboot;
|
|
|
|
bool _cal_has_run;
|
|
|
|
|
2014-11-15 21:58:23 -04:00
|
|
|
// backend objects
|
2015-02-23 19:17:44 -04:00
|
|
|
AP_Compass_Backend *_backends[COMPASS_MAX_BACKEND];
|
2014-11-15 21:58:23 -04:00
|
|
|
uint8_t _backend_count;
|
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// number of registered compasses.
|
|
|
|
uint8_t _compass_count;
|
|
|
|
|
|
|
|
// settable parameters
|
|
|
|
AP_Int8 _learn;
|
|
|
|
|
|
|
|
// board orientation from AHRS
|
|
|
|
enum Rotation _board_orientation;
|
|
|
|
|
|
|
|
// primary instance
|
|
|
|
AP_Int8 _primary;
|
|
|
|
|
|
|
|
// declination in radians
|
2014-11-15 21:58:23 -04:00
|
|
|
AP_Float _declination;
|
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// enable automatic declination code
|
|
|
|
AP_Int8 _auto_declination;
|
|
|
|
|
|
|
|
// first-time-around flag used by offset nulling
|
|
|
|
bool _null_init_done;
|
2012-03-28 06:46:11 -03:00
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// used by offset correction
|
2012-03-28 06:46:11 -03:00
|
|
|
static const uint8_t _mag_history_size = 20;
|
2013-01-13 01:02:49 -04:00
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// motor compensation type
|
|
|
|
// 0 = disabled, 1 = enabled for throttle, 2 = enabled for current
|
|
|
|
AP_Int8 _motor_comp_type;
|
2013-02-27 03:57:04 -04:00
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// throttle expressed as a percentage from 0 ~ 1.0 or current expressed in amps
|
|
|
|
float _thr_or_curr;
|
2014-11-15 21:58:23 -04:00
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
struct mag_state {
|
|
|
|
AP_Int8 external;
|
|
|
|
bool healthy;
|
|
|
|
AP_Int8 orientation;
|
|
|
|
AP_Vector3f offset;
|
2015-03-18 20:18:47 -03:00
|
|
|
AP_Vector3f diagonals;
|
|
|
|
AP_Vector3f offdiagonals;
|
2014-11-15 21:58:23 -04:00
|
|
|
|
2015-10-14 13:04:02 -03:00
|
|
|
// device id detected at init.
|
2015-02-23 19:17:44 -04:00
|
|
|
// saved to eeprom when offsets are saved allowing ram &
|
|
|
|
// eeprom values to be compared as consistency check
|
|
|
|
AP_Int32 dev_id;
|
2015-10-14 13:04:02 -03:00
|
|
|
|
2015-02-23 19:17:44 -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;
|
2015-07-16 05:56:12 -03:00
|
|
|
uint32_t last_update_usec;
|
2015-03-18 19:14:38 -03:00
|
|
|
|
|
|
|
uint32_t raw_meas_time_us;
|
|
|
|
bool has_raw_field;
|
|
|
|
bool has_unfiltered_field;
|
|
|
|
bool updated_raw_field;
|
|
|
|
bool updated_unfiltered_field;
|
|
|
|
Vector3f raw_field;
|
|
|
|
Vector3f unfiltered_field;
|
2015-02-23 19:17:44 -04:00
|
|
|
} _state[COMPASS_MAX_INSTANCES];
|
2015-03-13 08:32:35 -03:00
|
|
|
|
2015-03-18 20:42:30 -03:00
|
|
|
CompassCalibrator _calibrator[COMPASS_MAX_INSTANCES];
|
|
|
|
|
2015-03-13 08:32:35 -03:00
|
|
|
// if we want HIL only
|
|
|
|
bool _hil_mode:1;
|
2015-09-14 04:01:14 -03:00
|
|
|
|
|
|
|
AP_Float _calibration_threshold;
|
2011-02-14 00:27:07 -04:00
|
|
|
};
|
2014-11-15 21:58:23 -04:00
|
|
|
|
|
|
|
#include "AP_Compass_Backend.h"
|
|
|
|
#include "AP_Compass_HMC5843.h"
|
|
|
|
#include "AP_Compass_HIL.h"
|
|
|
|
#include "AP_Compass_AK8963.h"
|
|
|
|
#include "AP_Compass_PX4.h"
|
2015-08-17 21:09:52 -03:00
|
|
|
#include "AP_Compass_LSM303D.h"
|
2011-02-14 00:27:07 -04:00
|
|
|
#endif
|