15 #include <gtest/gtest.h>
25 #if BELUGA_ROS_VERSION == 1
26 #include <boost/smart_ptr.hpp>
38 auto make_dummy_occupancy_grid() {
39 constexpr std::size_t kWidth = 100;
40 constexpr std::size_t kHeight = 200;
42 #if BELUGA_ROS_VERSION == 2
43 auto message = std::make_shared<beluga_ros::msg::OccupancyGrid>();
44 #elif BELUGA_ROS_VERSION == 1
45 auto message = boost::make_shared<beluga_ros::msg::OccupancyGrid>();
47 #error BELUGA_ROS_VERSION is not defined or invalid
49 message->info.resolution = 0.1F;
52 message->info.origin.position.x = 1;
53 message->info.origin.position.y = 2;
54 message->info.origin.position.z = 0;
55 message->data = std::vector<std::int8_t>(kWidth * kHeight);
60 auto make_dummy_laser_scan() {
61 #if BELUGA_ROS_VERSION == 2
62 auto message = std::make_shared<beluga_ros::msg::LaserScan>();
63 #elif BELUGA_ROS_VERSION == 1
64 auto message = boost::make_shared<beluga_ros::msg::LaserScan>();
66 message->ranges = std::vector<float>{1., 2., 3.};
73 auto map = make_dummy_occupancy_grid();
85 TEST(TestAmcl, InitializeWithNoParticles) {
86 auto amcl = make_amcl();
87 ASSERT_EQ(amcl.particles().size(), 0);
90 TEST(TestAmcl, InitializeFromMap) {
91 auto amcl = make_amcl();
92 amcl.initialize_from_map();
93 ASSERT_EQ(amcl.particles().size(), 50UL);
96 TEST(TestAmcl, InitializeFromPose) {
97 auto amcl = make_amcl();
98 amcl.initialize(
Sophus::SE2d{}, Eigen::Vector3d::Ones().asDiagonal());
99 ASSERT_EQ(amcl.particles().size(), 50UL);
102 TEST(TestAmcl, UpdateWithNoParticles) {
103 auto amcl = make_amcl();
104 ASSERT_EQ(amcl.particles().size(), 0);
109 TEST(TestAmcl, UpdateWithParticles) {
110 auto amcl = make_amcl();
111 ASSERT_EQ(amcl.particles().size(), 0);
112 amcl.initialize_from_map();
113 ASSERT_EQ(amcl.particles().size(), 50UL);
118 TEST(TestAmcl, UpdateWithParticlesNoMotion) {
119 auto amcl = make_amcl();
120 ASSERT_EQ(amcl.particles().size(), 0);
121 amcl.initialize_from_map();
122 ASSERT_EQ(amcl.particles().size(), 50UL);
129 TEST(TestAmcl, UpdateWithParticlesForced) {
130 auto amcl = make_amcl();
131 ASSERT_EQ(amcl.particles().size(), 0);
132 amcl.initialize_from_map();
133 ASSERT_EQ(amcl.particles().size(), 50UL);