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
|
|
|
*/
|
|
|
|
|
2023-04-24 06:54:51 -03:00
|
|
|
#include "AP_ExternalAHRS_config.h"
|
|
|
|
|
|
|
|
#if HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
#include "AP_ExternalAHRS.h"
|
2023-04-24 06:54:51 -03:00
|
|
|
#include "AP_ExternalAHRS_backend.h"
|
2021-03-24 03:24:01 -03:00
|
|
|
#include "AP_ExternalAHRS_VectorNav.h"
|
2023-08-18 16:14:40 -03:00
|
|
|
#include "AP_ExternalAHRS_MicroStrain5.h"
|
2020-12-27 22:04:13 -04:00
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2020-12-27 22:04:13 -04:00
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
extern const AP_HAL::HAL &hal;
|
2020-12-27 22:04:13 -04:00
|
|
|
|
|
|
|
AP_ExternalAHRS *AP_ExternalAHRS::_singleton;
|
|
|
|
|
|
|
|
// constructor
|
|
|
|
AP_ExternalAHRS::AP_ExternalAHRS()
|
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
|
|
|
_singleton = this;
|
2021-02-06 02:24:39 -04:00
|
|
|
if (rate.get() < 50) {
|
|
|
|
// min 50Hz
|
|
|
|
rate.set(50);
|
|
|
|
}
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
2021-01-13 17:08:05 -04:00
|
|
|
#ifndef HAL_EXTERNAL_AHRS_DEFAULT
|
|
|
|
#define HAL_EXTERNAL_AHRS_DEFAULT 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
// table of user settable parameters
|
|
|
|
const AP_Param::GroupInfo AP_ExternalAHRS::var_info[] = {
|
|
|
|
|
|
|
|
// @Param: _TYPE
|
|
|
|
// @DisplayName: AHRS type
|
|
|
|
// @Description: Type of AHRS device
|
2023-08-04 18:30:29 -03:00
|
|
|
// @Values: 0:None,1:VectorNav,2:MicroStrain
|
2020-12-27 22:04:13 -04:00
|
|
|
// @User: Standard
|
2021-01-13 17:08:05 -04:00
|
|
|
AP_GROUPINFO_FLAGS("_TYPE", 1, AP_ExternalAHRS, devtype, HAL_EXTERNAL_AHRS_DEFAULT, AP_PARAM_FLAG_ENABLE),
|
2020-12-27 22:04:13 -04:00
|
|
|
|
2021-02-06 02:24:39 -04:00
|
|
|
// @Param: _RATE
|
|
|
|
// @DisplayName: AHRS data rate
|
|
|
|
// @Description: Requested rate for AHRS device
|
|
|
|
// @Units: Hz
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_RATE", 2, AP_ExternalAHRS, rate, 50),
|
2022-12-22 17:16:10 -04:00
|
|
|
|
|
|
|
// @Param: _OPTIONS
|
|
|
|
// @DisplayName: External AHRS options
|
|
|
|
// @Description: External AHRS options bitmask
|
|
|
|
// @Bitmask: 0:Vector Nav use uncompensated values for accel gyro and mag.
|
|
|
|
// @User: Standard
|
|
|
|
AP_GROUPINFO("_OPTIONS", 3, AP_ExternalAHRS, options, 0),
|
|
|
|
|
2023-01-24 00:39:49 -04:00
|
|
|
// @Param: _SENSORS
|
|
|
|
// @DisplayName: External AHRS sensors
|
|
|
|
// @Description: External AHRS sensors bitmask
|
|
|
|
// @Bitmask: 0:GPS,1:IMU,2:Baro,3:Compass
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("_SENSORS", 4, AP_ExternalAHRS, sensors, 0xF),
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void AP_ExternalAHRS::init(void)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (rate.get() < 50) {
|
|
|
|
// min 50Hz
|
|
|
|
rate.set(50);
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
switch (DevType(devtype)) {
|
2021-04-13 23:29:34 -03:00
|
|
|
case DevType::None:
|
|
|
|
// nothing to do
|
2023-08-26 00:07:54 -03:00
|
|
|
return;
|
2023-04-24 06:54:51 -03:00
|
|
|
#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED
|
2021-03-24 03:24:01 -03:00
|
|
|
case DevType::VecNav:
|
|
|
|
backend = new AP_ExternalAHRS_VectorNav(this, state);
|
2023-08-26 00:07:54 -03:00
|
|
|
return;
|
2023-04-24 06:54:51 -03:00
|
|
|
#endif
|
2023-08-18 16:14:40 -03:00
|
|
|
#if AP_EXTERNAL_AHRS_MICROSTRAIN5_ENABLED
|
|
|
|
case DevType::MicroStrain5:
|
|
|
|
backend = new AP_ExternalAHRS_MicroStrain5(this, state);
|
2023-08-26 00:07:54 -03:00
|
|
|
return;
|
2023-04-24 06:54:51 -03:00
|
|
|
#endif
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
2023-08-26 00:07:54 -03:00
|
|
|
|
|
|
|
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Unsupported ExternalAHRS type %u", unsigned(devtype));
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
2022-12-21 09:25:05 -04:00
|
|
|
bool AP_ExternalAHRS::enabled() const
|
|
|
|
{
|
|
|
|
return DevType(devtype) != DevType::None;
|
|
|
|
}
|
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
// get serial port number for the uart, or -1 if not applicable
|
2023-01-24 00:39:49 -04:00
|
|
|
int8_t AP_ExternalAHRS::get_port(AvailableSensor sensor) const
|
2020-12-27 22:04:13 -04:00
|
|
|
{
|
2023-01-24 00:39:49 -04:00
|
|
|
if (!backend || !has_sensor(sensor)) {
|
2020-12-27 22:04:13 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2021-03-24 03:24:01 -03:00
|
|
|
return backend->get_port();
|
2020-12-27 22:04:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// accessors for AP_AHRS
|
|
|
|
bool AP_ExternalAHRS::healthy(void) const
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
return backend && backend->healthy();
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
2021-02-01 12:26:27 -04:00
|
|
|
bool AP_ExternalAHRS::initialised(void) const
|
2020-12-27 22:04:13 -04:00
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
return backend && backend->initialised();
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_ExternalAHRS::get_quaternion(Quaternion &quat)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (state.have_quaternion) {
|
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
quat = state.quat;
|
|
|
|
return true;
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
2021-03-24 03:24:01 -03:00
|
|
|
return false;
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_ExternalAHRS::get_origin(Location &loc)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (state.have_origin) {
|
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
loc = state.origin;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_ExternalAHRS::get_location(Location &loc)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (!state.have_location) {
|
2020-12-27 22:04:13 -04:00
|
|
|
return false;
|
|
|
|
}
|
2021-03-24 03:24:01 -03:00
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
loc = state.location;
|
2020-12-27 22:04:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2f AP_ExternalAHRS::get_groundspeed_vector()
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
Vector2f vec{state.velocity.x, state.velocity.y};
|
|
|
|
return vec;
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_ExternalAHRS::get_velocity_NED(Vector3f &vel)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (!state.have_velocity) {
|
2020-12-27 22:04:13 -04:00
|
|
|
return false;
|
|
|
|
}
|
2021-03-24 03:24:01 -03:00
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
vel = state.velocity;
|
2020-12-27 22:04:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_ExternalAHRS::get_speed_down(float &speedD)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (!state.have_velocity) {
|
2020-12-27 22:04:13 -04:00
|
|
|
return false;
|
|
|
|
}
|
2021-03-24 03:24:01 -03:00
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
speedD = state.velocity.z;
|
2020-12-27 22:04:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_ExternalAHRS::pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const
|
|
|
|
{
|
2023-09-24 00:25:06 -03:00
|
|
|
if (backend == nullptr) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, "ExternalAHRS: Invalid backend");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return backend->pre_arm_check(failure_msg, failure_msg_len);
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-03-24 03:24:01 -03:00
|
|
|
get filter status
|
2020-12-27 22:04:13 -04:00
|
|
|
*/
|
|
|
|
void AP_ExternalAHRS::get_filter_status(nav_filter_status &status) const
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
status = {};
|
|
|
|
if (backend) {
|
|
|
|
backend->get_filter_status(status);
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3f AP_ExternalAHRS::get_gyro(void)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
return state.gyro;
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3f AP_ExternalAHRS::get_accel(void)
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
WITH_SEMAPHORE(state.sem);
|
|
|
|
return state.accel;
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// send an EKF_STATUS message to GCS
|
2022-07-08 01:15:35 -03:00
|
|
|
void AP_ExternalAHRS::send_status_report(GCS_MAVLINK &link) const
|
2020-12-27 22:04:13 -04:00
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (backend) {
|
2022-07-08 01:15:35 -03:00
|
|
|
backend->send_status_report(link);
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
2021-03-24 03:24:01 -03:00
|
|
|
}
|
2020-12-27 22:04:13 -04:00
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
void AP_ExternalAHRS::update(void)
|
|
|
|
{
|
|
|
|
if (backend) {
|
|
|
|
backend->update();
|
|
|
|
}
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
|
2022-12-21 11:51:42 -04:00
|
|
|
// Get model/type name
|
|
|
|
const char* AP_ExternalAHRS::get_name() const
|
|
|
|
{
|
|
|
|
if (backend) {
|
|
|
|
return backend->get_name();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-12-27 22:04:13 -04:00
|
|
|
namespace AP {
|
|
|
|
|
|
|
|
AP_ExternalAHRS &externalAHRS()
|
|
|
|
{
|
|
|
|
return *AP_ExternalAHRS::get_singleton();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
|