2020-06-17 08:28:03 -03: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AP_NavEKF_Source.h"
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_DAL/AP_DAL.h>
|
2021-07-15 22:54:55 -03:00
|
|
|
#include <AP_Logger/AP_Logger.h>
|
2020-06-17 08:28:03 -03:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
const AP_Param::GroupInfo AP_NavEKF_Source::var_info[] = {
|
|
|
|
|
|
|
|
// @Param: 1_POSXY
|
|
|
|
// @DisplayName: Position Horizontal Source (Primary)
|
|
|
|
// @Description: Position Horizontal Source (Primary)
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("1_POSXY", 1, AP_NavEKF_Source, _source_set[0].posxy, (int8_t)AP_NavEKF_Source::SourceXY::GPS),
|
|
|
|
|
|
|
|
// @Param: 1_VELXY
|
|
|
|
// @DisplayName: Velocity Horizontal Source
|
|
|
|
// @Description: Velocity Horizontal Source
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 5:OpticalFlow, 6:ExternalNav, 7:WheelEncoder
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("1_VELXY", 2, AP_NavEKF_Source, _source_set[0].velxy, (int8_t)AP_NavEKF_Source::SourceXY::GPS),
|
|
|
|
|
|
|
|
// @Param: 1_POSZ
|
|
|
|
// @DisplayName: Position Vertical Source
|
|
|
|
// @Description: Position Vertical Source
|
|
|
|
// @Values: 0:None, 1:Baro, 2:RangeFinder, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("1_POSZ", 3, AP_NavEKF_Source, _source_set[0].posz, (int8_t)AP_NavEKF_Source::SourceZ::BARO),
|
|
|
|
|
|
|
|
// @Param: 1_VELZ
|
|
|
|
// @DisplayName: Velocity Vertical Source
|
|
|
|
// @Description: Velocity Vertical Source
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("1_VELZ", 4, AP_NavEKF_Source, _source_set[0].velz, (int8_t)AP_NavEKF_Source::SourceZ::GPS),
|
|
|
|
|
|
|
|
// @Param: 1_YAW
|
|
|
|
// @DisplayName: Yaw Source
|
|
|
|
// @Description: Yaw Source
|
2020-12-22 04:07:38 -04:00
|
|
|
// @Values: 0:None, 1:Compass, 2:GPS, 3:GPS with Compass Fallback, 6:ExternalNav, 8:GSF
|
2020-06-17 08:28:03 -03:00
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("1_YAW", 5, AP_NavEKF_Source, _source_set[0].yaw, (int8_t)AP_NavEKF_Source::SourceYaw::COMPASS),
|
|
|
|
|
|
|
|
#if AP_NAKEKF_SOURCE_SET_MAX >= 2
|
|
|
|
// @Param: 2_POSXY
|
|
|
|
// @DisplayName: Position Horizontal Source (Secondary)
|
|
|
|
// @Description: Position Horizontal Source (Secondary)
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("2_POSXY", 6, AP_NavEKF_Source, _source_set[1].posxy, (int8_t)AP_NavEKF_Source::SourceXY::NONE),
|
|
|
|
|
|
|
|
// @Param: 2_VELXY
|
|
|
|
// @DisplayName: Velocity Horizontal Source (Secondary)
|
|
|
|
// @Description: Velocity Horizontal Source (Secondary)
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 5:OpticalFlow, 6:ExternalNav, 7:WheelEncoder
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("2_VELXY", 7, AP_NavEKF_Source, _source_set[1].velxy, (int8_t)AP_NavEKF_Source::SourceXY::NONE),
|
|
|
|
|
|
|
|
// @Param: 2_POSZ
|
|
|
|
// @DisplayName: Position Vertical Source (Secondary)
|
|
|
|
// @Description: Position Vertical Source (Secondary)
|
|
|
|
// @Values: 0:None, 1:Baro, 2:RangeFinder, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("2_POSZ", 8, AP_NavEKF_Source, _source_set[1].posz, (int8_t)AP_NavEKF_Source::SourceZ::BARO),
|
|
|
|
|
|
|
|
// @Param: 2_VELZ
|
|
|
|
// @DisplayName: Velocity Vertical Source (Secondary)
|
|
|
|
// @Description: Velocity Vertical Source (Secondary)
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("2_VELZ", 9, AP_NavEKF_Source, _source_set[1].velz, (int8_t)AP_NavEKF_Source::SourceZ::NONE),
|
|
|
|
|
|
|
|
// @Param: 2_YAW
|
|
|
|
// @DisplayName: Yaw Source (Secondary)
|
|
|
|
// @Description: Yaw Source (Secondary)
|
2020-12-22 04:07:38 -04:00
|
|
|
// @Values: 0:None, 1:Compass, 2:GPS, 3:GPS with Compass Fallback, 6:ExternalNav, 8:GSF
|
2020-06-17 08:28:03 -03:00
|
|
|
// @User: Advanced
|
2020-11-23 23:47:25 -04:00
|
|
|
AP_GROUPINFO("2_YAW", 10, AP_NavEKF_Source, _source_set[1].yaw, (int8_t)AP_NavEKF_Source::SourceYaw::NONE),
|
2020-06-17 08:28:03 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_NAKEKF_SOURCE_SET_MAX >= 3
|
|
|
|
// @Param: 3_POSXY
|
|
|
|
// @DisplayName: Position Horizontal Source (Tertiary)
|
|
|
|
// @Description: Position Horizontal Source (Tertiary)
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("3_POSXY", 11, AP_NavEKF_Source, _source_set[2].posxy, (int8_t)AP_NavEKF_Source::SourceXY::NONE),
|
|
|
|
|
|
|
|
// @Param: 3_VELXY
|
|
|
|
// @DisplayName: Velocity Horizontal Source (Tertiary)
|
|
|
|
// @Description: Velocity Horizontal Source (Tertiary)
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 5:OpticalFlow, 6:ExternalNav, 7:WheelEncoder
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("3_VELXY", 12, AP_NavEKF_Source, _source_set[2].velxy, (int8_t)AP_NavEKF_Source::SourceXY::NONE),
|
|
|
|
|
|
|
|
// @Param: 3_POSZ
|
|
|
|
// @DisplayName: Position Vertical Source (Tertiary)
|
|
|
|
// @Description: Position Vertical Source (Tertiary)
|
|
|
|
// @Values: 0:None, 1:Baro, 2:RangeFinder, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("3_POSZ", 13, AP_NavEKF_Source, _source_set[2].posz, (int8_t)AP_NavEKF_Source::SourceZ::BARO),
|
|
|
|
|
|
|
|
// @Param: 3_VELZ
|
|
|
|
// @DisplayName: Velocity Vertical Source (Tertiary)
|
|
|
|
// @Description: Velocity Vertical Source (Tertiary)
|
|
|
|
// @Values: 0:None, 3:GPS, 4:Beacon, 6:ExternalNav
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("3_VELZ", 14, AP_NavEKF_Source, _source_set[2].velz, (int8_t)AP_NavEKF_Source::SourceZ::NONE),
|
|
|
|
|
|
|
|
// @Param: 3_YAW
|
|
|
|
// @DisplayName: Yaw Source (Tertiary)
|
|
|
|
// @Description: Yaw Source (Tertiary)
|
2020-12-22 04:07:38 -04:00
|
|
|
// @Values: 0:None, 1:Compass, 2:GPS, 3:GPS with Compass Fallback, 6:ExternalNav, 8:GSF
|
2020-06-17 08:28:03 -03:00
|
|
|
// @User: Advanced
|
2020-11-23 23:47:25 -04:00
|
|
|
AP_GROUPINFO("3_YAW", 15, AP_NavEKF_Source, _source_set[2].yaw, (int8_t)AP_NavEKF_Source::SourceYaw::NONE),
|
2020-06-17 08:28:03 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// @Param: _OPTIONS
|
|
|
|
// @DisplayName: EKF Source Options
|
|
|
|
// @Description: EKF Source Options
|
|
|
|
// @Bitmask: 0:FuseAllVelocities
|
|
|
|
// @User: Advanced
|
2020-11-19 23:10:07 -04:00
|
|
|
AP_GROUPINFO("_OPTIONS", 16, AP_NavEKF_Source, _options, (int16_t)SourceOptions::FUSE_ALL_VELOCITIES),
|
2020-06-17 08:28:03 -03:00
|
|
|
|
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
|
|
|
AP_NavEKF_Source::AP_NavEKF_Source()
|
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set position, velocity and yaw sources to either 0=primary, 1=secondary, 2=tertiary
|
|
|
|
void AP_NavEKF_Source::setPosVelYawSourceSet(uint8_t source_set_idx)
|
|
|
|
{
|
|
|
|
// sanity check source idx
|
2020-12-15 06:59:15 -04:00
|
|
|
if (source_set_idx < AP_NAKEKF_SOURCE_SET_MAX) {
|
|
|
|
active_source_set = source_set_idx;
|
2021-07-15 22:54:55 -03:00
|
|
|
static const LogEvent evt[AP_NAKEKF_SOURCE_SET_MAX] {
|
|
|
|
LogEvent::EK3_SOURCES_SET_TO_PRIMARY,
|
|
|
|
LogEvent::EK3_SOURCES_SET_TO_SECONDARY,
|
|
|
|
LogEvent::EK3_SOURCES_SET_TO_TERTIARY,
|
|
|
|
};
|
|
|
|
AP::logger().Write_Event(evt[active_source_set]);
|
2020-06-17 08:28:03 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// true/false of whether velocity source should be used
|
|
|
|
bool AP_NavEKF_Source::useVelXYSource(SourceXY velxy_source) const
|
|
|
|
{
|
2020-12-15 06:59:15 -04:00
|
|
|
if (velxy_source == _source_set[active_source_set].velxy) {
|
2020-06-17 08:28:03 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for fuse all velocities
|
|
|
|
if (_options.get() & (uint16_t)(SourceOptions::FUSE_ALL_VELOCITIES)) {
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
2020-12-15 06:48:52 -04:00
|
|
|
if (_source_set[i].velxy == velxy_source) {
|
2020-06-17 08:28:03 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got this far source should not be used
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_NavEKF_Source::useVelZSource(SourceZ velz_source) const
|
|
|
|
{
|
2020-12-15 06:59:15 -04:00
|
|
|
if (velz_source == _source_set[active_source_set].velz) {
|
2020-06-17 08:28:03 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for fuse all velocities
|
|
|
|
if (_options.get() & (uint16_t)(SourceOptions::FUSE_ALL_VELOCITIES)) {
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
2020-12-15 06:48:52 -04:00
|
|
|
if (_source_set[i].velz == velz_source) {
|
2020-06-17 08:28:03 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got this far source should not be used
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// true if a velocity source is configured
|
|
|
|
bool AP_NavEKF_Source::haveVelZSource() const
|
|
|
|
{
|
2020-12-15 06:59:15 -04:00
|
|
|
if (_source_set[active_source_set].velz != SourceZ::NONE) {
|
2020-06-17 08:28:03 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for fuse all velocities
|
|
|
|
if (_options.get() & (uint16_t)(SourceOptions::FUSE_ALL_VELOCITIES)) {
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
2020-12-15 06:48:52 -04:00
|
|
|
if (_source_set[i].velz != SourceZ::NONE) {
|
2020-06-17 08:28:03 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got this far no velocity z source has been configured
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-17 03:26:51 -04:00
|
|
|
// get yaw source
|
|
|
|
AP_NavEKF_Source::SourceYaw AP_NavEKF_Source::getYawSource() const
|
|
|
|
{
|
|
|
|
// check for special case of disabled compasses
|
|
|
|
if ((_source_set[active_source_set].yaw == SourceYaw::COMPASS) && (AP::dal().compass().get_num_enabled() == 0)) {
|
|
|
|
return SourceYaw::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _source_set[active_source_set].yaw;
|
|
|
|
}
|
|
|
|
|
2020-06-17 08:28:03 -03:00
|
|
|
// align position of inactive sources to ahrs
|
|
|
|
void AP_NavEKF_Source::align_inactive_sources()
|
|
|
|
{
|
|
|
|
// align visual odometry
|
|
|
|
#if HAL_VISUALODOM_ENABLED
|
|
|
|
|
|
|
|
auto *visual_odom = AP::dal().visualodom();
|
|
|
|
if (!visual_odom || !visual_odom->enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// consider aligning XY position:
|
|
|
|
bool align_posxy = false;
|
|
|
|
if ((getPosXYSource() == SourceXY::GPS) ||
|
|
|
|
(getPosXYSource() == SourceXY::BEACON)) {
|
|
|
|
// only align position if active source is GPS or Beacon
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
2020-12-15 06:48:52 -04:00
|
|
|
if (_source_set[i].posxy == SourceXY::EXTNAV) {
|
2020-06-17 08:28:03 -03:00
|
|
|
// ExtNav could potentially be used, so align it
|
|
|
|
align_posxy = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// consider aligning Z position:
|
|
|
|
bool align_posz = false;
|
|
|
|
if ((getPosZSource() == SourceZ::BARO) ||
|
|
|
|
(getPosZSource() == SourceZ::RANGEFINDER) ||
|
|
|
|
(getPosZSource() == SourceZ::GPS) ||
|
|
|
|
(getPosZSource() == SourceZ::BEACON)) {
|
|
|
|
// ExtNav is not the active source; we do not want to align active source!
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
2020-12-15 06:48:52 -04:00
|
|
|
if (_source_set[i].posz == SourceZ::EXTNAV) {
|
2020-06-17 08:28:03 -03:00
|
|
|
// ExtNav could potentially be used, so align it
|
|
|
|
align_posz = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
visual_odom->align_position_to_ahrs(align_posxy, align_posz);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// sensor specific helper functions
|
|
|
|
bool AP_NavEKF_Source::usingGPS() const
|
|
|
|
{
|
|
|
|
return getPosXYSource() == SourceXY::GPS ||
|
|
|
|
getPosZSource() == SourceZ::GPS ||
|
|
|
|
getVelXYSource() == SourceXY::GPS ||
|
2020-12-22 03:15:21 -04:00
|
|
|
getVelZSource() == SourceZ::GPS ||
|
|
|
|
getYawSource() == SourceYaw::GSF;
|
2020-06-17 08:28:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// true if some parameters have been configured (used during parameter conversion)
|
2020-11-22 21:27:46 -04:00
|
|
|
bool AP_NavEKF_Source::configured_in_storage()
|
2020-06-17 08:28:03 -03:00
|
|
|
{
|
2020-11-22 21:27:46 -04:00
|
|
|
if (config_in_storage) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:34:09 -04:00
|
|
|
// first source parameter is used to determine if configured or not
|
2020-11-22 21:27:46 -04:00
|
|
|
config_in_storage = _source_set[0].posxy.configured_in_storage();
|
|
|
|
|
|
|
|
return config_in_storage;
|
2020-11-19 23:34:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// mark parameters as configured in storage (used to ensure parameter conversion is only done once)
|
|
|
|
void AP_NavEKF_Source::mark_configured_in_storage()
|
|
|
|
{
|
|
|
|
// save first parameter's current value to mark as configured
|
|
|
|
return _source_set[0].posxy.save(true);
|
2020-06-17 08:28:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns false if we fail arming checks, in which case the buffer will be populated with a failure message
|
2021-08-02 12:42:42 -03:00
|
|
|
// requires_position should be true if vertical or horizontal position configuration should be checked
|
2021-01-20 23:42:47 -04:00
|
|
|
bool AP_NavEKF_Source::pre_arm_check(bool requires_position, char *failure_msg, uint8_t failure_msg_len) const
|
2020-06-17 08:28:03 -03:00
|
|
|
{
|
|
|
|
auto &dal = AP::dal();
|
|
|
|
bool baro_required = false;
|
|
|
|
bool beacon_required = false;
|
|
|
|
bool compass_required = false;
|
|
|
|
bool gps_required = false;
|
|
|
|
bool rangefinder_required = false;
|
|
|
|
bool visualodom_required = false;
|
|
|
|
bool optflow_required = false;
|
2020-11-27 04:21:34 -04:00
|
|
|
bool wheelencoder_required = false;
|
2020-06-17 08:28:03 -03:00
|
|
|
|
|
|
|
// check source params are valid
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
|
|
|
|
2021-01-20 23:42:47 -04:00
|
|
|
if (requires_position) {
|
|
|
|
// check posxy
|
|
|
|
switch ((SourceXY)_source_set[i].posxy.get()) {
|
|
|
|
case SourceXY::NONE:
|
|
|
|
break;
|
|
|
|
case SourceXY::GPS:
|
|
|
|
gps_required = true;
|
|
|
|
break;
|
|
|
|
case SourceXY::BEACON:
|
|
|
|
beacon_required = true;
|
|
|
|
break;
|
|
|
|
case SourceXY::EXTNAV:
|
|
|
|
visualodom_required = true;
|
|
|
|
break;
|
|
|
|
case SourceXY::OPTFLOW:
|
|
|
|
case SourceXY::WHEEL_ENCODER:
|
|
|
|
default:
|
|
|
|
// invalid posxy value
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, "Check EK3_SRC%d_POSXY", (int)i+1);
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-17 08:28:03 -03:00
|
|
|
|
2021-01-20 23:42:47 -04:00
|
|
|
// check velxy
|
|
|
|
switch ((SourceXY)_source_set[i].velxy.get()) {
|
|
|
|
case SourceXY::NONE:
|
|
|
|
break;
|
|
|
|
case SourceXY::GPS:
|
|
|
|
gps_required = true;
|
|
|
|
break;
|
|
|
|
case SourceXY::OPTFLOW:
|
|
|
|
optflow_required = true;
|
|
|
|
break;
|
|
|
|
case SourceXY::EXTNAV:
|
|
|
|
visualodom_required = true;
|
|
|
|
break;
|
|
|
|
case SourceXY::WHEEL_ENCODER:
|
|
|
|
wheelencoder_required = true;
|
|
|
|
break;
|
|
|
|
case SourceXY::BEACON:
|
|
|
|
default:
|
|
|
|
// invalid velxy value
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, "Check EK3_SRC%d_VELXY", (int)i+1);
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-17 08:28:03 -03:00
|
|
|
|
2021-01-20 23:42:47 -04:00
|
|
|
// check posz
|
|
|
|
switch ((SourceZ)_source_set[i].posz.get()) {
|
|
|
|
case SourceZ::BARO:
|
|
|
|
baro_required = true;
|
|
|
|
break;
|
|
|
|
case SourceZ::RANGEFINDER:
|
|
|
|
rangefinder_required = true;
|
|
|
|
break;
|
|
|
|
case SourceZ::GPS:
|
|
|
|
gps_required = true;
|
|
|
|
break;
|
|
|
|
case SourceZ::BEACON:
|
|
|
|
beacon_required = true;
|
|
|
|
break;
|
|
|
|
case SourceZ::EXTNAV:
|
|
|
|
visualodom_required = true;
|
|
|
|
break;
|
|
|
|
case SourceZ::NONE:
|
|
|
|
default:
|
|
|
|
// invalid posz value
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, "Check EK3_SRC%d_POSZ", (int)i+1);
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-17 08:28:03 -03:00
|
|
|
|
2021-01-20 23:42:47 -04:00
|
|
|
// check velz
|
|
|
|
switch ((SourceZ)_source_set[i].velz.get()) {
|
|
|
|
case SourceZ::NONE:
|
|
|
|
break;
|
|
|
|
case SourceZ::GPS:
|
|
|
|
gps_required = true;
|
|
|
|
break;
|
|
|
|
case SourceZ::EXTNAV:
|
|
|
|
visualodom_required = true;
|
|
|
|
break;
|
|
|
|
case SourceZ::BARO:
|
|
|
|
case SourceZ::RANGEFINDER:
|
|
|
|
case SourceZ::BEACON:
|
|
|
|
default:
|
|
|
|
// invalid velz value
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, "Check EK3_SRC%d_VELZ", (int)i+1);
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-17 08:28:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// check yaw
|
|
|
|
switch ((SourceYaw)_source_set[i].yaw.get()) {
|
|
|
|
case SourceYaw::NONE:
|
2020-12-22 04:07:38 -04:00
|
|
|
case SourceYaw::GPS:
|
2020-06-17 08:28:03 -03:00
|
|
|
// valid yaw value
|
|
|
|
break;
|
2020-11-22 18:22:37 -04:00
|
|
|
case SourceYaw::COMPASS:
|
2020-12-17 04:11:38 -04:00
|
|
|
// skip compass check for easier user setup of compass-less operation
|
|
|
|
break;
|
2020-12-22 04:07:38 -04:00
|
|
|
case SourceYaw::GPS_COMPASS_FALLBACK:
|
2020-11-22 18:22:37 -04:00
|
|
|
compass_required = true;
|
|
|
|
break;
|
2020-11-30 08:32:01 -04:00
|
|
|
case SourceYaw::EXTNAV:
|
|
|
|
visualodom_required = true;
|
|
|
|
break;
|
2020-12-22 03:15:21 -04:00
|
|
|
case SourceYaw::GSF:
|
|
|
|
gps_required = true;
|
|
|
|
break;
|
2020-06-17 08:28:03 -03:00
|
|
|
default:
|
|
|
|
// invalid yaw value
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, "Check EK3_SRC%d_YAW", (int)i+1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check all required sensors are available
|
|
|
|
const char* ekf_requires_msg = "EK3 sources require %s";
|
|
|
|
if (baro_required && (dal.baro().num_instances() == 0)) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "Baro");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (beacon_required && (dal.beacon() == nullptr || !dal.beacon()->enabled())) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "Beacon");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-26 13:43:42 -04:00
|
|
|
if (compass_required && (dal.compass().get_num_enabled() == 0)) {
|
2020-06-17 08:28:03 -03:00
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "Compass");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gps_required && (dal.gps().num_sensors() == 0)) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "GPS");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optflow_required && !dal.opticalflow_enabled()) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "OpticalFlow");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rangefinder_required && (dal.rangefinder() == nullptr || !dal.rangefinder()->has_orientation(ROTATION_PITCH_270))) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "RangeFinder");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visualodom_required) {
|
|
|
|
bool visualodom_available = false;
|
|
|
|
#if HAL_VISUALODOM_ENABLED
|
|
|
|
auto *vo = AP::dal().visualodom();
|
|
|
|
visualodom_available = vo && vo->enabled();
|
|
|
|
#endif
|
|
|
|
if (!visualodom_available) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "VisualOdom");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 04:21:34 -04:00
|
|
|
if (wheelencoder_required && !dal.wheelencoder_enabled()) {
|
|
|
|
hal.util->snprintf(failure_msg, failure_msg_len, ekf_requires_msg, "WheelEncoder");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-17 08:28:03 -03:00
|
|
|
return true;
|
|
|
|
}
|
2020-11-26 18:37:13 -04:00
|
|
|
|
|
|
|
// return true if ext nav is enabled on any source
|
|
|
|
bool AP_NavEKF_Source::ext_nav_enabled(void) const
|
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
|
|
|
const auto &src = _source_set[i];
|
2020-12-15 06:48:52 -04:00
|
|
|
if (src.posxy == SourceXY::EXTNAV) {
|
2020-11-26 18:37:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-15 06:48:52 -04:00
|
|
|
if (src.posz == SourceZ::EXTNAV) {
|
2020-11-26 18:37:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-15 06:48:52 -04:00
|
|
|
if (src.velxy == SourceXY::EXTNAV) {
|
2020-11-26 18:37:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-15 06:48:52 -04:00
|
|
|
if (src.velz == SourceZ::EXTNAV) {
|
2020-11-26 18:37:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
2020-11-30 08:35:24 -04:00
|
|
|
if (src.yaw == SourceYaw::EXTNAV) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-26 18:37:13 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if wheel encoder is enabled on any source
|
|
|
|
bool AP_NavEKF_Source::wheel_encoder_enabled(void) const
|
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
|
|
|
const auto &src = _source_set[i];
|
2020-12-15 06:48:52 -04:00
|
|
|
if (src.velxy == SourceXY::WHEEL_ENCODER) {
|
2020-11-26 18:37:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-22 04:07:38 -04:00
|
|
|
// return true if GPS yaw is enabled on any source
|
|
|
|
bool AP_NavEKF_Source::gps_yaw_enabled(void) const
|
2020-11-26 18:37:13 -04:00
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<AP_NAKEKF_SOURCE_SET_MAX; i++) {
|
|
|
|
const auto &src = _source_set[i];
|
|
|
|
const SourceYaw yaw = SourceYaw(src.yaw.get());
|
2020-12-22 04:07:38 -04:00
|
|
|
if (yaw == SourceYaw::GPS ||
|
|
|
|
yaw == SourceYaw::GPS_COMPASS_FALLBACK) {
|
2020-11-26 18:37:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|