mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-01 20:24:08 +08:00
Add test for gps projection & reprojections
This commit is contained in:
parent
fa5a00d871
commit
a013bb9314
@ -50,6 +50,7 @@ set(SRCS
|
||||
test_EKF_withReplayData.cpp
|
||||
test_EKF_flow.cpp
|
||||
test_SensorRangeFinder.cpp
|
||||
test_geo.cpp
|
||||
)
|
||||
add_executable(ECL_GTESTS ${SRCS})
|
||||
|
||||
|
||||
97
test/test_geo.cpp
Normal file
97
test/test_geo.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <math.h>
|
||||
#include <mathlib/mathlib.h>
|
||||
#include <memory>
|
||||
#include <geo/geo.h>
|
||||
|
||||
class GeoTest : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
origin.timestamp = 0;
|
||||
origin.lat_rad = math::radians(473566094 / 1e7);
|
||||
origin.lon_rad = math::radians(85190237 / 1e7);
|
||||
origin.sin_lat = sin(origin.lat_rad);
|
||||
origin.cos_lat = cos(origin.lat_rad);
|
||||
origin.init_done = true;
|
||||
}
|
||||
|
||||
protected:
|
||||
map_projection_reference_s origin;
|
||||
|
||||
};
|
||||
|
||||
|
||||
TEST_F(GeoTest, reprojectProject)
|
||||
{
|
||||
// GIVEN: x and y coordinates in the local cartesian frame
|
||||
float x = 0.5;
|
||||
float y = 1;
|
||||
double lat;
|
||||
double lon;
|
||||
map_projection_reproject(&origin, x, y, &lat, &lon);
|
||||
float x_new;
|
||||
float y_new;
|
||||
map_projection_project(&origin, lat, lon, &x_new, &y_new);
|
||||
double lat_new;
|
||||
double lon_new;
|
||||
map_projection_reproject(&origin, x_new, y_new, &lat_new, &lon_new);
|
||||
EXPECT_FLOAT_EQ(x, x_new);
|
||||
EXPECT_FLOAT_EQ(y, y_new);
|
||||
EXPECT_FLOAT_EQ(lat, lat_new);
|
||||
EXPECT_FLOAT_EQ(lon, lon_new);
|
||||
}
|
||||
|
||||
TEST_F(GeoTest, projectReproject)
|
||||
{
|
||||
// GIVEN: x and y coordinates in the local cartesian frame
|
||||
double lat = 47.356616973876953;
|
||||
double lon = 8.5190505981445313;
|
||||
float x;
|
||||
float y;
|
||||
map_projection_project(&origin, lat, lon, &x, &y);
|
||||
double lat_new;
|
||||
double lon_new;
|
||||
map_projection_reproject(&origin, x, y, &lat_new, &lon_new);
|
||||
float x_new;
|
||||
float y_new;
|
||||
map_projection_project(&origin, lat_new, lon_new, &x_new, &y_new);
|
||||
// WHEN: apply the mapping and its inverse the output should stay the same
|
||||
EXPECT_FLOAT_EQ(x, x_new);
|
||||
EXPECT_FLOAT_EQ(y, y_new);
|
||||
EXPECT_FLOAT_EQ(lat, lat_new);
|
||||
EXPECT_FLOAT_EQ(lon, lon_new);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user