Depth cameras now go through their own costmap layer instead of the frustum clearing that lived in ObstacleLayer and VoxelLayer. - Add DepthCameraObstacleLayer. It stores marked points per costmap column, clears stored points inside each camera frustum with a kd-tree check against the new cloud, keeps points outside the view, groups points with Euclidean clustering, and does not mark a 12 cm band at the frustum faces. - The layer follows the CostmapLayer contract: updateWithMax/Overwrite by combination_method, reset(), clearArea() with the usual invert semantics, footprint clearing, matchSize() and the layer mutex. So ClearCostmapRecovery and costmap resets work on it. - Add LayerType::DEPTH_CAMERA_LAYER, appended last so the existing values keep their numbers. The host's SensorGateway must dispatch PointCloud2 and DepthCameraData to it (move_base2 feature/depth-camera-layer-type). - Remove the frustum clearing code from Observation, ObservationBuffer, ObstacleLayer, VoxelLayer and costmap_2d_robot.cpp. - ObstacleLayer and VoxelLayer now reject a DepthCameraData source or frustum_clearing_enabled: true at startup, with a message that points to DepthCameraObstacleLayer. - Link PCL into the plugins library only. Add 21 unit tests for the layer (depth_camera_obstacle_layer_test). Squashed from feature/depth-observed-volume (2ca0bcc..40dc70e).
261 lines
8.2 KiB
C++
261 lines
8.2 KiB
C++
/*
|
|
* Software License Agreement (BSD License)
|
|
*
|
|
* Copyright (c) 2019, Locus Robotics
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer in the documentation and/or other materials provided
|
|
* with the distribution.
|
|
* * Neither the name of the copyright holder nor the names of its
|
|
* contributors may be used to endorse or promote products derived
|
|
* from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
// Tests ripped from https://github.com/locusrobotics/robot_navigation/blob/master/nav_grid/test/utest.cpp
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <robot_costmap_2d/costmap_2d.h>
|
|
#include <robot_costmap_2d/cost_values.h>
|
|
#include <robot_costmap_2d/inflation_layer.h>
|
|
#include <robot_costmap_2d/layered_costmap.h>
|
|
#include <robot_costmap_2d/observation_buffer.h>
|
|
#include <robot_costmap_2d/voxel_layer.h>
|
|
|
|
#include <boost/make_shared.hpp>
|
|
#include <cstdlib>
|
|
|
|
using namespace robot_costmap_2d;
|
|
|
|
TEST(CostmapCoordinates, easy_coordinates_test)
|
|
{
|
|
Costmap2D costmap(2, 3, 1.0, 0, 0);
|
|
|
|
double wx, wy;
|
|
costmap.mapToWorld(0u, 0u, wx, wy);
|
|
EXPECT_DOUBLE_EQ(wx, 0.5);
|
|
EXPECT_DOUBLE_EQ(wy, 0.5);
|
|
costmap.mapToWorld(1u, 2u, wx, wy);
|
|
EXPECT_DOUBLE_EQ(wx, 1.5);
|
|
EXPECT_DOUBLE_EQ(wy, 2.5);
|
|
|
|
unsigned int umx, umy;
|
|
int mx, my;
|
|
ASSERT_TRUE(costmap.worldToMap(wx, wy, umx, umy));
|
|
EXPECT_EQ(umx, 1);
|
|
EXPECT_EQ(umy, 2);
|
|
costmap.worldToMapNoBounds(wx, wy, mx, my);
|
|
EXPECT_EQ(mx, 1);
|
|
EXPECT_EQ(my, 2);
|
|
|
|
// Invalid Coordinate
|
|
wx = 2.5;
|
|
EXPECT_FALSE(costmap.worldToMap(wx, wy, umx, umy));
|
|
costmap.worldToMapEnforceBounds(wx, wy, mx, my);
|
|
EXPECT_EQ(mx, 1);
|
|
EXPECT_EQ(my, 2);
|
|
costmap.worldToMapNoBounds(wx, wy, mx, my);
|
|
EXPECT_EQ(mx, 2);
|
|
EXPECT_EQ(my, 2);
|
|
|
|
// Border Cases
|
|
EXPECT_TRUE(costmap.worldToMap(0.0, wy, umx, umy));
|
|
EXPECT_EQ(umx, 0);
|
|
EXPECT_TRUE(costmap.worldToMap(0.25, wy, umx, umy));
|
|
EXPECT_EQ(umx, 0);
|
|
EXPECT_TRUE(costmap.worldToMap(0.75, wy, umx, umy));
|
|
EXPECT_EQ(umx, 0);
|
|
EXPECT_TRUE(costmap.worldToMap(0.9999, wy, umx, umy));
|
|
EXPECT_EQ(umx, 0);
|
|
EXPECT_TRUE(costmap.worldToMap(1.0, wy, umx, umy));
|
|
EXPECT_EQ(umx, 1);
|
|
EXPECT_TRUE(costmap.worldToMap(1.25, wy, umx, umy));
|
|
EXPECT_EQ(umx, 1);
|
|
EXPECT_TRUE(costmap.worldToMap(1.75, wy, umx, umy));
|
|
EXPECT_EQ(umx, 1);
|
|
EXPECT_TRUE(costmap.worldToMap(1.9999, wy, umx, umy));
|
|
EXPECT_EQ(umx, 1);
|
|
EXPECT_FALSE(costmap.worldToMap(2.0, wy, umx, umy));
|
|
costmap.worldToMapEnforceBounds(2.0, wy, mx, my);
|
|
EXPECT_EQ(mx, 1);
|
|
}
|
|
|
|
TEST(CostmapCoordinates, hard_coordinates_test)
|
|
{
|
|
Costmap2D costmap(2, 3, 0.1, -0.2, 0.2);
|
|
|
|
double wx, wy;
|
|
costmap.mapToWorld(0, 0, wx, wy);
|
|
EXPECT_DOUBLE_EQ(wx, -0.15);
|
|
EXPECT_DOUBLE_EQ(wy, 0.25);
|
|
costmap.mapToWorld(1, 2, wx, wy);
|
|
EXPECT_DOUBLE_EQ(wx, -0.05);
|
|
EXPECT_DOUBLE_EQ(wy, 0.45);
|
|
|
|
unsigned int umx, umy;
|
|
int mx, my;
|
|
EXPECT_TRUE(costmap.worldToMap(wx, wy, umx, umy));
|
|
EXPECT_EQ(umx, 1);
|
|
EXPECT_EQ(umy, 2);
|
|
costmap.worldToMapNoBounds(wx, wy, mx, my);
|
|
EXPECT_EQ(mx, 1);
|
|
EXPECT_EQ(my, 2);
|
|
|
|
// Invalid Coordinate
|
|
wx = 2.5;
|
|
EXPECT_FALSE(costmap.worldToMap(wx, wy, umx, umy));
|
|
costmap.worldToMapEnforceBounds(wx, wy, mx, my);
|
|
EXPECT_EQ(mx, 1);
|
|
EXPECT_EQ(my, 2);
|
|
costmap.worldToMapNoBounds(wx, wy, mx, my);
|
|
EXPECT_EQ(mx, 27);
|
|
EXPECT_EQ(my, 2);
|
|
}
|
|
|
|
TEST(CostmapPerformanceRegression, rolling_origin_preserves_overlap)
|
|
{
|
|
Costmap2D costmap(4, 3, 1.0, 0.0, 0.0, FREE_SPACE);
|
|
costmap.setCost(1, 1, LETHAL_OBSTACLE);
|
|
costmap.setCost(3, 2, INSCRIBED_INFLATED_OBSTACLE);
|
|
|
|
costmap.updateOrigin(0.25, 0.25);
|
|
EXPECT_DOUBLE_EQ(costmap.getOriginX(), 0.0);
|
|
EXPECT_DOUBLE_EQ(costmap.getOriginY(), 0.0);
|
|
EXPECT_EQ(costmap.getCost(1, 1), LETHAL_OBSTACLE);
|
|
|
|
costmap.updateOrigin(1.0, 0.0);
|
|
EXPECT_DOUBLE_EQ(costmap.getOriginX(), 1.0);
|
|
EXPECT_EQ(costmap.getCost(0, 1), LETHAL_OBSTACLE);
|
|
EXPECT_EQ(costmap.getCost(3, 2), FREE_SPACE);
|
|
}
|
|
|
|
TEST(CostmapPerformanceRegression, voxel_origin_subcell_shift_is_noop)
|
|
{
|
|
VoxelLayer layer;
|
|
layer.resizeMap(4, 3, 1.0, 0.0, 0.0);
|
|
layer.setCost(1, 1, LETHAL_OBSTACLE);
|
|
|
|
layer.updateOrigin(0.25, 0.25);
|
|
|
|
EXPECT_DOUBLE_EQ(layer.getOriginX(), 0.0);
|
|
EXPECT_DOUBLE_EQ(layer.getOriginY(), 0.0);
|
|
EXPECT_EQ(layer.getCost(1, 1), LETHAL_OBSTACLE);
|
|
}
|
|
|
|
TEST(CostmapPerformanceRegression, observation_copy_shares_cloud_payload)
|
|
{
|
|
robot_geometry_msgs::Point origin;
|
|
robot_sensor_msgs::PointCloud2 cloud;
|
|
cloud.height = 1;
|
|
cloud.width = 1;
|
|
cloud.point_step = 4;
|
|
cloud.row_step = 4;
|
|
cloud.data = {1, 2, 3, 4};
|
|
|
|
Observation observation(origin, cloud, 2.5, 3.0);
|
|
Observation copied = observation;
|
|
|
|
EXPECT_EQ(copied.cloud_, observation.cloud_);
|
|
EXPECT_EQ(copied.cloud_handle_.use_count(), 2);
|
|
EXPECT_EQ(copied.cloud_->data, cloud.data);
|
|
}
|
|
|
|
TEST(CostmapPerformanceRegression, inflation_buckets_preserve_radial_costs)
|
|
{
|
|
ASSERT_EQ(setenv("PNKX_NAV_CORE_CONFIG_DIR", ROBOT_COSTMAP_2D_DIR, 1), 0);
|
|
|
|
LayeredCostmap layered_costmap("map", false, false);
|
|
layered_costmap.resizeMap(7, 7, 1.0, 0.0, 0.0, true);
|
|
tf3::BufferCore tf_buffer(tf3::Duration(10.0));
|
|
InflationLayer inflation;
|
|
inflation.initialize(&layered_costmap, "inflation", &tf_buffer);
|
|
inflation.setInflationParameters(2.0, 1.0);
|
|
|
|
Costmap2D& master = *layered_costmap.getCostmap();
|
|
master.setCost(3, 3, LETHAL_OBSTACLE);
|
|
inflation.updateCosts(master, 0, 0, 7, 7);
|
|
|
|
EXPECT_EQ(master.getCost(3, 3), LETHAL_OBSTACLE);
|
|
EXPECT_EQ(master.getCost(2, 3), master.getCost(4, 3));
|
|
EXPECT_EQ(master.getCost(3, 2), master.getCost(3, 4));
|
|
EXPECT_GT(master.getCost(4, 3), master.getCost(5, 3));
|
|
EXPECT_EQ(master.getCost(6, 3), FREE_SPACE);
|
|
}
|
|
|
|
TEST(CostmapSnapshot, copy_from_copies_grid_and_metadata)
|
|
{
|
|
Costmap2D src(10, 8, 0.05, 1.0, 2.0, FREE_SPACE);
|
|
src.setCost(3, 4, LETHAL_OBSTACLE);
|
|
src.setCost(9, 7, 42);
|
|
|
|
Costmap2D dst;
|
|
dst.copyFrom(src);
|
|
|
|
EXPECT_EQ(dst.getSizeInCellsX(), 10u);
|
|
EXPECT_EQ(dst.getSizeInCellsY(), 8u);
|
|
EXPECT_DOUBLE_EQ(dst.getResolution(), 0.05);
|
|
EXPECT_DOUBLE_EQ(dst.getOriginX(), 1.0);
|
|
EXPECT_DOUBLE_EQ(dst.getOriginY(), 2.0);
|
|
EXPECT_EQ(dst.getCost(3, 4), LETHAL_OBSTACLE);
|
|
EXPECT_EQ(dst.getCost(9, 7), 42);
|
|
EXPECT_EQ(dst.getCost(0, 0), FREE_SPACE);
|
|
}
|
|
|
|
TEST(CostmapSnapshot, copy_from_reuses_buffer_when_size_unchanged)
|
|
{
|
|
Costmap2D src(6, 6, 0.05, 0.0, 0.0, FREE_SPACE);
|
|
Costmap2D dst;
|
|
dst.copyFrom(src);
|
|
unsigned char* first_buffer = dst.getCharMap();
|
|
|
|
src.setCost(2, 2, LETHAL_OBSTACLE);
|
|
dst.copyFrom(src);
|
|
|
|
// Same size: the buffer must be reused (this is the whole point of
|
|
// copyFrom vs operator=), and the fresh cell must arrive.
|
|
EXPECT_EQ(dst.getCharMap(), first_buffer);
|
|
EXPECT_EQ(dst.getCost(2, 2), LETHAL_OBSTACLE);
|
|
}
|
|
|
|
TEST(CostmapSnapshot, copy_from_reallocates_on_resize)
|
|
{
|
|
Costmap2D src(4, 4, 0.05, 0.0, 0.0, FREE_SPACE);
|
|
Costmap2D dst;
|
|
dst.copyFrom(src);
|
|
|
|
Costmap2D bigger(12, 9, 0.1, -1.0, -2.0, NO_INFORMATION);
|
|
bigger.setCost(11, 8, LETHAL_OBSTACLE);
|
|
dst.copyFrom(bigger);
|
|
|
|
EXPECT_EQ(dst.getSizeInCellsX(), 12u);
|
|
EXPECT_EQ(dst.getSizeInCellsY(), 9u);
|
|
EXPECT_EQ(dst.getCost(11, 8), LETHAL_OBSTACLE);
|
|
EXPECT_EQ(dst.getCost(0, 0), NO_INFORMATION);
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
testing::InitGoogleTest( &argc, argv );
|
|
return RUN_ALL_TESTS();
|
|
}
|