-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathtest_amcl.cpp
More file actions
158 lines (136 loc) · 4.9 KB
/
Copy pathtest_amcl.cpp
File metadata and controls
158 lines (136 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright 2024 Ekumen, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <cstddef>
#include <cstdint>
#include <execution>
#include <memory>
#include <vector>
#include <Eigen/Core>
#if BELUGA_ROS_VERSION == 1
#include <boost/smart_ptr.hpp>
#endif
#include <beluga/motion/differential_drive_model.hpp>
#include <beluga/sensor/likelihood_field_model.hpp>
#include "beluga_ros/amcl.hpp"
#include "beluga_ros/laser_scan.hpp"
#include "beluga_ros/messages.hpp"
namespace {
auto make_dummy_occupancy_grid() {
constexpr std::size_t kWidth = 100;
constexpr std::size_t kHeight = 200;
#if BELUGA_ROS_VERSION == 2
auto message = std::make_shared<beluga_ros::msg::OccupancyGrid>();
#elif BELUGA_ROS_VERSION == 1
auto message = boost::make_shared<beluga_ros::msg::OccupancyGrid>();
#else
#error BELUGA_ROS_VERSION is not defined or invalid
#endif
message->info.resolution = 0.1F;
message->info.width = kWidth;
message->info.height = kHeight;
message->info.origin.position.x = 1;
message->info.origin.position.y = 2;
message->info.origin.position.z = 0;
message->data = std::vector<std::int8_t>(kWidth * kHeight);
return beluga_ros::OccupancyGrid{message};
}
auto make_dummy_laser_scan() {
#if BELUGA_ROS_VERSION == 2
auto message = std::make_shared<beluga_ros::msg::LaserScan>();
#elif BELUGA_ROS_VERSION == 1
auto message = boost::make_shared<beluga_ros::msg::LaserScan>();
#endif
message->ranges = std::vector<float>{1., 2., 3.};
message->range_min = 10.F;
message->range_max = 100.F;
return beluga_ros::LaserScan(message);
}
auto make_amcl() {
auto map = make_dummy_occupancy_grid();
auto params = beluga_ros::AmclParams{};
params.max_particles = 50UL;
return beluga_ros::Amcl{
map, //
beluga::DifferentialDriveModel{beluga::DifferentialDriveModelParam{}}, //
beluga::LikelihoodFieldModel{beluga::LikelihoodFieldModelParam{}, map}, //
params, //
std::execution::seq,
};
}
TEST(TestAmcl, InitializeWithNoParticles) {
auto amcl = make_amcl();
ASSERT_EQ(amcl.particles().size(), 0);
}
TEST(TestAmcl, InitializeFromMap) {
auto amcl = make_amcl();
amcl.initialize_from_map();
ASSERT_EQ(amcl.particles().size(), 50UL);
}
TEST(TestAmcl, InitializeFromPose) {
auto amcl = make_amcl();
amcl.initialize(Sophus::SE2d{}, Eigen::Vector3d::Ones().asDiagonal());
ASSERT_EQ(amcl.particles().size(), 50UL);
}
TEST(TestAmcl, UpdateWithNoParticles) {
auto amcl = make_amcl();
ASSERT_EQ(amcl.particles().size(), 0);
auto estimate = amcl.update(Sophus::SE2d{}, make_dummy_laser_scan());
ASSERT_FALSE(estimate.has_value());
}
TEST(TestAmcl, UpdateWithParticles) {
auto amcl = make_amcl();
ASSERT_EQ(amcl.particles().size(), 0);
amcl.initialize_from_map();
ASSERT_EQ(amcl.particles().size(), 50UL);
auto estimate = amcl.update(Sophus::SE2d{}, make_dummy_laser_scan());
ASSERT_TRUE(estimate.has_value());
}
TEST(TestAmcl, UpdateWithParticlesWithMotion) {
auto amcl = make_amcl();
ASSERT_EQ(amcl.particles().size(), 0);
amcl.initialize_from_map();
ASSERT_EQ(amcl.particles().size(), 50UL);
auto estimate = amcl.update(Sophus::SE2d{}, make_dummy_laser_scan());
ASSERT_TRUE(estimate.has_value());
estimate = amcl.update(Sophus::SE2d{0.0, {1.0, 0.0}}, make_dummy_laser_scan());
ASSERT_TRUE(estimate.has_value());
}
TEST(TestAmcl, UpdateWithParticlesNoMotion) {
auto amcl = make_amcl();
ASSERT_EQ(amcl.particles().size(), 0);
amcl.initialize_from_map();
ASSERT_EQ(amcl.particles().size(), 50UL);
auto estimate = amcl.update(Sophus::SE2d{}, make_dummy_laser_scan());
ASSERT_TRUE(estimate.has_value());
estimate = amcl.update(Sophus::SE2d{}, make_dummy_laser_scan());
ASSERT_FALSE(estimate.has_value());
}
TEST(TestAmcl, UpdateWithParticlesForced) {
auto amcl = make_amcl();
ASSERT_EQ(amcl.particles().size(), 0);
amcl.initialize_from_map();
ASSERT_EQ(amcl.particles().size(), 50UL);
auto estimate = amcl.update(Sophus::SE2d{}, make_dummy_laser_scan());
ASSERT_TRUE(estimate.has_value());
amcl.force_update();
estimate = amcl.update(Sophus::SE2d{}, make_dummy_laser_scan());
ASSERT_TRUE(estimate.has_value());
}
TEST(TestAmcl, UpdatePropagationWithNoParticles) {
auto amcl = make_amcl();
amcl.update_propagation(Sophus::SE2d{});
ASSERT_EQ(amcl.particles().size(), 0);
}
} // namespace