mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 07:43:37 +08:00
ekf2-fake pos: add valid fake position fusion
This is similar to fake pos but is only used when the ekf has an external information telling it that the vehicle is not changing position. This information can then be used to keep a valid local position even when the vehicle isn't exactly at rest.
This commit is contained in:
committed by
Mathieu Bresciani
parent
64b0586dad
commit
1a0f97ebbd
@@ -40,6 +40,7 @@ px4_add_unit_gtest(SRC test_EKF_accelerometer.cpp LINKLIBS ecl_EKF ecl_sensor_si
|
||||
px4_add_unit_gtest(SRC test_EKF_airspeed.cpp LINKLIBS ecl_EKF ecl_sensor_sim)
|
||||
px4_add_unit_gtest(SRC test_EKF_basics.cpp LINKLIBS ecl_EKF ecl_sensor_sim)
|
||||
px4_add_unit_gtest(SRC test_EKF_externalVision.cpp LINKLIBS ecl_EKF ecl_sensor_sim ecl_test_helper)
|
||||
px4_add_unit_gtest(SRC test_EKF_fake_pos.cpp LINKLIBS ecl_EKF ecl_sensor_sim ecl_test_helper)
|
||||
px4_add_unit_gtest(SRC test_EKF_flow.cpp LINKLIBS ecl_EKF ecl_sensor_sim ecl_test_helper)
|
||||
px4_add_unit_gtest(SRC test_EKF_flow_generated.cpp LINKLIBS ecl_EKF ecl_sensor_sim ecl_test_helper)
|
||||
px4_add_unit_gtest(SRC test_EKF_gyroscope.cpp LINKLIBS ecl_EKF ecl_sensor_sim)
|
||||
|
||||
@@ -15,13 +15,18 @@ Airspeed::~Airspeed()
|
||||
|
||||
void Airspeed::send(uint64_t time)
|
||||
{
|
||||
if (_true_airspeed_data > FLT_EPSILON && _indicated_airspeed_data > FLT_EPSILON) {
|
||||
airspeedSample airspeed_sample;
|
||||
airspeed_sample.time_us = time;
|
||||
airspeed_sample.eas2tas = _true_airspeed_data / _indicated_airspeed_data;
|
||||
airspeed_sample.true_airspeed = _true_airspeed_data;
|
||||
_ekf->setAirspeedData(airspeed_sample);
|
||||
float ias2tas = 1.f;
|
||||
|
||||
if (PX4_ISFINITE(_indicated_airspeed_data)
|
||||
&& (_indicated_airspeed_data > FLT_EPSILON)) {
|
||||
ias2tas = _true_airspeed_data / _indicated_airspeed_data;
|
||||
}
|
||||
|
||||
airspeedSample airspeed_sample;
|
||||
airspeed_sample.time_us = time;
|
||||
airspeed_sample.eas2tas = ias2tas;
|
||||
airspeed_sample.true_airspeed = _true_airspeed_data;
|
||||
_ekf->setAirspeedData(airspeed_sample);
|
||||
}
|
||||
|
||||
void Airspeed::setData(float true_airspeed, float indicated_airspeed)
|
||||
|
||||
@@ -78,7 +78,6 @@ public:
|
||||
|
||||
TEST_F(EkfAirspeedTest, testWindVelocityEstimation)
|
||||
{
|
||||
|
||||
const Vector3f simulated_velocity_earth(0.0f, 1.5f, 0.0f);
|
||||
const Vector2f airspeed_body(2.4f, 0.0f);
|
||||
_ekf_wrapper.enableExternalVisionVelocityFusion();
|
||||
@@ -86,6 +85,9 @@ TEST_F(EkfAirspeedTest, testWindVelocityEstimation)
|
||||
_sensor_simulator._vio.setVelocityFrameToLocalNED();
|
||||
_sensor_simulator.startExternalVision();
|
||||
|
||||
// Let the EV fusion start first to reset the velocity estimate
|
||||
_sensor_simulator.runSeconds(0.5);
|
||||
|
||||
_ekf->set_in_air_status(true);
|
||||
_ekf->set_vehicle_at_rest(false);
|
||||
_ekf->set_is_fixed_wing(true);
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "EKF/ekf.h"
|
||||
#include "sensor_simulator/sensor_simulator.h"
|
||||
#include "sensor_simulator/ekf_wrapper.h"
|
||||
|
||||
|
||||
class EkfFakePosTest : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
|
||||
EkfFakePosTest(): ::testing::Test(),
|
||||
_ekf{std::make_shared<Ekf>()},
|
||||
_sensor_simulator(_ekf),
|
||||
_ekf_wrapper(_ekf),
|
||||
_quat_sim(Eulerf(0.0f, 0.0f, math::radians(45.0f))) {};
|
||||
|
||||
std::shared_ptr<Ekf> _ekf;
|
||||
SensorSimulator _sensor_simulator;
|
||||
EkfWrapper _ekf_wrapper;
|
||||
const Quatf _quat_sim;
|
||||
|
||||
// Setup the Ekf with synthetic measurements
|
||||
void SetUp() override
|
||||
{
|
||||
// run briefly to init, then manually set in air and at rest (default for a real vehicle)
|
||||
_ekf->init(0);
|
||||
_sensor_simulator.runSeconds(0.1);
|
||||
_ekf->set_in_air_status(false);
|
||||
_ekf->set_vehicle_at_rest(true);
|
||||
|
||||
_sensor_simulator.simulateOrientation(_quat_sim);
|
||||
_sensor_simulator.runSeconds(7);
|
||||
}
|
||||
|
||||
// Use this method to clean up any memory, network etc. after each test
|
||||
void TearDown() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(EkfFakePosTest, testValidFakePos)
|
||||
{
|
||||
_ekf->set_vehicle_at_rest(false);
|
||||
_ekf->set_constant_pos(true);
|
||||
_sensor_simulator.runSeconds(1);
|
||||
|
||||
EXPECT_EQ(1, (int) _ekf->control_status_flags().constant_pos);
|
||||
EXPECT_EQ(0, (int) _ekf->control_status_flags().fake_pos);
|
||||
EXPECT_EQ(1, (int) _ekf->control_status_flags().valid_fake_pos);
|
||||
}
|
||||
|
||||
TEST_F(EkfFakePosTest, testFakePosStopGnss)
|
||||
{
|
||||
_ekf->set_vehicle_at_rest(false);
|
||||
_ekf->set_constant_pos(true);
|
||||
_sensor_simulator.startGps();
|
||||
_sensor_simulator.runSeconds(12);
|
||||
|
||||
EXPECT_TRUE(_ekf_wrapper.isIntendingGpsFusion());
|
||||
EXPECT_EQ(1, (int) _ekf->control_status_flags().constant_pos);
|
||||
EXPECT_EQ(0, (int) _ekf->control_status_flags().fake_pos);
|
||||
EXPECT_EQ(0, (int) _ekf->control_status_flags().valid_fake_pos);
|
||||
}
|
||||
|
||||
TEST_F(EkfFakePosTest, testValidFakePosValidLocalPos)
|
||||
{
|
||||
_ekf->set_is_fixed_wing(true);
|
||||
_sensor_simulator.startAirspeedSensor();
|
||||
_sensor_simulator._airspeed.setData(-0.01f, 0.f); // airspeed close to 0
|
||||
_ekf_wrapper.enableBetaFusion();
|
||||
|
||||
// WHEN: the vehicle is not as rest but is known to be at a constant position
|
||||
_ekf->set_vehicle_at_rest(false);
|
||||
_ekf->set_constant_pos(true);
|
||||
_sensor_simulator.runSeconds(1);
|
||||
|
||||
// THEN: the valid fake position is fused
|
||||
EXPECT_EQ(1, (int) _ekf->control_status_flags().constant_pos);
|
||||
EXPECT_EQ(0, (int) _ekf->control_status_flags().fake_pos);
|
||||
EXPECT_EQ(1, (int) _ekf->control_status_flags().valid_fake_pos);
|
||||
|
||||
// AND: since airspeed is expected to provide wind-relative dead-reckoning after takeoff
|
||||
// the local position is considered valid
|
||||
_sensor_simulator.runSeconds(60);
|
||||
|
||||
EXPECT_EQ(1, (int) _ekf->control_status_flags().valid_fake_pos);
|
||||
EXPECT_TRUE(_ekf->local_position_is_valid());
|
||||
}
|
||||
Reference in New Issue
Block a user