APM:Libraries
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
Compass Class Reference

#include <AP_Compass.h>

Collaboration diagram for Compass:
[legend]

Classes

struct  mag_state
 

Public Types

enum  LearnType { LEARN_NONE =0, LEARN_INTERNAL =1, LEARN_EKF =2, LEARN_INFLIGHT =3 }
 

Public Member Functions

 Compass ()
 
 Compass (const Compass &other)=delete
 
Compassoperator= (const Compass &)=delete
 
bool init ()
 
bool read ()
 
void accumulate ()
 
float calculate_heading (const Matrix3f &dcm_matrix) const
 
float calculate_heading (const Matrix3f &dcm_matrix, uint8_t i) const
 
void set_offsets (uint8_t i, const Vector3f &offsets)
 
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)
 
void save_offsets (uint8_t i)
 
void save_offsets (void)
 
uint8_t get_count (void) const
 
const Vector3fget_field (uint8_t i) const
 Return the current field as a Vector3f in milligauss. More...
 
const Vector3fget_field (void) const
 
void compass_cal_update ()
 
void per_motor_calibration_start (void)
 
void per_motor_calibration_update (void)
 
void per_motor_calibration_end (void)
 
void start_calibration_all (bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot=false)
 
void cancel_calibration_all ()
 
bool compass_cal_requires_reboot ()
 
bool is_calibrating () const
 
MAV_RESULT handle_mag_cal_command (const mavlink_command_long_t &packet)
 
void send_mag_cal_progress (mavlink_channel_t chan)
 
void send_mag_cal_report (mavlink_channel_t chan)
 
bool consistent () const
 
bool healthy (uint8_t i) const
 Return the health of a compass. More...
 
bool healthy (void) const
 
uint8_t get_healthy_mask () const
 
const Vector3fget_offsets (uint8_t i) const
 
const Vector3fget_offsets (void) const
 
const Vector3fget_diagonals (uint8_t i) const
 
const Vector3fget_diagonals (void) const
 
const Vector3fget_offdiagonals (uint8_t i) const
 
const Vector3fget_offdiagonals (void) const
 
void set_initial_location (int32_t latitude, int32_t longitude)
 
void set_and_save_offsets (uint8_t i, int x, int y, int z)
 
bool learn_offsets_enabled () const
 
bool use_for_yaw (uint8_t i) const
 return true if the compass should be used for yaw calculations More...
 
bool use_for_yaw (void) const
 return true if the compass should be used for yaw calculations More...
 
void set_use_for_yaw (uint8_t i, bool use)
 
void set_declination (float radians, bool save_to_eeprom=true)
 
float get_declination () const
 
void set_board_orientation (enum Rotation orientation, Matrix3f *custom_rotation=nullptr)
 
void motor_compensation_type (const uint8_t comp_type)
 
uint8_t get_motor_compensation_type () const
 get the motor compensation value. More...
 
void set_motor_compensation (uint8_t i, const Vector3f &motor_comp_factor)
 
const Vector3fget_motor_compensation (uint8_t i) const
 get motor compensation factors as a vector More...
 
const Vector3fget_motor_compensation (void) const
 
void save_motor_compensation ()
 
const Vector3fget_motor_offsets (uint8_t i) const
 
const Vector3fget_motor_offsets (void) const
 
void set_throttle (float thr_pct)
 
void set_voltage (float voltage)
 Set the battery voltage for per-motor compensation. More...
 
bool configured (uint8_t i)
 
bool configured (void)
 
uint8_t get_primary (void) const
 
void setHIL (uint8_t instance, float roll, float pitch, float yaw)
 
void setHIL (uint8_t instance, const Vector3f &mag, uint32_t last_update_usec)
 
const Vector3fgetHIL (uint8_t instance) const
 
void _setup_earth_field ()
 
void set_hil_mode (void)
 
uint32_t last_update_usec (void) const
 
uint32_t last_update_usec (uint8_t i) const
 
uint32_t last_update_ms (void) const
 
uint32_t last_update_ms (uint8_t i) const
 
enum LearnType get_learn_type (void) const
 
void set_learn_type (enum LearnType type, bool save)
 
uint16_t get_offsets_max (void) const
 
uint8_t get_filter_range () const
 

Static Public Member Functions

static Compassget_singleton ()
 

Public Attributes

struct {
   Vector3f   Bearth
 
   float   last_declination
 
   bool   healthy [COMPASS_MAX_INSTANCES]
 
   Vector3f   field [COMPASS_MAX_INSTANCES]
 
_hil
 

Static Public Attributes

static const struct AP_Param::GroupInfo var_info []
 

Private Types

enum  DriverType {
  DRIVER_HMC5883 =0, 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, DRIVER_MAG3110 =14
}
 

Private Member Functions

uint8_t register_compass (void)
 
bool _add_backend (AP_Compass_Backend *backend, const char *name, bool external)
 
void _detect_backends (void)
 
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 ()
 
bool _have_driver (AP_HAL::Device::BusType bus_type, uint8_t bus_num, uint8_t address, uint8_t devtype) const
 
bool _driver_enabled (enum DriverType driver_type)
 

Private Attributes

bool _cal_saved [COMPASS_MAX_INSTANCES]
 
bool _cal_autosave
 
bool _compass_cal_autoreboot
 
bool _cal_complete_requires_reboot
 
bool _cal_has_run
 
AP_Compass_Backend_backends [COMPASS_MAX_BACKEND]
 
uint8_t _backend_count
 
uint8_t _compass_count
 
AP_Int8 _learn
 
enum Rotation _board_orientation
 
Matrix3f_custom_rotation
 
AP_Int8 _primary
 
AP_Float _declination
 
AP_Int8 _auto_declination
 
bool _null_init_done
 
AP_Int8 _motor_comp_type
 
float _thr
 
struct Compass::mag_state _state [COMPASS_MAX_INSTANCES]
 
AP_Int16 _offset_max
 
CompassCalibrator _calibrator [COMPASS_MAX_INSTANCES]
 
Compass_PerMotor _per_motor {*this}
 
bool _hil_mode:1
 
AP_Float _calibration_threshold
 
AP_Int32 _driver_type_mask
 
AP_Int8 _filter_range
 

Static Private Attributes

static Compass_singleton
 
static const uint8_t _mag_history_size = 20
 

Friends

class AP_Compass_Backend
 
class CompassLearn
 

Detailed Description

Definition at line 49 of file AP_Compass.h.

Member Enumeration Documentation

◆ DriverType

enum Compass::DriverType
private
Enumerator
DRIVER_HMC5883 
DRIVER_LSM303D 
DRIVER_AK8963 
DRIVER_BMM150 
DRIVER_LSM9DS1 
DRIVER_LIS3MDL 
DRIVER_AK09916 
DRIVER_IST8310 
DRIVER_ICM20948 
DRIVER_MMC3416 
DRIVER_UAVCAN 
DRIVER_QMC5883 
DRIVER_SITL 
DRIVER_MAG3110 

Definition at line 368 of file AP_Compass.h.

◆ LearnType

Enumerator
LEARN_NONE 
LEARN_INTERNAL 
LEARN_EKF 
LEARN_INFLIGHT 

Definition at line 305 of file AP_Compass.h.

Constructor & Destructor Documentation

◆ Compass() [1/2]

Compass::Compass ( void  )

Definition at line 454 of file AP_Compass.cpp.

Here is the call graph for this function:

◆ Compass() [2/2]

Compass::Compass ( const Compass other)
delete

Member Function Documentation

◆ _accept_calibration()

bool Compass::_accept_calibration ( uint8_t  i)
private

Definition at line 132 of file AP_Compass_Calibration.cpp.

Referenced by _accept_calibration_mask(), and compass_cal_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _accept_calibration_mask()

bool Compass::_accept_calibration_mask ( uint8_t  mask)
private

Definition at line 160 of file AP_Compass_Calibration.cpp.

Referenced by handle_mag_cal_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _add_backend()

bool Compass::_add_backend ( AP_Compass_Backend backend,
const char *  name,
bool  external 
)
private

Definition at line 511 of file AP_Compass.cpp.

Referenced by _detect_backends().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _auto_reboot()

bool Compass::_auto_reboot ( )
inlineprivate

Definition at line 352 of file AP_Compass.h.

Referenced by compass_cal_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _cancel_calibration()

void Compass::_cancel_calibration ( uint8_t  i)
private

Definition at line 104 of file AP_Compass_Calibration.cpp.

Referenced by _cancel_calibration_mask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _cancel_calibration_mask()

void Compass::_cancel_calibration_mask ( uint8_t  mask)
private

Definition at line 116 of file AP_Compass_Calibration.cpp.

Referenced by _start_calibration_mask(), cancel_calibration_all(), and handle_mag_cal_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _detect_backends()

void Compass::_detect_backends ( void  )
private

Definition at line 552 of file AP_Compass.cpp.

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _driver_enabled()

bool Compass::_driver_enabled ( enum DriverType  driver_type)
private

Definition at line 529 of file AP_Compass.cpp.

Referenced by _detect_backends().

Here is the caller graph for this function:

◆ _get_cal_mask()

uint8_t Compass::_get_cal_mask ( ) const
private

Definition at line 255 of file AP_Compass_Calibration.cpp.

Referenced by send_mag_cal_progress(), and send_mag_cal_report().

Here is the caller graph for this function:

◆ _have_driver()

bool Compass::_have_driver ( AP_HAL::Device::BusType  bus_type,
uint8_t  bus_num,
uint8_t  address,
uint8_t  devtype 
) const
private

Definition at line 538 of file AP_Compass.cpp.

Referenced by _auto_reboot(), and _detect_backends().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setup_earth_field()

void Compass::_setup_earth_field ( void  )

Definition at line 1246 of file AP_Compass.cpp.

Referenced by AP_Compass_HIL::AP_Compass_HIL(), AP_Compass_SITL::AP_Compass_SITL(), get_primary(), and setHIL().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _start_calibration()

bool Compass::_start_calibration ( uint8_t  i,
bool  retry = false,
float  delay_sec = 0.0f 
)
private

Definition at line 45 of file AP_Compass_Calibration.cpp.

Referenced by _start_calibration_mask(), and start_calibration_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _start_calibration_mask()

bool Compass::_start_calibration_mask ( uint8_t  mask,
bool  retry = false,
bool  autosave = false,
float  delay_sec = 0.0f,
bool  autoreboot = false 
)
private

Definition at line 74 of file AP_Compass_Calibration.cpp.

Referenced by handle_mag_cal_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ accumulate()

void Compass::accumulate ( void  )

use spare CPU cycles to accumulate values from the compass if possible (this method should also be implemented in the backends)

Definition at line 970 of file AP_Compass.cpp.

Referenced by loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_heading() [1/2]

float Compass::calculate_heading ( const Matrix3f dcm_matrix) const
inline

Calculate the tilt-compensated heading_ variables.

Parameters
dcm_matrixThe current orientation rotation matrix
Returns
heading in radians

Definition at line 87 of file AP_Compass.h.

Referenced by AP_AHRS_DCM::drift_correction_yaw(), and loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_heading() [2/2]

float Compass::calculate_heading ( const Matrix3f dcm_matrix,
uint8_t  i 
) const

Definition at line 1123 of file AP_Compass.cpp.

Here is the call graph for this function:

◆ cancel_calibration_all()

void Compass::cancel_calibration_all ( )

Definition at line 126 of file AP_Compass_Calibration.cpp.

Referenced by compass_cal_update(), handle_mag_cal_command(), and per_motor_calibration_end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compass_cal_requires_reboot()

bool Compass::compass_cal_requires_reboot ( )
inline

Definition at line 143 of file AP_Compass.h.

Referenced by AP_Arming::compass_checks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compass_cal_update()

void Compass::compass_cal_update ( )

Definition at line 10 of file AP_Compass_Calibration.cpp.

Referenced by get_field().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configured() [1/2]

bool Compass::configured ( uint8_t  i)

Returns True if the compasses have been configured (i.e. offsets saved)

Returns
True if compass has been configured

Definition at line 1156 of file AP_Compass.cpp.

Referenced by AP_Arming::compass_checks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configured() [2/2]

bool Compass::configured ( void  )

Definition at line 1186 of file AP_Compass.cpp.

Referenced by set_voltage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consistent()

bool Compass::consistent ( ) const

Definition at line 1272 of file AP_Compass.cpp.

Referenced by compass_cal_requires_reboot(), AP_Arming::compass_checks(), NavEKF2_core::readMagData(), and NavEKF3_core::readMagData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_count()

uint8_t Compass::get_count ( void  ) const
inline

Definition at line 119 of file AP_Compass.h.

Referenced by configured(), consistent(), DataFlash_Class::Log_Write_Compass(), loop(), NavEKF2_core::readMagData(), NavEKF3_core::readMagData(), GCS_MAVLINK::send_raw_imu(), and setup().

Here is the caller graph for this function:

◆ get_declination()

float Compass::get_declination ( ) const

◆ get_diagonals() [1/2]

const Vector3f& Compass::get_diagonals ( uint8_t  i) const
inline

Definition at line 169 of file AP_Compass.h.

Referenced by CompassLearn::update().

Here is the caller graph for this function:

◆ get_diagonals() [2/2]

const Vector3f& Compass::get_diagonals ( void  ) const
inline

Definition at line 170 of file AP_Compass.h.

Referenced by get_diagonals().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_field() [1/2]

const Vector3f& Compass::get_field ( uint8_t  i) const
inline

Return the current field as a Vector3f in milligauss.

Definition at line 122 of file AP_Compass.h.

Referenced by Compass_PerMotor::calibration_start(), Compass_PerMotor::calibration_update(), AP_Arming::compass_checks(), DataFlash_Class::Log_Write_Compass_instance(), loop(), SoloGimbalEKF::readMagData(), NavEKF2_core::readMagData(), NavEKF3_core::readMagData(), GCS_MAVLINK::send_raw_imu(), CompassLearn::update(), and AP_AHRS_DCM::yaw_error_compass().

Here is the caller graph for this function:

◆ get_field() [2/2]

const Vector3f& Compass::get_field ( void  ) const
inline

Definition at line 123 of file AP_Compass.h.

Referenced by calculate_heading(), consistent(), and get_field().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_filter_range()

uint8_t Compass::get_filter_range ( ) const
inline

Definition at line 331 of file AP_Compass.h.

Referenced by AP_Compass_Backend::field_ok().

Here is the caller graph for this function:

◆ get_healthy_mask()

uint8_t Compass::get_healthy_mask ( ) const

Definition at line 993 of file AP_Compass.cpp.

Referenced by healthy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_learn_type()

enum LearnType Compass::get_learn_type ( void  ) const
inline

Definition at line 313 of file AP_Compass.h.

Referenced by CompassLearn::update().

Here is the caller graph for this function:

◆ get_motor_compensation() [1/2]

const Vector3f& Compass::get_motor_compensation ( uint8_t  i) const
inline

get motor compensation factors as a vector

Definition at line 237 of file AP_Compass.h.

◆ get_motor_compensation() [2/2]

const Vector3f& Compass::get_motor_compensation ( void  ) const
inline

Definition at line 238 of file AP_Compass.h.

Referenced by get_motor_compensation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_motor_compensation_type()

uint8_t Compass::get_motor_compensation_type ( ) const
inline

get the motor compensation value.

Definition at line 225 of file AP_Compass.h.

Here is the call graph for this function:

◆ get_motor_offsets() [1/2]

const Vector3f& Compass::get_motor_offsets ( uint8_t  i) const
inline

Returns the current motor compensation offset values

Returns
The current compass offsets in milligauss.

Definition at line 250 of file AP_Compass.h.

Referenced by DataFlash_Class::Log_Write_Compass_instance().

Here is the caller graph for this function:

◆ get_motor_offsets() [2/2]

const Vector3f& Compass::get_motor_offsets ( void  ) const
inline

Definition at line 251 of file AP_Compass.h.

Referenced by get_motor_offsets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_offdiagonals() [1/2]

const Vector3f& Compass::get_offdiagonals ( uint8_t  i) const
inline

Definition at line 172 of file AP_Compass.h.

Referenced by CompassLearn::update().

Here is the caller graph for this function:

◆ get_offdiagonals() [2/2]

const Vector3f& Compass::get_offdiagonals ( void  ) const
inline

Definition at line 173 of file AP_Compass.h.

Referenced by get_offdiagonals().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_offsets() [1/2]

const Vector3f& Compass::get_offsets ( uint8_t  i) const
inline

Returns the current offset values

Returns
The current compass offsets in milligauss.

Definition at line 166 of file AP_Compass.h.

Referenced by AP_Arming::compass_checks(), NavEKF2_core::getMagOffsets(), NavEKF3_core::getMagOffsets(), DataFlash_Class::Log_Write_Compass_instance(), NavEKF2_core::readMagData(), NavEKF3_core::readMagData(), GCS_MAVLINK::send_sensor_offsets(), and CompassLearn::update().

Here is the caller graph for this function:

◆ get_offsets() [2/2]

const Vector3f& Compass::get_offsets ( void  ) const
inline

Definition at line 167 of file AP_Compass.h.

Referenced by configured(), and get_offsets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_offsets_max()

uint16_t Compass::get_offsets_max ( void  ) const
inline

Definition at line 327 of file AP_Compass.h.

Referenced by _start_calibration(), and AP_Arming::compass_checks().

Here is the caller graph for this function:

◆ get_primary()

uint8_t Compass::get_primary ( void  ) const
inline

Returns the instance of the primary compass

Returns
the instance number of the primary compass

Definition at line 277 of file AP_Compass.h.

Referenced by _start_calibration(), calculate_heading(), get_diagonals(), get_field(), get_motor_compensation(), get_motor_offsets(), get_offdiagonals(), get_offsets(), healthy(), NavEKF2_core::InitialiseVariables(), NavEKF3_core::InitialiseVariables(), last_update_ms(), last_update_usec(), and use_for_yaw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_singleton()

static Compass* Compass::get_singleton ( )
inlinestatic

Definition at line 60 of file AP_Compass.h.

Referenced by AP::compass().

Here is the caller graph for this function:

◆ getHIL()

const Vector3f & Compass::getHIL ( uint8_t  instance) const

Definition at line 1240 of file AP_Compass.cpp.

Referenced by get_primary().

Here is the caller graph for this function:

◆ handle_mag_cal_command()

MAV_RESULT Compass::handle_mag_cal_command ( const mavlink_command_long_t &  packet)

Definition at line 270 of file AP_Compass_Calibration.cpp.

Referenced by compass_cal_requires_reboot(), and GCS_MAVLINK::handle_command_mag_cal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ healthy() [1/2]

bool Compass::healthy ( uint8_t  i) const
inline

Return the health of a compass.

Definition at line 158 of file AP_Compass.h.

◆ healthy() [2/2]

bool Compass::healthy ( void  ) const
inline

Definition at line 159 of file AP_Compass.h.

Referenced by _start_calibration(), get_healthy_mask(), healthy(), read(), and use_for_yaw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

bool Compass::init ( void  )

Initialize the compass device.

Returns
True if the compass was initialized OK, false if it was not found or is not functioning.

Definition at line 487 of file AP_Compass.cpp.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_calibrating()

bool Compass::is_calibrating ( ) const

Definition at line 239 of file AP_Compass_Calibration.cpp.

Referenced by _accept_calibration(), _start_calibration(), compass_cal_requires_reboot(), compass_cal_update(), and AP_Arming::compass_checks().

Here is the caller graph for this function:

◆ last_update_ms() [1/2]

uint32_t Compass::last_update_ms ( void  ) const
inline

Definition at line 292 of file AP_Compass.h.

Here is the call graph for this function:

◆ last_update_ms() [2/2]

uint32_t Compass::last_update_ms ( uint8_t  i) const
inline

Definition at line 293 of file AP_Compass.h.

◆ last_update_usec() [1/2]

uint32_t Compass::last_update_usec ( void  ) const
inline

Definition at line 289 of file AP_Compass.h.

Referenced by AP_AHRS_DCM::drift_correction_yaw(), get_primary(), DataFlash_Class::Log_Write_Compass_instance(), AP_Compass_HIL::read(), SoloGimbalEKF::readMagData(), NavEKF2_core::readMagData(), and NavEKF3_core::readMagData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ last_update_usec() [2/2]

uint32_t Compass::last_update_usec ( uint8_t  i) const
inline

Definition at line 290 of file AP_Compass.h.

◆ learn_offsets_enabled()

bool Compass::learn_offsets_enabled ( ) const
inline

Definition at line 194 of file AP_Compass.h.

Referenced by AP_Arming::compass_checks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ motor_compensation_type()

void Compass::motor_compensation_type ( const uint8_t  comp_type)

Set the motor compensation type

Parameters
comp_type0 = disabled, 1 = enabled use throttle, 2 = enabled use current

Definition at line 1261 of file AP_Compass.cpp.

Referenced by set_board_orientation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

Compass& Compass::operator= ( const Compass )
delete

◆ per_motor_calibration_end()

void Compass::per_motor_calibration_end ( void  )
inline

Definition at line 135 of file AP_Compass.h.

Here is the call graph for this function:

◆ per_motor_calibration_start()

void Compass::per_motor_calibration_start ( void  )
inline

Definition at line 129 of file AP_Compass.h.

Here is the call graph for this function:

◆ per_motor_calibration_update()

void Compass::per_motor_calibration_update ( void  )
inline

Definition at line 132 of file AP_Compass.h.

Here is the call graph for this function:

◆ read()

bool Compass::read ( void  )

Read the compass and update the mag_ variables.

Definition at line 979 of file AP_Compass.cpp.

Referenced by Compass_PerMotor::calibration_start(), AP_AHRS_DCM::drift_correction_yaw(), init(), and loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_compass()

uint8_t Compass::register_compass ( void  )
private

Register a new compas driver, allocating an instance number

Returns
number of compass instances

Definition at line 503 of file AP_Compass.cpp.

Referenced by AP_Compass_Backend::register_compass().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_motor_compensation()

void Compass::save_motor_compensation ( )

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

Definition at line 1063 of file AP_Compass.cpp.

Referenced by get_motor_compensation().

Here is the caller graph for this function:

◆ save_offsets() [1/2]

void Compass::save_offsets ( uint8_t  i)

Saves the current offset x/y/z values for one or all compasses

Parameters
icompass instance

This should be invoked periodically to save the offset values maintained by ::learn_offsets.

Definition at line 1042 of file AP_Compass.cpp.

Referenced by CompassLearn::update().

Here is the caller graph for this function:

◆ save_offsets() [2/2]

void Compass::save_offsets ( void  )

Definition at line 1049 of file AP_Compass.cpp.

Referenced by calculate_heading(), and set_and_save_offsets().

Here is the caller graph for this function:

◆ send_mag_cal_progress()

void Compass::send_mag_cal_progress ( mavlink_channel_t  chan)

Definition at line 176 of file AP_Compass_Calibration.cpp.

Referenced by compass_cal_requires_reboot(), and GCS_MAVLINK::try_send_compass_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_mag_cal_report()

void Compass::send_mag_cal_report ( mavlink_channel_t  chan)

Definition at line 207 of file AP_Compass_Calibration.cpp.

Referenced by compass_cal_requires_reboot(), and GCS_MAVLINK::try_send_compass_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_and_save_diagonals()

void Compass::set_and_save_diagonals ( uint8_t  i,
const Vector3f diagonals 
)

Definition at line 1024 of file AP_Compass.cpp.

Referenced by _accept_calibration(), and calculate_heading().

Here is the caller graph for this function:

◆ set_and_save_offdiagonals()

void Compass::set_and_save_offdiagonals ( uint8_t  i,
const Vector3f diagonals 
)

Definition at line 1033 of file AP_Compass.cpp.

Referenced by _accept_calibration(), and calculate_heading().

Here is the caller graph for this function:

◆ set_and_save_offsets() [1/2]

void Compass::set_and_save_offsets ( uint8_t  i,
const Vector3f offsets 
)

Sets and saves the compass offset x/y/z values.

Parameters
icompass instance
offsetsOffsets to the raw mag_ values in milligauss.

Definition at line 1014 of file AP_Compass.cpp.

Referenced by _accept_calibration(), calculate_heading(), GCS_MAVLINK::handle_command_preflight_set_sensor_offsets(), set_and_save_offsets(), and setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_and_save_offsets() [2/2]

void Compass::set_and_save_offsets ( uint8_t  i,
int  x,
int  y,
int  z 
)
inline

Program new offset values.

Parameters
icompass instance
xOffset to the raw mag_x value in milligauss.
yOffset to the raw mag_y value in milligauss.
zOffset to the raw mag_z value in milligauss.

Definition at line 189 of file AP_Compass.h.

Here is the call graph for this function:

◆ set_board_orientation()

void Compass::set_board_orientation ( enum Rotation  orientation,
Matrix3f custom_rotation = nullptr 
)
inline

Definition at line 213 of file AP_Compass.h.

Referenced by AP_AHRS::set_orientation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_declination()

void Compass::set_declination ( float  radians,
bool  save_to_eeprom = true 
)

Sets the local magnetic field declination.

Parameters
radiansLocal field declination.
save_to_eepromtrue to save to eeprom (false saves only to memory)

Definition at line 1104 of file AP_Compass.cpp.

Referenced by set_use_for_yaw(), and setup().

Here is the caller graph for this function:

◆ set_hil_mode()

void Compass::set_hil_mode ( void  )
inline

Definition at line 286 of file AP_Compass.h.

◆ set_initial_location()

void Compass::set_initial_location ( int32_t  latitude,
int32_t  longitude 
)

Sets the initial location used to get declination

Parameters
latitudeGPS Latitude.
longitudeGPS Longitude.

Definition at line 1072 of file AP_Compass.cpp.

Referenced by get_offdiagonals().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_learn_type()

void Compass::set_learn_type ( enum LearnType  type,
bool  save 
)
inline

Definition at line 318 of file AP_Compass.h.

Referenced by CompassLearn::update().

Here is the caller graph for this function:

◆ set_motor_compensation()

void Compass::set_motor_compensation ( uint8_t  i,
const Vector3f motor_comp_factor 
)

Set the motor compensation factor x/y/z values.

Parameters
iinstance of compass
offsetsOffsets multiplied by the throttle value and added to the raw mag_ values.

Definition at line 1057 of file AP_Compass.cpp.

Referenced by get_motor_compensation_type(), and motor_compensation_type().

Here is the caller graph for this function:

◆ set_offsets()

void Compass::set_offsets ( uint8_t  i,
const Vector3f offsets 
)

Sets offset x/y/z values.

Parameters
icompass instance
offsetsOffsets to the raw mag_ values in milligauss.

Definition at line 1005 of file AP_Compass.cpp.

Referenced by calculate_heading(), and CompassLearn::update().

Here is the caller graph for this function:

◆ set_throttle()

void Compass::set_throttle ( float  thr_pct)
inline

Set the throttle as a percentage from 0.0 to 1.0

Parameters
thr_pctthrottle expressed as a percentage from 0 to 1.0

Definition at line 255 of file AP_Compass.h.

◆ set_use_for_yaw()

void Compass::set_use_for_yaw ( uint8_t  i,
bool  use 
)
inline

Definition at line 200 of file AP_Compass.h.

Referenced by CompassLearn::update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_voltage()

void Compass::set_voltage ( float  voltage)
inline

Set the battery voltage for per-motor compensation.

Definition at line 262 of file AP_Compass.h.

Here is the call graph for this function:

◆ setHIL() [1/2]

void Compass::setHIL ( uint8_t  instance,
float  roll,
float  pitch,
float  yaw 
)

Definition at line 1197 of file AP_Compass.cpp.

Referenced by get_primary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHIL() [2/2]

void Compass::setHIL ( uint8_t  instance,
const Vector3f mag,
uint32_t  last_update_usec 
)

Definition at line 1233 of file AP_Compass.cpp.

◆ start_calibration_all()

void Compass::start_calibration_all ( bool  retry = false,
bool  autosave = false,
float  delay_sec = 0.0f,
bool  autoreboot = false 
)

Definition at line 91 of file AP_Compass_Calibration.cpp.

Referenced by handle_mag_cal_command(), and per_motor_calibration_end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ use_for_yaw() [1/2]

bool Compass::use_for_yaw ( uint8_t  i) const

return true if the compass should be used for yaw calculations

return true if the specified compass can be used for yaw calculations

Definition at line 1095 of file AP_Compass.cpp.

Referenced by AP_AHRS_NavEKF::active_EKF_type(), AP_Arming::compass_checks(), loop(), SoloGimbalEKF::readMagData(), NavEKF2_core::readMagData(), NavEKF3_core::readMagData(), AP_AHRS_DCM::use_compass(), NavEKF2_core::use_compass(), NavEKF3_core::use_compass(), and AP_AHRS::use_compass().

Here is the caller graph for this function:

◆ use_for_yaw() [2/2]

bool Compass::use_for_yaw ( void  ) const

return true if the compass should be used for yaw calculations

Definition at line 1087 of file AP_Compass.cpp.

Referenced by _start_calibration(), configured(), consistent(), and learn_offsets_enabled().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ AP_Compass_Backend

friend class AP_Compass_Backend
friend

Definition at line 51 of file AP_Compass.h.

◆ CompassLearn

friend class CompassLearn
friend

Definition at line 64 of file AP_Compass.h.

Member Data Documentation

◆ _auto_declination

AP_Int8 Compass::_auto_declination
private

Definition at line 408 of file AP_Compass.h.

Referenced by set_initial_location().

◆ _backend_count

uint8_t Compass::_backend_count
private

Definition at line 389 of file AP_Compass.h.

Referenced by _add_backend(), _detect_backends(), accumulate(), and read().

◆ _backends

AP_Compass_Backend* Compass::_backends[COMPASS_MAX_BACKEND]
private

Definition at line 388 of file AP_Compass.h.

Referenced by _add_backend(), accumulate(), Compass(), and read().

◆ _board_orientation

enum Rotation Compass::_board_orientation
private

Definition at line 398 of file AP_Compass.h.

Referenced by AP_Compass_Backend::rotate_field(), set_board_orientation(), and setHIL().

◆ _cal_autosave

bool Compass::_cal_autosave
private

◆ _cal_complete_requires_reboot

bool Compass::_cal_complete_requires_reboot
private

Definition at line 364 of file AP_Compass.h.

Referenced by _accept_calibration(), and compass_cal_requires_reboot().

◆ _cal_has_run

bool Compass::_cal_has_run
private

Definition at line 365 of file AP_Compass.h.

Referenced by compass_cal_update().

◆ _cal_saved

bool Compass::_cal_saved[COMPASS_MAX_INSTANCES]
private

◆ _calibration_threshold

AP_Float Compass::_calibration_threshold
private

Definition at line 468 of file AP_Compass.h.

Referenced by _start_calibration().

◆ _calibrator

CompassCalibrator Compass::_calibrator[COMPASS_MAX_INSTANCES]
private

◆ _compass_cal_autoreboot

bool Compass::_compass_cal_autoreboot
private

Definition at line 363 of file AP_Compass.h.

Referenced by _auto_reboot(), _start_calibration_mask(), and start_calibration_all().

◆ _compass_count

uint8_t Compass::_compass_count
private

Definition at line 392 of file AP_Compass.h.

Referenced by _detect_backends(), _have_driver(), get_count(), init(), and register_compass().

◆ _custom_rotation

Matrix3f* Compass::_custom_rotation
private

Definition at line 399 of file AP_Compass.h.

Referenced by AP_Compass_Backend::rotate_field(), set_board_orientation(), and setHIL().

◆ _declination

AP_Float Compass::_declination
private

◆ _driver_type_mask

AP_Int32 Compass::_driver_type_mask
private

Definition at line 471 of file AP_Compass.h.

Referenced by _detect_backends(), and _driver_enabled().

◆ _filter_range

AP_Int8 Compass::_filter_range
private

Definition at line 473 of file AP_Compass.h.

Referenced by get_filter_range().

◆ _hil

struct { ... } Compass::_hil

◆ _hil_mode

bool Compass::_hil_mode
private

Definition at line 466 of file AP_Compass.h.

Referenced by _detect_backends(), and set_hil_mode().

◆ _learn

AP_Int8 Compass::_learn
private

◆ _mag_history_size

const uint8_t Compass::_mag_history_size = 20
staticprivate

Definition at line 414 of file AP_Compass.h.

◆ _motor_comp_type

AP_Int8 Compass::_motor_comp_type
private

◆ _null_init_done

bool Compass::_null_init_done
private

Definition at line 411 of file AP_Compass.h.

◆ _offset_max

AP_Int16 Compass::_offset_max
private

Definition at line 458 of file AP_Compass.h.

Referenced by get_offsets_max().

◆ _per_motor

Compass_PerMotor Compass::_per_motor {*this}
private

◆ _primary

AP_Int8 Compass::_primary
private

Definition at line 402 of file AP_Compass.h.

Referenced by get_primary().

◆ _singleton

Compass * Compass::_singleton
staticprivate

Definition at line 334 of file AP_Compass.h.

Referenced by Compass(), consistent(), and get_singleton().

◆ _state

struct Compass::mag_state Compass::_state[COMPASS_MAX_INSTANCES]
private

◆ _thr

float Compass::_thr
private

◆ Bearth

Vector3f Compass::Bearth

Definition at line 299 of file AP_Compass.h.

◆ field

Definition at line 302 of file AP_Compass.h.

Referenced by calculate_heading(), and AP_Compass_HIL::read().

◆ healthy

bool Compass::healthy[COMPASS_MAX_INSTANCES]

◆ last_declination

float Compass::last_declination

Definition at line 300 of file AP_Compass.h.

◆ var_info

const AP_Param::GroupInfo Compass::var_info
static

Definition at line 295 of file AP_Compass.h.

Referenced by Compass().


The documentation for this class was generated from the following files: