2020-12-27 22:04:13 -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/>.
|
|
|
|
*/
|
|
|
|
/*
|
2023-10-11 04:41:52 -03:00
|
|
|
support for serial connected AHRS systems
|
2020-12-27 22:04:13 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-26 06:21:36 -03:00
|
|
|
#include "AP_ExternalAHRS_config.h"
|
|
|
|
|
|
|
|
#if HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Common/Location.h>
|
|
|
|
#include <AP_NavEKF/AP_Nav_Common.h>
|
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
class AP_ExternalAHRS_backend;
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
class AP_ExternalAHRS {
|
|
|
|
|
|
|
|
public:
|
2021-03-24 03:24:01 -03:00
|
|
|
friend class AP_ExternalAHRS_backend;
|
2022-12-22 17:16:10 -04:00
|
|
|
friend class AP_ExternalAHRS_VectorNav;
|
2021-03-24 03:24:01 -03:00
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
AP_ExternalAHRS();
|
|
|
|
|
|
|
|
void init(void);
|
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
enum class DevType : uint8_t {
|
|
|
|
None = 0,
|
2023-04-24 06:54:51 -03:00
|
|
|
#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED
|
2020-12-27 22:04:13 -04:00
|
|
|
VecNav = 1,
|
2023-04-24 06:54:51 -03:00
|
|
|
#endif
|
2023-08-18 16:14:40 -03:00
|
|
|
#if AP_EXTERNAL_AHRS_MICROSTRAIN5_ENABLED
|
|
|
|
MicroStrain5 = 2,
|
2023-04-24 06:54:51 -03:00
|
|
|
#endif
|
2023-11-29 16:43:11 -04:00
|
|
|
// 3 reserved for AdNav
|
|
|
|
// 4 reserved for CINS
|
|
|
|
// 5 reserved for InertialLabs
|
|
|
|
// 6 reserved for Trimble
|
2023-09-23 16:42:35 -03:00
|
|
|
#if AP_EXTERNAL_AHRS_MICROSTRAIN7_ENABLED
|
|
|
|
MicroStrain7 = 7,
|
|
|
|
#endif
|
2023-11-29 16:43:11 -04:00
|
|
|
// 8 reserved for SBG
|
|
|
|
// 9 reserved for EulerNav
|
2020-12-27 22:04:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static AP_ExternalAHRS *get_singleton(void) {
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
// expected IMU rate in Hz
|
2020-12-27 22:04:13 -04:00
|
|
|
float get_IMU_rate(void) const {
|
2021-02-06 02:24:39 -04:00
|
|
|
return rate.get();
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
2022-12-21 11:51:42 -04:00
|
|
|
// Get model/type name
|
|
|
|
const char* get_name() const;
|
|
|
|
|
2023-01-24 00:39:49 -04:00
|
|
|
enum class AvailableSensor {
|
|
|
|
GPS = (1U<<0),
|
|
|
|
IMU = (1U<<1),
|
|
|
|
BARO = (1U<<2),
|
|
|
|
COMPASS = (1U<<3),
|
|
|
|
};
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
// get serial port number, -1 for not enabled
|
2023-01-24 00:39:49 -04:00
|
|
|
int8_t get_port(AvailableSensor sensor) const;
|
2020-12-27 22:04:13 -04:00
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
struct state_t {
|
|
|
|
HAL_Semaphore sem;
|
|
|
|
|
|
|
|
Vector3f accel;
|
|
|
|
Vector3f gyro;
|
|
|
|
Quaternion quat;
|
|
|
|
Location location;
|
|
|
|
Vector3f velocity;
|
|
|
|
Location origin;
|
|
|
|
|
|
|
|
bool have_quaternion;
|
|
|
|
bool have_origin;
|
|
|
|
bool have_location;
|
|
|
|
bool have_velocity;
|
|
|
|
} state;
|
|
|
|
|
|
|
|
// accessors for AP_AHRS
|
2022-12-21 09:25:05 -04:00
|
|
|
bool enabled() const;
|
2021-03-24 03:24:01 -03:00
|
|
|
bool healthy(void) const;
|
|
|
|
bool initialised(void) const;
|
|
|
|
bool get_quaternion(Quaternion &quat);
|
|
|
|
bool get_origin(Location &loc);
|
|
|
|
bool get_location(Location &loc);
|
|
|
|
Vector2f get_groundspeed_vector();
|
|
|
|
bool get_velocity_NED(Vector3f &vel);
|
|
|
|
bool get_speed_down(float &speedD);
|
|
|
|
bool pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const;
|
|
|
|
void get_filter_status(nav_filter_status &status) const;
|
|
|
|
Vector3f get_gyro(void);
|
|
|
|
Vector3f get_accel(void);
|
2022-07-08 01:15:35 -03:00
|
|
|
void send_status_report(class GCS_MAVLINK &link) const;
|
2021-03-24 03:24:01 -03:00
|
|
|
|
|
|
|
// update backend
|
|
|
|
void update();
|
|
|
|
|
|
|
|
/*
|
|
|
|
structures passed to other subsystems
|
|
|
|
*/
|
2020-12-27 22:04:13 -04:00
|
|
|
typedef struct {
|
|
|
|
uint8_t instance;
|
|
|
|
float pressure_pa;
|
|
|
|
float temperature;
|
|
|
|
} baro_data_message_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Vector3f field;
|
|
|
|
} mag_data_message_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t gps_week; // GPS week, 0xFFFF if not available
|
|
|
|
uint32_t ms_tow;
|
|
|
|
uint8_t fix_type;
|
|
|
|
uint8_t satellites_in_view;
|
|
|
|
float horizontal_pos_accuracy;
|
|
|
|
float vertical_pos_accuracy;
|
|
|
|
float horizontal_vel_accuracy;
|
|
|
|
float hdop;
|
|
|
|
float vdop;
|
|
|
|
int32_t longitude;
|
|
|
|
int32_t latitude;
|
|
|
|
int32_t msl_altitude; // cm
|
|
|
|
float ned_vel_north;
|
|
|
|
float ned_vel_east;
|
|
|
|
float ned_vel_down;
|
|
|
|
} gps_data_message_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Vector3f accel;
|
|
|
|
Vector3f gyro;
|
|
|
|
float temperature;
|
|
|
|
} ins_data_message_t;
|
2022-12-22 17:16:10 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
enum class OPTIONS {
|
|
|
|
VN_UNCOMP_IMU = 1U << 0,
|
|
|
|
};
|
|
|
|
bool option_is_set(OPTIONS option) const { return (options.get() & int32_t(option)) != 0; }
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
private:
|
2021-03-24 03:24:01 -03:00
|
|
|
AP_ExternalAHRS_backend *backend;
|
2020-12-27 22:04:13 -04:00
|
|
|
|
|
|
|
AP_Enum<DevType> devtype;
|
2021-02-06 02:24:39 -04:00
|
|
|
AP_Int16 rate;
|
2022-12-22 17:16:10 -04:00
|
|
|
AP_Int16 options;
|
2023-01-24 00:39:49 -04:00
|
|
|
AP_Int16 sensors;
|
2020-12-27 22:04:13 -04:00
|
|
|
|
|
|
|
static AP_ExternalAHRS *_singleton;
|
2023-01-24 00:39:49 -04:00
|
|
|
|
|
|
|
// check if a sensor type is enabled
|
|
|
|
bool has_sensor(AvailableSensor sensor) const {
|
|
|
|
return (uint16_t(sensors.get()) & uint16_t(sensor)) != 0;
|
|
|
|
}
|
2020-12-27 22:04:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_ExternalAHRS &externalAHRS();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
|