1 #include <gtest/gtest.h> 3 #include "../../core/mock_grid_cell.h" 5 #include "../../../src/core/math_utils.h" 6 #include "../../../src/core/states/robot_pose.h" 7 #include "../../../src/core/maps/plain_grid_map.h" 8 #include "../../../src/utils/data_generation/map_primitives.h" 9 #include "../../../src/utils/data_generation/grid_map_patcher.h" 10 #include "../../../src/utils/data_generation/laser_scan_generator.h" 12 #include "../../../src/utils/console_view.h" 17 :
map{std::make_shared<MockGridCell>(),
25 static constexpr
double Map_Scale = 1;
31 int scale = Patch_Scale) {
42 const ScanPoint2D &sp_err = {Map_Scale / 2, 0.001}) {
43 ASSERT_EQ(expected.size(), actual.size());
44 for (std::size_t sp_i = 0; sp_i < expected.size(); ++sp_i) {
46 auto expected_occ = actual[sp_i].is_occupied() ? 1.0 : 0;
58 ASSERT_NEAR(expected.
range(), actual.
range(), std::abs(range_err));
62 auto scale = Patch_Scale *
map.
scale();
64 l * scale, r * scale, u * scale, d * scale);
101 auto mp_free_space = cecum_mp.
free_space()[0];
105 (-cecum_mp.height() * Patch_Scale + 1) *
map.
scale(),
114 {mp_free_space.hside_len() * scale,
deg2rad(0)},
115 {mp_free_space.vside_len() * scale,
deg2rad(90)}};
122 auto mp_free_space = cecum_mp.
free_space()[0];
125 (mp_free_space.right() * Patch_Scale - 1) *
map.
scale(),
126 (-cecum_mp.height() * Patch_Scale + 1) *
map.
scale(),
135 {mp_free_space.vside_len() * scale,
deg2rad(0)},
136 {mp_free_space.hside_len() * scale,
deg2rad(90)}};
143 auto mp_free_space = cecum_mp.
free_space()[0];
146 (mp_free_space.right() * Patch_Scale - 1) *
map.
scale(),
147 ((mp_free_space.top() - 1) * Patch_Scale) *
map.
scale(),
163 auto mp_free_space = cecum_mp.
free_space()[0];
167 ((mp_free_space.top() - 1) * Patch_Scale) *
map.
scale(),
183 auto mp_free_space = cecum_mp.
free_space()[0];
186 (cecum_mp.width() * Patch_Scale / 2) *
map.
scale(),
187 (-cecum_mp.height() * Patch_Scale + 1) *
map.
scale(),
194 {((Patch_Scale * mp_free_space.hside_len() + 1) / 2) *
map.
scale(),
196 {Patch_Scale * mp_free_space.vside_len() *
map.
scale(),
198 {(Patch_Scale * mp_free_space.hside_len() / 2 + 1) *
map.
scale(),
214 (mp_fspc.right() * Patch_Scale - 1) *
map.
scale(),
215 ((mp_fspc.top() - 1) * Patch_Scale) *
map.
scale(),
224 {mp_fspc.hside_len() *
map.
scale() * Patch_Scale / std::cos(
deg2rad(45)),
237 ((mp_fspc.top() - 1) * Patch_Scale) *
map.
scale(),
246 {mp_fspc.hside_len() *
map.
scale() * Patch_Scale / std::cos(
deg2rad(30)),
260 ((mp_fspc.top() - 1) - mp_fspc.vside_len() / 2) * Patch_Scale *
map.
scale(),
266 auto scan = lsgen.laser_scan_2D(
map,
rpose, 1);
268 constexpr
double A_Step = 270.0 / 8;
269 double cecum_free_w = mp_fspc.hside_len();
270 double left_w = ((Patch_Scale * cecum_free_w + 1) / 2) *
map.
scale();
271 double right_w = (Patch_Scale * cecum_free_w / 2) *
map.
scale();
273 {left_w / std::cos(
deg2rad(45 - 0 * A_Step)),
deg2rad(-135 + 0 * A_Step)},
274 {left_w / std::cos(
deg2rad(45 - 1 * A_Step)),
deg2rad(-135 + 1 * A_Step)},
275 {left_w / std::cos(
deg2rad(45 - 2 * A_Step)),
deg2rad(-135 + 2 * A_Step)},
276 {left_w / std::cos(
deg2rad(45 - 3 * A_Step)),
deg2rad(-135 + 3 * A_Step)},
278 {right_w / std::cos(
deg2rad(45 - 3 * A_Step)),
deg2rad(-135 + 5 * A_Step)},
279 {right_w / std::cos(
deg2rad(45 - 2 * A_Step)),
deg2rad(-135 + 6 * A_Step)},
280 {right_w / std::cos(
deg2rad(45 - 1 * A_Step)),
deg2rad(-135 + 7 * A_Step)},
281 {right_w / std::cos(
deg2rad(45 - 0 * A_Step)),
deg2rad(-135 + 8 * A_Step)}};
294 ((mp_fspc.top() - 1) - mp_fspc.vside_len() / 2) * Patch_Scale *
map.
scale(),
299 const int LS_Points_Nm = 4000;
302 auto scan = lsgen.laser_scan_2D(
map,
rpose, 1);
304 const double D_Angle =
deg2rad(1.3);
305 scan.trig_provider->set_base_angle(D_Angle);
306 for (
auto &sp : scan.points()) {
307 ASSERT_NEAR(std::cos(sp.angle() + D_Angle),
308 scan.trig_provider->cos(sp.angle()), 0.001);
309 ASSERT_NEAR(std::sin(sp.angle() + D_Angle),
310 scan.trig_provider->sin(sp.angle()), 0.001);
316 int main (
int argc,
char *argv[]) {
317 ::testing::InitGoogleTest(&argc, argv);
318 return RUN_ALL_TESTS();
void check_scan_point(const ScanPoint2D &expected, const ScanPoint2D &actual, const ScanPoint2D &abs_err)
void dbg_show_map_near_robot(int l, int r, int u, int d)
Coord world_to_cell(const Point2D &pt) const
void show_grid_map(const GridMap &map, const Point2D ¢er, double d_x_left, double d_x_right, double d_y_up, double d_y_down)
void update(const Coord &area_id, const AreaOccupancyObservation &aoo) override
Updates area with a given observation.
static constexpr int Patch_Scale
TEST_F(LaserScanGeneratorTest, emptyMap4beams)
UnboundedPlainGridMap map
void patch_map(const MapPrimitive &mp, int scale)
void apply_text_raster(MapType &dst_map, std::istream &src_raster, const DiscretePoint2D &dst_offset, int w_zoom=1, int h_zoom=1)
static constexpr int Map_Width
static constexpr int Map_Height
virtual std::istream & to_stream() const =0
int main(int argc, char *argv[])
LaserScan2D laser_scan_2D(const GridMap &map, const RobotPose &pose, double occ_threshold=1)
void check_scan_points(const ScanPoints &expected, const ScanPoints &actual, const ScanPoint2D &sp_err={Map_Scale/2, 0.001})
std::vector< ScanPoint2D > ScanPoints
void prepare_map_and_robot_pose(const MapPrimitive &mp, const RobotPoseDelta &rpd, int scale=Patch_Scale)
constexpr double deg2rad(double angle_deg)
virtual double scale() const
static constexpr double Map_Scale