2014-11-15 21:58:23 -04:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compass driver backend class. Each supported compass sensor type
|
|
|
|
needs to have an object derived from this class.
|
|
|
|
*/
|
2016-02-17 21:25:20 -04:00
|
|
|
#pragma once
|
2014-11-15 21:58:23 -04:00
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
#include "AP_Compass.h"
|
2014-11-15 21:58:23 -04:00
|
|
|
|
|
|
|
class Compass; // forward declaration
|
|
|
|
class AP_Compass_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AP_Compass_Backend(Compass &compass);
|
|
|
|
|
|
|
|
// we declare a virtual destructor so that drivers can
|
|
|
|
// override with a custom destructor if need be.
|
|
|
|
virtual ~AP_Compass_Backend(void) {}
|
|
|
|
|
|
|
|
// read sensor data
|
2015-02-23 19:17:44 -04:00
|
|
|
virtual void read(void) = 0;
|
2014-11-15 21:58:23 -04:00
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// accumulate a reading from the magnetometer. Optional in
|
|
|
|
// backends
|
|
|
|
virtual void accumulate(void) {};
|
2014-11-15 21:58:23 -04:00
|
|
|
|
2017-04-02 11:56:15 -03:00
|
|
|
// callback for UAVCAN messages
|
|
|
|
virtual void handle_mag_msg(Vector3f &mag) {};
|
|
|
|
|
2016-11-04 21:24:21 -03:00
|
|
|
/*
|
|
|
|
device driver IDs. These are used to fill in the devtype field
|
|
|
|
of the device ID, which shows up as COMPASS*ID* parameters to
|
|
|
|
users. The values are chosen for compatibility with existing PX4
|
|
|
|
drivers.
|
|
|
|
If a change is made to a driver that would make existing
|
|
|
|
calibration values invalid then this number must be changed.
|
|
|
|
*/
|
|
|
|
enum DevTypes {
|
2016-11-07 17:54:32 -04:00
|
|
|
DEVTYPE_HMC5883_OLD = 0x01,
|
2016-11-07 04:04:40 -04:00
|
|
|
DEVTYPE_HMC5883 = 0x07,
|
2016-11-04 21:24:21 -03:00
|
|
|
DEVTYPE_LSM303D = 0x02,
|
|
|
|
DEVTYPE_AK8963 = 0x04,
|
|
|
|
DEVTYPE_BMM150 = 0x05,
|
|
|
|
DEVTYPE_LSM9DS1 = 0x06,
|
2016-11-24 02:54:44 -04:00
|
|
|
DEVTYPE_LIS3MDL = 0x08,
|
2016-11-24 03:46:47 -04:00
|
|
|
DEVTYPE_AK09916 = 0x09,
|
2016-12-07 11:12:40 -04:00
|
|
|
DEVTYPE_IST8310 = 0x0A,
|
2016-11-04 21:24:21 -03:00
|
|
|
};
|
2017-04-02 11:56:15 -03:00
|
|
|
|
|
|
|
|
2014-11-15 21:58:23 -04:00
|
|
|
protected:
|
2015-03-18 19:15:22 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A compass measurement is expected to pass through the following functions:
|
|
|
|
* 1. rotate_field - this rotates the measurement in-place from sensor frame
|
|
|
|
* to body frame
|
|
|
|
* 2. publish_raw_field - this provides an uncorrected point-sample for
|
|
|
|
* calibration libraries
|
|
|
|
* 3. correct_field - this corrects the measurement in-place for hard iron,
|
|
|
|
* soft iron, motor interference, and non-orthagonality errors
|
2016-03-10 21:07:52 -04:00
|
|
|
* 4. publish_filtered_field - legacy filtered magnetic field
|
2015-09-29 16:51:21 -03:00
|
|
|
*
|
|
|
|
* All those functions expect the mag field to be in milligauss.
|
2015-03-18 19:15:22 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void rotate_field(Vector3f &mag, uint8_t instance);
|
|
|
|
void publish_raw_field(const Vector3f &mag, uint32_t time_us, uint8_t instance);
|
|
|
|
void correct_field(Vector3f &mag, uint8_t i);
|
|
|
|
void publish_filtered_field(const Vector3f &mag, uint8_t instance);
|
2016-05-04 04:11:02 -03:00
|
|
|
void set_last_update_usec(uint32_t last_update, uint8_t instance);
|
2015-02-23 19:17:44 -04:00
|
|
|
|
|
|
|
// register a new compass instance with the frontend
|
|
|
|
uint8_t register_compass(void) const;
|
|
|
|
|
|
|
|
// set dev_id for an instance
|
|
|
|
void set_dev_id(uint8_t instance, uint32_t dev_id);
|
|
|
|
|
|
|
|
// set external state for an instance
|
|
|
|
void set_external(uint8_t instance, bool external);
|
|
|
|
|
2016-01-28 13:07:00 -04:00
|
|
|
// tell if instance is an external compass
|
|
|
|
bool is_external(uint8_t instance);
|
|
|
|
|
2016-11-06 06:04:48 -04:00
|
|
|
// set rotation of an instance
|
|
|
|
void set_rotation(uint8_t instance, enum Rotation rotation);
|
2017-04-02 11:56:15 -03:00
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
// access to frontend
|
|
|
|
Compass &_compass;
|
|
|
|
|
2016-11-03 21:47:43 -03:00
|
|
|
// semaphore for access to shared frontend data
|
2017-04-02 11:56:15 -03:00
|
|
|
AP_HAL::Semaphore *_sem;
|
|
|
|
|
2015-02-23 19:17:44 -04:00
|
|
|
private:
|
|
|
|
void apply_corrections(Vector3f &mag, uint8_t i);
|
2014-11-15 21:58:23 -04:00
|
|
|
};
|