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 all 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
9 changes: 9 additions & 0 deletions planning/costmap_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ 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_lib
)

ament_add_ros_isolated_gtest(test_objects_to_costmap
test/test_objects_to_costmap.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define COSTMAP_GENERATOR__OBJECTS_TO_COSTMAP_HPP_

#include <grid_map_ros/grid_map_ros.hpp>

#ifdef ROS_DISTRO_GALACTIC
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#define COSTMAP_GENERATOR__POINTS_TO_COSTMAP_HPP_

#include <grid_map_ros/grid_map_ros.hpp>
#include <rclcpp/rclcpp.hpp>

#include <pcl_conversions/pcl_conversions.h>

Expand Down
218 changes: 218 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,218 @@
// Copyright 2022 The Autoware Contributors
//
// 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 <costmap_generator/points_to_costmap.hpp>
storrrrrrrrm marked this conversation as resolved.
Show resolved Hide resolved

#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 construct_gridmap();

public:
const double grid_resolution_ = 1.0;
const double grid_length_x_ = 20.0;
const double grid_length_y_ = 20.0;
const double grid_position_x_ = 0.0;
const double grid_position_y_ = 0.0;
};

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

gm.setFrameId("map");
// set gridmap size,resolution
gm.setGeometry(grid_map::Length(grid_length_x_, grid_length_y_), grid_resolution_);
// center of grid to position p in map frame
gm.setPosition(grid_map::Position(grid_position_x_, grid_position_y_));

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

return gm;
}

// grid_y
// | map_x-------
// | |
// | |
// | |
// | map_y
// |__________________grid_x
TEST_F(PointsToCostmapTest, TestMakeCostmapFromPoints_validPoints)
{
// 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 = construct_gridmap();

PointsToCostmap point2costmap;
const double maximum_height_thres = 5.0;
const double minimum_lidar_height_thres = 0.0;
const double grid_min_value = 0.0;
const double grid_max_value = 1.0;
const 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_grid_cell_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) {
// std::cout << "i:"<< i <<",j:"<<j<< std::endl;
nonempty_grid_cell_num += 1;
}
}
}

EXPECT_EQ(nonempty_grid_cell_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 = construct_gridmap();

PointsToCostmap point2costmap;
const double maximum_height_thres = 0.99;
const double minimum_lidar_height_thres = 0.0;
const double grid_min_value = 0.0;
const double grid_max_value = 1.0;
const 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_grid_cell_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_grid_cell_num += 1;
}
}
}

EXPECT_EQ(nonempty_grid_cell_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 = construct_gridmap();

PointsToCostmap point2costmap;
const double maximum_height_thres = 0.99;
const double minimum_lidar_height_thres = 0.0;
const double grid_min_value = 0.0;
const double grid_max_value = 1.0;
const 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_grid_cell_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_grid_cell_num += 1;
}
}
}

EXPECT_EQ(nonempty_grid_cell_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);

// when we construct gridmap,we set grid map center to (0,0) in map frame
// so it would be outside of grid map if absolute value of point.x bigger than half of
// grid_length_x_
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 = construct_gridmap();

PointsToCostmap point2costmap;
const double maximum_height_thres = 0.99;
const double minimum_lidar_height_thres = 0.0;
const double grid_min_value = 0.0;
const double grid_max_value = 1.0;
const 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_grid_cell_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_grid_cell_num += 1;
}
}
}

EXPECT_EQ(nonempty_grid_cell_num, 0);
}