test_beam_model.cpp
Go to the documentation of this file.
1 // Copyright 2023 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 
17 #include <utility>
18 #include <vector>
19 
22 
23 namespace beluga {
24 
26 
28 
30  BeamModelParam ret;
31  ret.z_hit = 0.5;
32  ret.z_short = 0.05;
33  ret.z_max = 0.05;
34  ret.z_rand = 0.5;
35  ret.sigma_hit = 0.2;
36  ret.lambda_short = 0.1;
37  ret.beam_max_range = 60;
38  return ret;
39 }
40 TEST(BeamSensorModel, ImportanceWeight) {
41  constexpr double kResolution = 0.5;
42  // clang-format off
43  const auto grid = StaticOccupancyGrid<5, 5>{{
44  false, false, false, false, false,
45  false, false, false, false, false,
46  false, false, true , false, false,
47  false, false, false, false, false,
48  false, false, false, false, false},
49  kResolution};
50  // clang-format on
51 
52  const auto params = GetParams();
53  auto sensor_model = UUT{params, grid};
54 
55  // Perfect hit.
56  {
57  auto state_weighting_function = sensor_model(std::vector<std::pair<double, double>>{{1., 1.}});
58  EXPECT_NEAR(1.0171643824743635, state_weighting_function(grid.origin()), 1e-6);
59  }
60 
61  // This is a hit that's before the obstacle, hence is affected by the unexpected obstacle part of the distribution.
62  {
63  auto state_weighting_function = sensor_model(std::vector<std::pair<double, double>>{{0.75, 0.75}});
64  EXPECT_NEAR(0.015905891701088148, state_weighting_function(grid.origin()), 1e-6);
65  }
66 
67  // Hit that's past the obstacle, hence is not affected by the unexpected obstacle part of the distribution.
68  // This should be really close to zero.
69 
70  {
71  auto state_weighting_function = sensor_model(std::vector<std::pair<double, double>>{{2.25, 2.25}});
72  EXPECT_NEAR(0.000, state_weighting_function(grid.origin()), 1e-6);
73  }
74 
75  // Range return longer than beam_max_range, so the max measurement distribution kicks in and this shouldn't be
76  // zero.
77  {
78  auto state_weighting_function =
79  sensor_model(std::vector<std::pair<double, double>>{{params.beam_max_range, params.beam_max_range}});
80  EXPECT_NEAR(0.00012500000000000003, state_weighting_function(grid.origin()), 1e-6);
81  }
82 }
83 
84 TEST(BeamSensorModel, GridUpdates) {
85  const auto origin = Sophus::SE2d{};
86 
87  constexpr double kResolution = 0.5;
88  // clang-format off
89  auto grid = StaticOccupancyGrid<5, 5>{{
90  false, false, false, false, false,
91  false, false, false, false, false,
92  false, false, true , false, false,
93  false, false, false, false, false,
94  false, false, false, false, false},
95  kResolution, origin};
96  // clang-format on
97 
98  const auto params = GetParams();
99  auto sensor_model = UUT{params, std::move(grid)};
100 
101  {
102  auto state_weighting_function = sensor_model(std::vector<std::pair<double, double>>{{1., 1.}});
103  EXPECT_NEAR(1.0171643824743635, state_weighting_function(origin), 1e-6);
104  }
105 
106  // clang-format off
108  false, false, false, false, false,
109  false, false, false, false, false,
110  false, false, false, false, false,
111  false, false, false, false, false,
112  false, false, false, false, false},
113  kResolution, origin};
114  // clang-format on
115 
116  sensor_model.update_map(std::move(grid));
117 
118  {
119  auto state_weighting_function = sensor_model(std::vector<std::pair<double, double>>{{1., 1.}});
120  EXPECT_NEAR(0.0, state_weighting_function(origin), 1e-3);
121  }
122 }
123 
124 } // namespace beluga
beluga::BeamModelParam::z_rand
double z_rand
Weight associated with random readings.
Definition: beam_model.hpp:50
beluga::BeamModelParam::lambda_short
double lambda_short
Intrinsic parameter assoaciated with short readings distribution.
Definition: beam_model.hpp:54
beam_model.hpp
Implementation of a beam sensor model for range finders.
static_occupancy_grid.hpp
beluga::BeamModelParam::z_hit
double z_hit
Weight associated with good but noisy readings.
Definition: beam_model.hpp:44
beluga::BeamModelParam::beam_max_range
double beam_max_range
Maximum beam range. This is the expected value in case of a miss.
Definition: beam_model.hpp:56
Sophus::SE2
beluga::testing::StaticOccupancyGrid
Definition: static_occupancy_grid.hpp:28
beluga::BeamModelParam::z_short
double z_short
Weight associated with unexpected obstacles.
Definition: beam_model.hpp:46
beluga::BeamModelParam::z_max
double z_max
Weight associated with max range readings.
Definition: beam_model.hpp:48
beluga::BeamModelParam::sigma_hit
double sigma_hit
Standard deviation of the gaussian noise associated with hits.
Definition: beam_model.hpp:52
beluga::BeamSensorModel
Beam sensor model for range finders.
Definition: beam_model.hpp:75
beluga::GetParams
BeamModelParam GetParams()
Definition: test_beam_model.cpp:29
beluga::BeamModelParam
Parameters used to construct a BeamSensorModel instance.
Definition: beam_model.hpp:42
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53