fix(costmap): put every layer on one parameter flow
Each layer reads its default file under $PNKX_NAV_CORE_CONFIG_DIR/config,
then overrides a key from "<costmap>/<plugin>".
Costmap2DROBOT::copyParentParameters() copies the shared "<plugin>:"
block there first. The copy lists covered only part of what the layers
read, so a key set in the shared block was dropped without a word.
DepthCameraObstacleLayer bypassed the flow: it had no default file and
read the shared block itself, with the opposite precedence.
- copyParentParameters(): copy every key each layer reads.
- StaticLayer: add enabled, first_map_only, subscribe_to_updates,
use_maximum, trinary_costmap and base_frame_id.
- Obstacle/VoxelLayer: add transform_tolerance,
footprint_clearing_enabled and combination_method; VoxelLayer also
gets enabled, max_obstacle_height and track_unknown_space.
- InflationLayer: add enabled and inflate_unknown.
- Add a DepthCameraObstacleLayer branch with its layer and per-source
keys.
- Drop copies that no layer reads (publish_voxel_map, layer-level
obstacle_range and raytrace_range).
- Keys are copied with the type the layer reads. A key that does not
convert now throws: getParam() used to write 0, false or "" into the
value, and that was copied as if configured.
- DepthCameraObstacleLayer::loadParameters(): read
config/depth_camera_obstacle_layer_params.yaml, then "<costmap>/<plugin>",
like ObstacleLayer. A missing file or block, or a value of the wrong
type, throws. ParamReader is gone. With the shared block copied in,
"<costmap>/<plugin>/<source>" exists, and the node_handle.cpp:265
warning at start-up goes away.
- config/depth_camera_obstacle_layer_params.yaml: new, equal to the C++
defaults. track_unknown_space is left out, so the layer still follows
the costmap.
- depth_camera_obstacle_layer_test: point PNKX_NAV_CORE_CONFIG_DIR at the
package. Add tests for a value of the wrong type and for a missing
default file.
This commit is contained in:
@@ -4,9 +4,12 @@
|
||||
#include <robot_sensor_msgs/DepthCameraData.h>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace robot_costmap_2d;
|
||||
@@ -17,6 +20,18 @@ constexpr double kFovW = 1.23; // D410 at 424x240, fx = 300 [rad]
|
||||
constexpr double kFovV = 0.76;
|
||||
constexpr char kTopic[] = "/camera/depth/points_proc";
|
||||
|
||||
// The layer reads config/depth_camera_obstacle_layer_params.yaml under PNKX_NAV_CORE_CONFIG_DIR
|
||||
// before its own namespace; point it at this package for every test.
|
||||
class ConfigDirEnvironment : public ::testing::Environment
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
ASSERT_EQ(setenv("PNKX_NAV_CORE_CONFIG_DIR", ROBOT_COSTMAP_2D_DIR, 1), 0);
|
||||
}
|
||||
};
|
||||
::testing::Environment* const kConfigDirEnvironment = ::testing::AddGlobalTestEnvironment(new ConfigDirEnvironment);
|
||||
|
||||
// Optical frame "camera" 0.19 m above odom, looking along +x of odom (rotated by yaw).
|
||||
tf3::TransformStampedMsg pose(robot::Time stamp, double yaw = 0)
|
||||
{
|
||||
@@ -444,4 +459,28 @@ TEST(DepthCameraLayerConfig, RejectsUnportedModeAndOutOfRangeValues)
|
||||
cfg = baseConfig();
|
||||
cfg["voxel_resolution"] = 0.0;
|
||||
expectThrow(cfg);
|
||||
// A value of the wrong type stops the layer instead of becoming 0.
|
||||
cfg = baseConfig();
|
||||
cfg["number_clearing_threshold"] = "many";
|
||||
expectThrow(cfg);
|
||||
cfg = baseConfig();
|
||||
cfg["depth_cam"]["FOV_W"] = "wide";
|
||||
expectThrow(cfg);
|
||||
}
|
||||
|
||||
TEST(DepthCameraLayerConfig, RefusesToStartWithoutItsDefaultFile)
|
||||
{
|
||||
tf3::BufferCore tf;
|
||||
LayeredCostmap parent{"odom", false, false};
|
||||
parent.getCostmap()->resizeMap(80, 80, .05, -2, -2);
|
||||
robot::NodeHandle nh("~");
|
||||
nh.setParam("dcam_no_default", baseConfig());
|
||||
// An empty directory: it has no config/depth_camera_obstacle_layer_params.yaml.
|
||||
char empty_dir[] = "/tmp/dcam_no_default_XXXXXX";
|
||||
ASSERT_NE(mkdtemp(empty_dir), nullptr);
|
||||
ASSERT_EQ(setenv("PNKX_NAV_CORE_CONFIG_DIR", empty_dir, 1), 0);
|
||||
DepthCameraObstacleLayer layer;
|
||||
EXPECT_THROW(layer.initialize(&parent, "dcam_no_default", &tf), std::runtime_error);
|
||||
ASSERT_EQ(setenv("PNKX_NAV_CORE_CONFIG_DIR", ROBOT_COSTMAP_2D_DIR, 1), 0);
|
||||
rmdir(empty_dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user