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/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
suppport for serial connected AHRS systems
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AP_ExternalAHRS.h"
|
2021-03-24 03:24:01 -03:00
|
|
|
#include "AP_ExternalAHRS_VectorNav.h"
|
2020-12-27 22:04:13 -04:00
|
|
|
|
|
|
|
#if HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
|
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
|
|
|
|
// @Values: 0:None,1:VectorNav
|
|
|
|
// @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),
|
|
|
|
|
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
|
|
|
|
break;
|
2021-03-24 03:24:01 -03:00
|
|
|
case DevType::VecNav:
|
|
|
|
backend = new AP_ExternalAHRS_VectorNav(this, state);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Unsupported ExternalAHRS type %u", unsigned(devtype));
|
|
|
|
break;
|
2020-12-27 22:04:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 03:24:01 -03:00
|
|
|
// get serial port number for the uart, or -1 if not applicable
|
2020-12-27 22:04:13 -04:00
|
|
|
int8_t AP_ExternalAHRS::get_port(void) const
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (!backend) {
|
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
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
return backend && 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
|
|
|
|
void AP_ExternalAHRS::send_status_report(mavlink_channel_t chan) const
|
|
|
|
{
|
2021-03-24 03:24:01 -03:00
|
|
|
if (backend) {
|
|
|
|
backend->send_status_report(chan);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
|
|
|
|
AP_ExternalAHRS &externalAHRS()
|
|
|
|
{
|
|
|
|
return *AP_ExternalAHRS::get_singleton();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
|