AP_Compass: add and use compass.available()
Covers both being enabled and initialised
This commit is contained in:
parent
8bbed968de
commit
658c978c9d
@ -1512,6 +1512,10 @@ void
|
|||||||
Compass::_detect_runtime(void)
|
Compass::_detect_runtime(void)
|
||||||
{
|
{
|
||||||
#if HAL_ENABLE_LIBUAVCAN_DRIVERS
|
#if HAL_ENABLE_LIBUAVCAN_DRIVERS
|
||||||
|
if (!available()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Don't try to add device while armed
|
//Don't try to add device while armed
|
||||||
if (hal.util->get_soft_armed()) {
|
if (hal.util->get_soft_armed()) {
|
||||||
return;
|
return;
|
||||||
@ -1537,6 +1541,10 @@ Compass::_detect_runtime(void)
|
|||||||
bool
|
bool
|
||||||
Compass::read(void)
|
Compass::read(void)
|
||||||
{
|
{
|
||||||
|
if (!available()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef HAL_BUILD_AP_PERIPH
|
#ifndef HAL_BUILD_AP_PERIPH
|
||||||
if (!_initial_location_set) {
|
if (!_initial_location_set) {
|
||||||
try_set_initial_location();
|
try_set_initial_location();
|
||||||
@ -1726,6 +1734,9 @@ Compass::use_for_yaw(void) const
|
|||||||
bool
|
bool
|
||||||
Compass::use_for_yaw(uint8_t i) const
|
Compass::use_for_yaw(uint8_t i) const
|
||||||
{
|
{
|
||||||
|
if (!available()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// when we are doing in-flight compass learning the state
|
// when we are doing in-flight compass learning the state
|
||||||
// estimator must not use the compass. The learning code turns off
|
// estimator must not use the compass. The learning code turns off
|
||||||
// inflight learning when it has converged
|
// inflight learning when it has converged
|
||||||
@ -1938,6 +1949,9 @@ bool Compass::consistent() const
|
|||||||
*/
|
*/
|
||||||
bool Compass::have_scale_factor(uint8_t i) const
|
bool Compass::have_scale_factor(uint8_t i) const
|
||||||
{
|
{
|
||||||
|
if (!available()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
StateIndex id = _get_state_id(Priority(i));
|
StateIndex id = _get_state_id(Priority(i));
|
||||||
if (id >= COMPASS_MAX_INSTANCES ||
|
if (id >= COMPASS_MAX_INSTANCES ||
|
||||||
_state[id].scale_factor < COMPASS_MIN_SCALE_FACTOR ||
|
_state[id].scale_factor < COMPASS_MIN_SCALE_FACTOR ||
|
||||||
|
@ -104,6 +104,10 @@ public:
|
|||||||
|
|
||||||
bool enabled() const { return _enabled; }
|
bool enabled() const { return _enabled; }
|
||||||
|
|
||||||
|
// available returns true if the compass is both enabled and has
|
||||||
|
// been initialised
|
||||||
|
bool available() const { return _enabled && init_done; }
|
||||||
|
|
||||||
/// Calculate the tilt-compensated heading_ variables.
|
/// Calculate the tilt-compensated heading_ variables.
|
||||||
///
|
///
|
||||||
/// @param dcm_matrix The current orientation rotation matrix
|
/// @param dcm_matrix The current orientation rotation matrix
|
||||||
|
Loading…
Reference in New Issue
Block a user