fix(costmap): one parameter flow for every layer; fail on a bad layer
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. This was broken in three ways: - 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 had no default file and read the shared block itself; - a layer that failed to initialize left a half-built costmap that reported READY. Failing loudly: - costmap_2d_robot.cpp: a failing layer, a malformed plugins: list or a missing costmap_params.yaml throws std::runtime_error with the costmap and layer name, after releasing layered_costmap_. NavigationRuntime::buildCostmaps() turns this into an initialization error, so the host never reports READY. - Static/Obstacle/Voxel/Inflation and DepthCameraObstacleLayer throw when their default file cannot be opened. - A key whose value does not convert to the type the layer reads throws. getParam() used to write 0, false or "" into the value, and that was copied as if configured. One flow: - copyParentParameters() copies every key each layer reads, with the layer's type, including a new DepthCameraObstacleLayer branch. Copies no layer reads are dropped. - DepthCameraObstacleLayer::loadParameters() reads config/depth_camera_obstacle_layer_params.yaml (new, equal to the C++ defaults), then "<costmap>/<plugin>". ParamReader is gone, and so is the node_handle.cpp:265 warning at start-up. - VoxelLayer: z_resolution can be overridden; unknown_threshold is computed after the final z_voxels; the column keys are range-checked; the effective column is logged once at start-up. - config/obstacle_layer_params.yaml: drop the per-source keys the layer never read there. - depth_camera_obstacle_layer_test: set PNKX_NAV_CORE_CONFIG_DIR; add tests for a wrong type and a missing default file. Squash of fix/config-flow (ae7fce9,f8705e1). Checked on the KIT robot on 22/10/2026: - the depth layer summary at start-up is unchanged; - a shared-block key now reaches VoxelLayer; - FOV_W 3.5, z_voxels 17, a wrong-typed key and a missing default file each give INITIALIZATION_FAILED.
This commit is contained in:
@@ -45,6 +45,8 @@
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#define VOXEL_BITS 16
|
||||
|
||||
@@ -65,7 +67,8 @@ void VoxelLayer::onInitialize()
|
||||
|
||||
ObstacleLayer::onInitialize();
|
||||
std::string config_file_name = "voxel_layer_params.yaml";
|
||||
getParams(config_file_name, priv_nh);
|
||||
if (!getParams(config_file_name, priv_nh))
|
||||
throw std::runtime_error("VoxelLayer " + name_ + ": cannot open the default file " + config_file_name);
|
||||
}
|
||||
|
||||
VoxelLayer::~VoxelLayer()
|
||||
@@ -92,14 +95,14 @@ bool VoxelLayer::getParams(const std::string& config_file_name, robot::NodeHandl
|
||||
enabled_ = loadParam(layer, "enabled", true);
|
||||
footprint_clearing_enabled_ = loadParam(layer, "footprint_clearing_enabled", true);
|
||||
max_obstacle_height_ = loadParam(layer, "max_obstacle_height", 2.0);
|
||||
size_z_ = loadParam(layer, "z_voxels", 10);
|
||||
int size_z = loadParam(layer, "z_voxels", 10);
|
||||
origin_z_ = loadParam(layer, "origin_z", 0.0);
|
||||
z_resolution_ = loadParam(layer, "z_resolution", 0.2);
|
||||
unknown_threshold_ = loadParam(layer, "unknown_threshold", 15.0) + (VOXEL_BITS - size_z_);
|
||||
mark_threshold_ = loadParam(layer, "mark_threshold", 0);
|
||||
// Read as double: the default file writes 15.0, which yaml-cpp refuses to convert to int.
|
||||
double unknown_threshold = loadParam(layer, "unknown_threshold", 15.0);
|
||||
int mark_threshold = loadParam(layer, "mark_threshold", 0);
|
||||
combination_method_ = loadParam(layer, "combination_method", 0.0);
|
||||
|
||||
int size_z, unknown_threshold, mark_threshold;
|
||||
if (nh.hasParam("enabled"))
|
||||
nh.getParam("enabled", enabled_);
|
||||
if (nh.hasParam("footprint_clearing_enabled"))
|
||||
@@ -107,25 +110,40 @@ bool VoxelLayer::getParams(const std::string& config_file_name, robot::NodeHandl
|
||||
if (nh.hasParam("max_obstacle_height"))
|
||||
nh.getParam("max_obstacle_height", max_obstacle_height_);
|
||||
if (nh.hasParam("z_voxels"))
|
||||
{
|
||||
nh.getParam("z_voxels", size_z);
|
||||
size_z_ = size_z;
|
||||
}
|
||||
if (nh.hasParam("origin_z"))
|
||||
nh.getParam("origin_z", origin_z_);
|
||||
if (nh.hasParam("z_resolution"))
|
||||
nh.getParam("z_resolution", z_resolution_);
|
||||
if (nh.hasParam("unknown_threshold"))
|
||||
{
|
||||
nh.getParam("unknown_threshold", unknown_threshold);
|
||||
unknown_threshold_ = unknown_threshold + (VOXEL_BITS - size_z_);
|
||||
}
|
||||
if (nh.hasParam("mark_threshold"))
|
||||
{
|
||||
nh.getParam("mark_threshold", mark_threshold);
|
||||
mark_threshold_ = mark_threshold;
|
||||
}
|
||||
if (nh.hasParam("combination_method"))
|
||||
nh.getParam("combination_method", combination_method_);
|
||||
|
||||
// A column stores VOXEL_BITS levels at most, and worldToMap3D divides by z_resolution.
|
||||
if (size_z < 1 || size_z > VOXEL_BITS)
|
||||
throw std::invalid_argument("VoxelLayer " + name_ + ": z_voxels must be in [1, 16]");
|
||||
if (!(z_resolution_ > 0.0) || !std::isfinite(z_resolution_))
|
||||
throw std::invalid_argument("VoxelLayer " + name_ + ": z_resolution must be > 0 [m]");
|
||||
if (!std::isfinite(origin_z_))
|
||||
throw std::invalid_argument("VoxelLayer " + name_ + ": origin_z must be finite [m]");
|
||||
if (!(unknown_threshold >= 0.0) || mark_threshold < 0)
|
||||
throw std::invalid_argument("VoxelLayer " + name_ + ": unknown_threshold and mark_threshold must be >= 0");
|
||||
|
||||
size_z_ = size_z;
|
||||
// Levels above z_voxels are never observed and stay unknown; adding them keeps the threshold
|
||||
// counting only the levels in use. Computed after size_z_ is final, so overriding z_voxels
|
||||
// alone no longer leaves the threshold sized for the default file's column.
|
||||
unknown_threshold_ = static_cast<unsigned int>(unknown_threshold) + (VOXEL_BITS - size_z_);
|
||||
mark_threshold_ = static_cast<unsigned int>(mark_threshold);
|
||||
|
||||
robot::log_info("VoxelLayer %s: column origin_z=%.2f m z_resolution=%.3f m z_voxels=%u (top %.2f m) "
|
||||
"unknown_threshold=%u mark_threshold=%u max_obstacle_height=%.2f m\n",
|
||||
name_.c_str(), origin_z_, z_resolution_, size_z_, origin_z_ + size_z_ * z_resolution_,
|
||||
unknown_threshold_, mark_threshold_, max_obstacle_height_);
|
||||
|
||||
this->matchSize();
|
||||
}
|
||||
catch (const YAML::BadFile& e) {
|
||||
|
||||
Reference in New Issue
Block a user