Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test_points_to_costmap #960

Merged
merged 29 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2e257aa
test: add test_points_to_costmap
May 25, 2022
c88adb1
ci(pre-commit): autofix
pre-commit-ci[bot] May 25, 2022
b080ed6
add copyright
May 25, 2022
d9fbcb4
test: add copyright
May 25, 2022
ab0b916
Update planning/costmap_generator/test/test_points_to_costmap.cpp
storrrrrrrrm May 26, 2022
b4e7adf
test: modify copyright
May 26, 2022
6f4ebea
Merge branch 'test_costmap_generator' of github.com:storrrrrrrrm/auto…
May 26, 2022
d440e87
ci(pre-commit): autofix
pre-commit-ci[bot] May 26, 2022
38a519b
test: add include header file
May 26, 2022
e95808a
Merge branch 'test_costmap_generator' of github.com:storrrrrrrrm/auto…
May 26, 2022
f0478e4
ci(pre-commit): autofix
pre-commit-ci[bot] May 26, 2022
5b6c3ec
test: add include header file
May 26, 2022
b962fb7
ci(pre-commit): autofix
pre-commit-ci[bot] May 26, 2022
f84616d
ci(pre-commit): autofix
pre-commit-ci[bot] May 26, 2022
6ed4614
test: modify comments for spell-check
May 26, 2022
5059460
Merge branch 'test_costmap_generator' of github.com:storrrrrrrrm/auto…
May 26, 2022
f537654
Merge branch 'main' into test_costmap_generator
storrrrrrrrm May 26, 2022
dfbc1d8
test: fix spell-check
May 30, 2022
1012b0d
test: const variable
May 30, 2022
dd1a594
Merge branch 'main' into test_costmap_generator
storrrrrrrrm Jun 20, 2022
6e48fcb
fix build error
Jun 24, 2022
a1f5064
fix build error
Jun 24, 2022
73d03a2
fix build error
Jun 24, 2022
f9cec97
ci(pre-commit): autofix
pre-commit-ci[bot] Jun 24, 2022
ba36d90
Merge branch 'main' into test_costmap_generator
Sharrrrk Jun 27, 2022
aab3ac3
Merge branch 'main' into test_costmap_generator
storrrrrrrrm Jun 27, 2022
9d8d910
ci(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2022
06d22d1
variable to const
Jun 28, 2022
5d258f5
ci(pre-commit): autofix
pre-commit-ci[bot] Jun 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions planning/costmap_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ rclcpp_components_register_node(costmap_generator_node

if(BUILD_TESTING)
find_package(ament_cmake_ros REQUIRED)
ament_add_ros_isolated_gtest(test_points_to_costmap
test/test_points_to_costmap.cpp
)

target_link_libraries(test_points_to_costmap
costmap_generator_node
)
endif()

ament_auto_package(INSTALL_TO_SHARE launch)
215 changes: 215 additions & 0 deletions planning/costmap_generator/test/test_points_to_costmap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved

#include <rclcpp/rclcpp.hpp>

#include <gtest/gtest.h>

using pointcloud = pcl::PointCloud<pcl::PointXYZ>;
class PointsToCostmapTest : public ::testing::Test
{
protected:
void SetUp() override { rclcpp::init(0, nullptr); }

~PointsToCostmapTest() override { rclcpp::shutdown(); }

grid_map::GridMap constrcut_gridmap();
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved

public:
double grid_resolution_ = 1;
double grid_length_x_ = 20;
double grid_length_y_ = 20;
double grid_position_x_ = 0;
double grid_position_y_ = 0;
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved
};

grid_map::GridMap PointsToCostmapTest::constrcut_gridmap()
{
grid_map::GridMap gm;

// set gridmap size
gm.setFrameId("map");
gm.setGeometry(
grid_map::Length(grid_length_x_, grid_length_y_), grid_resolution_,
grid_map::Position(grid_position_x_, grid_position_y_));

// set initial value
gm.add("points", 0);

// set car postion in map frame to center of grid
grid_map::Position p;
p.x() = 0;
p.y() = 0;
gm.setPosition(p);
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved

return gm;
}

// gridy
// | mapx-------
// | |
// | |
// | |
// | mapy
// |__________________gridx
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved
TEST_F(PointsToCostmapTest, TestmakeCostmapFromPoints_validPoints)
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved
{
// construct pointcloud in map frame
pointcloud in_sensor_points;

in_sensor_points.width = 3;
in_sensor_points.height = 1;
in_sensor_points.is_dense = false;
in_sensor_points.resize(in_sensor_points.width * in_sensor_points.height);

in_sensor_points.points[0].x = 0.7;
in_sensor_points.points[0].y = 1;
in_sensor_points.points[0].z = 1;

in_sensor_points.points[1].x = 1.1;
in_sensor_points.points[1].y = 1;
in_sensor_points.points[1].z = 4;

in_sensor_points.points[2].x = 1.4;
in_sensor_points.points[2].y = 2;
in_sensor_points.points[2].z = 2.7;

grid_map::GridMap gridmap = constrcut_gridmap();

PointsToCostmap point2costmap;
double maximum_height_thres = 5;
double minimum_lidar_height_thres = 0;
double grid_min_value = 0;
double grid_max_value = 1;
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved

std::string gridmap_layer_name = "points";
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved
grid_map::Matrix costmap_data = point2costmap.makeCostmapFromPoints(
maximum_height_thres, minimum_lidar_height_thres, grid_min_value, grid_max_value, gridmap,
gridmap_layer_name, in_sensor_points);

int nonempty_gridcell_num = 0;
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < costmap_data.rows(); i++) {
for (int j = 0; j < costmap_data.cols(); j++) {
if (costmap_data(i, j) == grid_max_value) {
// std::cout << "i:"<< i <<",j:"<<j<< std::endl;
nonempty_gridcell_num += 1;
}
}
}

EXPECT_EQ(nonempty_gridcell_num, 3);
}

TEST_F(PointsToCostmapTest, TestmakeCostmapFromPoints_invalidPoints_biggerThanMaximumHeightThres)
{
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved
// construct pointcloud in map frame
pointcloud in_sensor_points;
in_sensor_points.width = 1;
in_sensor_points.height = 1;
in_sensor_points.is_dense = false;
in_sensor_points.resize(in_sensor_points.width * in_sensor_points.height);

in_sensor_points.points[0].x = 0.7;
in_sensor_points.points[0].y = 1;
in_sensor_points.points[0].z = 1; // out of [maximum_height_thres,minimum_lidar_height_thres]

grid_map::GridMap gridmap = constrcut_gridmap();

PointsToCostmap point2costmap;
double maximum_height_thres = 0.99;
double minimum_lidar_height_thres = 0;
double grid_min_value = 0;
double grid_max_value = 1;

std::string gridmap_layer_name = "points";
grid_map::Matrix costmap_data = point2costmap.makeCostmapFromPoints(
maximum_height_thres, minimum_lidar_height_thres, grid_min_value, grid_max_value, gridmap,
gridmap_layer_name, in_sensor_points);

int nonempty_gridcell_num = 0;
for (int i = 0; i < costmap_data.rows(); i++) {
for (int j = 0; j < costmap_data.cols(); j++) {
if (costmap_data(i, j) == grid_max_value) {
nonempty_gridcell_num += 1;
}
}
}

EXPECT_EQ(nonempty_gridcell_num, 0);
}

TEST_F(PointsToCostmapTest, TestmakeCostmapFromPoints_invalidPoints_lessThanMinimumHeightThres)
{
// construct pointcloud in map frame
pointcloud in_sensor_points;
in_sensor_points.width = 1;
in_sensor_points.height = 1;
in_sensor_points.is_dense = false;
in_sensor_points.resize(in_sensor_points.width * in_sensor_points.height);

in_sensor_points.points[0].x = 0.7;
in_sensor_points.points[0].y = 1;
in_sensor_points.points[0].z = -0.1; // out of [maximum_height_thres,minimum_lidar_height_thres]

grid_map::GridMap gridmap = constrcut_gridmap();

PointsToCostmap point2costmap;
double maximum_height_thres = 0.99;
double minimum_lidar_height_thres = 0;
double grid_min_value = 0;
double grid_max_value = 1;

std::string gridmap_layer_name = "points";
grid_map::Matrix costmap_data = point2costmap.makeCostmapFromPoints(
maximum_height_thres, minimum_lidar_height_thres, grid_min_value, grid_max_value, gridmap,
gridmap_layer_name, in_sensor_points);

int nonempty_gridcell_num = 0;
for (int i = 0; i < costmap_data.rows(); i++) {
for (int j = 0; j < costmap_data.cols(); j++) {
if (costmap_data(i, j) == grid_max_value) {
nonempty_gridcell_num += 1;
}
}
}

EXPECT_EQ(nonempty_gridcell_num, 0);
}

TEST_F(PointsToCostmapTest, TestmakeCostmapFromPoints_invalidPoints_outOfGrid)
{
// construct pointcloud in map frame
pointcloud in_sensor_points;
in_sensor_points.width = 1;
in_sensor_points.height = 1;
in_sensor_points.is_dense = false;
in_sensor_points.resize(in_sensor_points.width * in_sensor_points.height);

in_sensor_points.points[0].x = 1 + grid_length_x_ / 2.0;
in_sensor_points.points[0].y = 1 + grid_length_y_ / 2.0;
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved
in_sensor_points.points[0].z = 0.5;

grid_map::GridMap gridmap = constrcut_gridmap();

PointsToCostmap point2costmap;
double maximum_height_thres = 0.99;
double minimum_lidar_height_thres = 0;
double grid_min_value = 0;
double grid_max_value = 1;
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved

std::string gridmap_layer_name = "points";
maxime-clem marked this conversation as resolved.
Show resolved Hide resolved
grid_map::Matrix costmap_data = point2costmap.makeCostmapFromPoints(
maximum_height_thres, minimum_lidar_height_thres, grid_min_value, grid_max_value, gridmap,
gridmap_layer_name, in_sensor_points);

int nonempty_gridcell_num = 0;
for (int i = 0; i < costmap_data.rows(); i++) {
for (int j = 0; j < costmap_data.cols(); j++) {
if (costmap_data(i, j) == grid_max_value) {
nonempty_gridcell_num += 1;
}
}
}

EXPECT_EQ(nonempty_gridcell_num, 0);
}