Path: blob/master/libraries/AP_ExternalAHRS/AP_ExternalAHRS.h
9701 views
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/14/*15support for serial connected AHRS systems16*/1718#pragma once1920#include "AP_ExternalAHRS_config.h"2122#if AP_EXTERNAL_AHRS_ENABLED2324#include <AP_HAL/AP_HAL.h>25#include <AP_Param/AP_Param.h>26#include <AP_Common/Location.h>27#include <AP_NavEKF/AP_Nav_Common.h>28#include <AP_GPS/AP_GPS_FixType.h>2930class AP_ExternalAHRS_backend;3132class AP_ExternalAHRS {3334public:35friend class AP_ExternalAHRS_backend;36friend class AP_ExternalAHRS_SBG;37friend class AP_ExternalAHRS_VectorNav;3839AP_ExternalAHRS();4041void init(void);4243static const struct AP_Param::GroupInfo var_info[];4445enum class DevType : uint8_t {46None = 0,47#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED48VecNav = 1,49#endif50#if AP_EXTERNAL_AHRS_MICROSTRAIN5_ENABLED51MicroStrain5 = 2,52#endif53#if AP_EXTERNAL_AHRS_INERTIALLABS_ENABLED54InertialLabs = 5,55#endif56// 3 reserved for AdNav57// 4 reserved for CINS58// 6 reserved for Trimble59#if AP_EXTERNAL_AHRS_MICROSTRAIN7_ENABLED60MicroStrain7 = 7,61#endif62#if AP_EXTERNAL_AHRS_SBG_ENABLED63SBG = 8,64#endif65// 9 reserved for EulerNav66// 10 reserved for Aeron67};6869static AP_ExternalAHRS *get_singleton(void) {70return _singleton;71}7273// expected IMU rate in Hz74float get_IMU_rate(void) const {75return rate.get();76}7778// Get model/type name79const char* get_name() const;8081enum class AvailableSensor {82GPS = (1U<<0),83IMU = (1U<<1),84BARO = (1U<<2),85COMPASS = (1U<<3),86};8788// get serial port number, -1 for not enabled89int8_t get_port(AvailableSensor sensor) const;9091struct state_t {92HAL_Semaphore sem;9394Vector3f accel;95Vector3f gyro;96Quaternion quat; // NED97Location location;98Vector3f velocity;99Location origin;100101bool have_quaternion;102bool have_origin;103bool have_location;104bool have_velocity;105106uint32_t last_location_update_us;107} state;108109// accessors for AP_AHRS110bool enabled() const;111bool healthy(void) const;112bool initialised(void) const;113bool get_quaternion(Quaternion &quat);114bool get_origin(Location &loc);115bool set_origin(const Location &loc);116bool get_location(Location &loc);117Vector2f get_groundspeed_vector();118bool get_velocity_NED(Vector3f &vel);119bool get_speed_down(float &speedD);120bool pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const;121void get_filter_status(nav_filter_status &status) const;122bool get_gyro(Vector3f &gyro);123bool get_accel(Vector3f &accel);124void send_status_report(class GCS_MAVLINK &link) const;125bool get_variances(float &velVar, float &posVar, float &hgtVar, Vector3f &magVar, float &tasVar) const;126127// update backend128void update();129130/*131structures passed to other subsystems132*/133typedef struct {134uint8_t instance;135float pressure_pa;136float temperature;137} baro_data_message_t;138139typedef struct {140Vector3f field;141} mag_data_message_t;142143typedef struct {144uint16_t gps_week;145uint32_t ms_tow;146AP_GPS_FixType fix_type;147uint8_t satellites_in_view;148float horizontal_pos_accuracy;149float vertical_pos_accuracy;150float horizontal_vel_accuracy;151float hdop;152float vdop;153int32_t longitude;154int32_t latitude;155int32_t msl_altitude; // cm156float ned_vel_north;157float ned_vel_east;158float ned_vel_down;159} gps_data_message_t;160161typedef struct {162Vector3f accel;163Vector3f gyro;164float temperature;165} ins_data_message_t;166167typedef struct {168float differential_pressure; // Pa169float temperature; // degC170} airspeed_data_message_t;171172// set GNSS disable for auxillary function GPS_DISABLE173void set_gnss_disable(bool disable) {174gnss_is_disabled = disable;175}176177protected:178179enum class OPTIONS {180VN_UNCOMP_IMU = 1U << 0,181SBG_EKF_AS_GNSS = 1U << 1,182};183bool option_is_set(OPTIONS option) const { return (options.get() & int32_t(option)) != 0; }184185private:186AP_ExternalAHRS_backend *backend;187188AP_Enum<DevType> devtype;189AP_Int16 rate;190AP_Int16 log_rate;191AP_Int16 options;192AP_Int16 sensors;193194static AP_ExternalAHRS *_singleton;195196// check if a sensor type is enabled197bool has_sensor(AvailableSensor sensor) const {198return (uint16_t(sensors.get()) & uint16_t(sensor)) != 0;199}200201// set default of EAHRS_SENSORS202void set_default_sensors(uint16_t _sensors) {203sensors.set_default(_sensors);204}205206uint32_t last_log_ms;207208// true when user has disabled the GNSS209bool gnss_is_disabled;210};211212namespace AP {213AP_ExternalAHRS &externalAHRS();214};215216#endif // AP_EXTERNAL_AHRS_ENABLED217218219220