PX4 Firmware
PX4 Autopilot Software http://px4.io
PreFlightCheckerTest.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * Test code for PreFlightChecker class
36  * Run this test only using make tests TESTFILTER=PreFlightChecker
37  */
38 
39 #include <gtest/gtest.h>
40 
41 #include "PreFlightChecker.hpp"
42 
43 class PreFlightCheckerTest : public ::testing::Test
44 {
45 };
46 
47 TEST_F(PreFlightCheckerTest, testInnovFailed)
48 {
49  const float test_limit = 1.0; ///< is the limit for innovation_lpf, the limit for innovation is 2*test_limit
50  const float innovations[9] = {0.0, 1.5, 2.5, -1.5, -2.5, 1.5, -1.5, -2.5, -2.5};
51  const float innovations_lpf[9] = {0.0, 0.9, 0.9, -0.9, -0.9, 1.1, -1.1, -1.1, 1.1};
52  const bool expected_result[9] = {false, false, true, false, true, true, true, true, true};
53 
54  for (int i = 0; i < 9; i++) {
55  EXPECT_EQ(PreFlightChecker::checkInnovFailed(innovations[i], innovations_lpf[i], test_limit), expected_result[i]);
56  }
57 
58  // Smaller test limit, all the checks should fail except the first
59  EXPECT_FALSE(PreFlightChecker::checkInnovFailed(innovations[0], innovations_lpf[0], 0.0));
60 
61  for (int i = 1; i < 9; i++) {
62  EXPECT_TRUE(PreFlightChecker::checkInnovFailed(innovations[i], innovations_lpf[i], 0.0));
63  }
64 
65  // Larger test limit, none of the checks should fail
66  for (int i = 0; i < 9; i++) {
67  EXPECT_FALSE(PreFlightChecker::checkInnovFailed(innovations[i], innovations_lpf[i], 2.0));
68  }
69 }
70 
71 TEST_F(PreFlightCheckerTest, testInnov2dFailed)
72 {
73  const float test_limit = 1.0;
74  Vector2f innovations[4] = {{0.0, 0.0}, {0.0, 0.0}, {0.0, -2.5}, {1.5, -1.5}};
75  Vector2f innovations_lpf[4] = {{0.0, 0.0}, {1.1, 0.0}, {0.5, 0.5}, {1.0, -1.0}};
76  const bool expected_result[4] = {false, true, true, true};
77 
78  for (int i = 0; i < 4; i++) {
79  EXPECT_EQ(PreFlightChecker::checkInnov2DFailed(innovations[i], innovations_lpf[i], test_limit), expected_result[i]);
80  }
81 
82  // Smaller test limit, all the checks should fail except the first
83  EXPECT_FALSE(PreFlightChecker::checkInnov2DFailed(innovations[0], innovations_lpf[0], 0.0));
84 
85  for (int i = 1; i < 4; i++) {
86  EXPECT_TRUE(PreFlightChecker::checkInnov2DFailed(innovations[i], innovations_lpf[i], 0.0));
87  }
88 
89  // Larger test limit, none of the checks should fail
90  for (int i = 0; i < 4; i++) {
91  EXPECT_FALSE(PreFlightChecker::checkInnov2DFailed(innovations[i], innovations_lpf[i], 1.42));
92  }
93 }
static bool checkInnovFailed(float innov, float innov_lpf, float test_limit)
Vector2< float > Vector2f
Definition: Vector2.hpp:69
TEST_F(PreFlightCheckerTest, testInnovFailed)
Class handling the EKF2 innovation pre flight checks.
static bool checkInnov2DFailed(const Vector2f &innov, const Vector2f &innov_lpf, float test_limit)
Test code for PreFlightChecker class Run this test only using make tests TESTFILTER=PreFlightChecker...