Browse Source
* Refactor velocity reset * Add unit tests for velocity resets * Expand updates to vertical buffer to velocity resets outside of resetHeight * Improve matrix library usage * Improve naming of vertical output samples * Fix update of output_vert_new during reset * Improve naming of vertical output samples 2master
kritz
5 years ago
committed by
GitHub
13 changed files with 259 additions and 78 deletions
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* Copyright (c) 2019 ECL 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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
/**
|
||||
* Test the gps fusion |
||||
* @author Kamil Ritz <ka.ritz@hotmail.com> |
||||
*/ |
||||
|
||||
#include <gtest/gtest.h> |
||||
#include "EKF/ekf.h" |
||||
#include "sensor_simulator/sensor_simulator.h" |
||||
#include "sensor_simulator/ekf_wrapper.h" |
||||
|
||||
|
||||
class EkfFlowTest : public ::testing::Test { |
||||
public: |
||||
|
||||
EkfFlowTest(): ::testing::Test(), |
||||
_ekf{std::make_shared<Ekf>()}, |
||||
_sensor_simulator(_ekf), |
||||
_ekf_wrapper(_ekf) {}; |
||||
|
||||
std::shared_ptr<Ekf> _ekf; |
||||
SensorSimulator _sensor_simulator; |
||||
EkfWrapper _ekf_wrapper; |
||||
|
||||
// Setup the Ekf with synthetic measurements
|
||||
void SetUp() override |
||||
{ |
||||
_ekf->init(0); |
||||
_sensor_simulator.runSeconds(2); |
||||
} |
||||
|
||||
// Use this method to clean up any memory, network etc. after each test
|
||||
void TearDown() override |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
TEST_F(EkfFlowTest, resetToFlowVelocityInAir) |
||||
{ |
||||
// WHEN: simulate being 5m above ground
|
||||
const float simulated_distance_to_ground = 5.f; |
||||
_sensor_simulator._rng.setData(simulated_distance_to_ground, 100); |
||||
_sensor_simulator._rng.setLimits(0.1f, 9.f); |
||||
_sensor_simulator.startRangeFinder(); |
||||
_ekf->set_in_air_status(true); |
||||
_sensor_simulator.runSeconds(1.5f); |
||||
|
||||
const float estimated_distance_to_ground = _ekf->getTerrainVertPos(); |
||||
EXPECT_FLOAT_EQ(estimated_distance_to_ground, simulated_distance_to_ground); |
||||
|
||||
// WHEN: start fusing flow data
|
||||
const Vector2f simulated_horz_velocity(0.5f, -0.2f); |
||||
flowSample flow_sample = _sensor_simulator._flow.dataAtRest(); |
||||
flow_sample.flow_xy_rad = |
||||
Vector2f(- simulated_horz_velocity(1) * flow_sample.dt / estimated_distance_to_ground, |
||||
simulated_horz_velocity(0) * flow_sample.dt / estimated_distance_to_ground); |
||||
_sensor_simulator._flow.setData(flow_sample); |
||||
_ekf_wrapper.enableFlowFusion(); |
||||
_sensor_simulator.startFlow(); |
||||
_sensor_simulator.runSeconds(0.2); |
||||
|
||||
// THEN: estimated velocity should match simulated velocity
|
||||
const Vector2f estimated_horz_velocity = Vector2f(_ekf->getVelocity()); |
||||
EXPECT_FALSE(isEqual(estimated_horz_velocity, simulated_horz_velocity)); // TODO: This needs to change
|
||||
} |
||||
|
||||
TEST_F(EkfFlowTest, resetToFlowVelocityOnGround) |
||||
{ |
||||
// WHEN: being on ground
|
||||
const float estimated_distance_to_ground = _ekf->getTerrainVertPos(); |
||||
EXPECT_LT(estimated_distance_to_ground, 0.3f); |
||||
|
||||
// WHEN: start fusing flow data
|
||||
_ekf_wrapper.enableFlowFusion(); |
||||
_sensor_simulator.startFlow(); |
||||
_sensor_simulator.runSeconds(0.6); |
||||
|
||||
// THEN: estimated velocity should match simulated velocity
|
||||
const Vector2f estimated_horz_velocity = Vector2f(_ekf->getVelocity()); |
||||
EXPECT_TRUE(isEqual(estimated_horz_velocity, Vector2f(0.f, 0.f))); |
||||
} |
Loading…
Reference in new issue