9 Commits

Author SHA1 Message Date
74a02bd4a8 refactor(obstacle_layer): drop the DepthCameraData startup guard
ObstacleLayer and VoxelLayer no longer carry any depth code, so the check
that rejected a DepthCameraData source or frustum_clearing_enabled goes too.
A DepthCameraData source still fails at startup through the generic
data_type check; frustum_clearing_enabled is now an unknown key.

The README and the LayerType comment now say the gateway feeds
DepthCameraObstacleLayer PointCloud2 only.
2026-10-21 13:39:41 +07:00
40dc70e758 feat(depth): DepthCameraObstacleLayer gets its own LayerType
The plugin reported VOXEL_LAYER only because SensorGateway feeds sensor data
to that type. It is its own layer, so LayerType gains DEPTH_CAMERA_LAYER
(appended last: the values of the existing types do not move) and the plugin
returns it. move_base2's SensorGateway delivers PointCloud2 and
DepthCameraData to the new type in the matching commit; without that commit
the layer receives nothing.

matchSize() is overridden as well: CostmapLayer::matchSize() rebuilds the own
grid with the default value, so the stored columns are re-marked under the
layer mutex right away and the whole layer is queued for the next merge.
2026-10-20 14:28:14 +07:00
a5f548f0d7 refactor(depth): DepthCameraObstacleLayer follows the CostmapLayer contract
The port wrote LETHAL straight into the master from its stored 3D points and
left its own grid empty, as costmap_depth_camera does. Everything CostmapLayer
offers on top of the own grid therefore missed the layer: clearArea() (the
ClearCostmapRecovery path), reset() (Costmap2DROBOT::resetLayers()), footprint
clearing and combination_method all acted on an empty grid, and the next cycle
wrote the ghosts back. Cleared cells also stayed on the master until another
layer's bounds covered them (the source's B7).

The stored points stay the source of truth; the clearing and marking
algorithm is unchanged. The own grid now mirrors them cell by cell, the way
VoxelLayer keeps a voxel grid next to its 2D grid:

- marking sets the column's cell LETHAL, the last point of a column leaving
  sets it FREE_SPACE, and both touch the bounds, so a cleared cell leaves the
  master in the same cycle (clear_touches_bounds is gone, always on);
- updateCosts() only merges the own grid with combination_method, like
  ObstacleLayer; combination_method other than 0/1 now means "no effect";
- reset() drops the stored points and buffered observations;
- clearArea() follows CostmapLayer::clearArea(): invert_area false clears
  outside the box and keeps the inside, true clears the inside;
- footprint clearing erases the stored columns under the robot;
- markings that leave the window are dropped in updateBounds() (B6), and a
  column whose cell went missing is re-marked;
- the layer mutex guards the point map, since ClearCostmapRecovery and
  resetLayers() reach it from other threads (recursive mutex, held by the
  recovery around clearArea()).

Tests: the two clear_touches_bounds cases become one bounded-update case, and
clearArea (both directions), reset and footprint clearing get their own.
2026-10-20 13:34:08 +07:00
b23ff27a3c refactor(depth): keep DepthCameraObstacleLayer, drop the legacy depth clearing
Two depth-image clearing designs lived in this package: the frustum ray
clearing inherited from dev_cam_intel (DepthCameraData sources of
ObstacleLayer/VoxelLayer, frustum_* and column_* keys) and the observed_volume
evidence clearing (ROC) on top of it. Both are replaced on the robot by
DepthCameraObstacleLayer, a port of costmap_depth_camera that takes the
filtered PointCloud2 directly, so both are removed and the tree is rebuilt
from main (a63c084) plus the plugin.

- observation.h / observation_buffer: DepthFrustumConfig, DepthCameraObservation
  and the depth buffering API are gone; buffers hold point clouds only.
- ObstacleLayer/VoxelLayer: no frustum ray casting, column clearing or depth
  ray cache. A DepthCameraData source or frustum_clearing_enabled: true now
  fails at startup with a message pointing to DepthCameraObstacleLayer
  instead of silently dropping the camera; DepthCameraData reaching the layer
  through the gateway is ignored.
- copyParentParameters no longer forwards the frustum_* / column_* keys.
- ROC files (depth_evidence_store, depth_visibility, depth_frame_pairer) and
  their tests are not carried over; CloudProcessingConfig goes with them.
- PCL is needed by the plugin library only. The plugin test moves under
  BUILD_COSTMAP_TESTS; BUILD_DEPTH_MARKING_TESTS is gone.
- README documents DepthCameraObstacleLayer and its known limits.

The plugin code is unchanged from the version running on the KIT robot.
2026-10-20 09:47:33 +07:00
9a67eee148 wip: state before depth cleanup
Uncommitted work as it ran on the KIT robot until 2026-10-20: the ROC observed_volume tuning patch on top of 63707c9 and the DepthCameraObstacleLayer plugin (clone of tsengapola/costmap_depth_camera noetic, B6 window fix), its 17 unit tests and the CMake wiring. Kept as one commit so the cleanup that follows has a recoverable starting point; not meant to be pushed.
2026-10-20 09:36:53 +07:00
63707c968c fix(depth): free voxels on clearArea/footprint, accept far returns as behind
clearArea and footprint clearing only wrote the 2D cells, so the voxels and
evidence points stayed MARKED and the next column update brought the phantom
back. VoxelLayer now frees the voxel column and its evidence in both paths
(footprint only for observed_volume; legacy unchanged).

A valid return deeper than depth_valid_max_z_m kept every evidence point
unknown, so phantoms with nothing within 3 m behind never cleared. New key
depth_far_return_is_behind (default false) counts such a return as behind a
point that lies at least free_margin_m inside the trusted range.

Replay of the 2026-10-15 bags: real phantoms 62 -> 53, static-cell dropouts
unchanged, object kept on 10/11 FOV exits as before.
2026-10-15 16:58:23 +07:00
6340838dac fix(depth): forward the evidence-point keys to the layer namespace
Costmap2DROBOT copies a fixed list of observed_volume keys from obstacles/<source>
into <costmap>/obstacles/<source>. The three phase-1 keys were missing, so the
live layer always ran with their C++ defaults (evidence off, marking border 0)
whatever the runtime YAML said. Unit tests set the layer params directly and did
not catch it.

The factory test now checks that the runtime YAML values reach the layer.
2026-10-15 13:40:26 +07:00
5e38857e48 feat(depth): certify evidence points instead of whole voxels (phase 1)
The whole-voxel rule never clears a voxel whose box crosses the image edge.
A person bending over to lift an object leaves high voxels at the top edge
of the image: in the 2026-10-15 lift bag 0 of 54 phantom cells cleared.

- DepthEvidenceStore keeps, per marked voxel, the 6 per-axis extreme points
  plus the most recent ones, keyed by a window-independent cell index.
- DepthVisibilityChecker::classifyPoints: Free only when every evidence
  point projects with a full patch inside the usable image and sees valid
  depth behind it; any surface in front keeps it, invalid depth keeps it.
- Paired marking drops points within depth_marking_border_px of the image
  edge, so every kept point can be re-checked from the pose that saw it.
- Voxels without evidence keep the whole-voxel rule; evidence is erased on
  clear, pruned on rolling shift and every 50 frames.
- New keys depth_evidence_points_enabled (default false),
  depth_evidence_points_per_voxel (8, 6..16), depth_marking_border_px
  (must be > depth_projection_margin_px when enabled); startup log and
  counters (by_evidence, border_dropped_points, evidence_voxels).
- Tests: depth_evidence_store_test; checker and layer tests for the image
  top cut, border drop, rolling shift and a still-visible object.
2026-10-15 13:22:28 +07:00
2ca0bcc1c1 feat(depth): observed_volume depth clearing as deployed 2026-10-14
Baseline commit of the working-tree refactor built on 2026-10-14 17:24 and
running on the KIT robot, recorded in one commit before further changes.

- VoxelLayer clearing looks up TF at the depth image stamp.
- ObservationBuffer: per-source cloud preparation at the measurement stamp,
  height/range gate before the PCL VoxelGrid.
- DepthFramePairer: pairs the marking cloud with the clearing image by
  source and stamp, bounded queue and age.
- DepthVisibilityChecker and the observed_volume clearing mode in VoxelLayer;
  the legacy frustum mode stays the default.
- Tests: depth_observation_buffer_test, depth_visibility_test.
2026-10-15 11:37:56 +07:00
9 changed files with 261 additions and 339 deletions

View File

@@ -1,46 +0,0 @@
# Giá trị mặc định của DepthCameraObstacleLayer, bằng mặc định trong code.
# Plugin đọc file này TRƯỚC, rồi khoá cùng tên trong khối <costmap>/<plugin> của config costmap đè lên
# (Costmap2DROBOT chép khối chung <plugin>: vào đó trước khi tạo layer).
# Đây là bản đóng gói kèm gói robot_costmap_2d; robot chạy bản trong
# pnkx_nav_core/config/runtime/config/depth_camera_obstacle_layer_params.yaml.
depth_camera_obstacle_layer:
enabled: true # [bool] false = layer không đánh dấu, không xoá gì.
# [m] Độ phân giải chiều cao của điểm lưu. > 0. Tăng (vd 0.05): ít điểm, nhẹ CPU hơn nhiều;
# giảm: nhiều điểm hơn, kd-tree mỗi chu kỳ nặng hơn.
voxel_resolution: 0.01
# [m] Bán kính tìm điểm cloud quanh điểm đã lưu. > 0. Tăng: khó xoá (vết ma bám lâu hơn);
# giảm: vật mỏng/thưa dễ bị xoá nhầm.
check_radius: 0.1
# [điểm] Ít hơn số điểm cloud này trong check_radius thì điểm đã lưu bị xoá. >= 1. Tăng: xoá mạnh hơn.
number_clearing_threshold: 2
# [m] Khoảng cách gom cụm Euclidean khi đánh dấu. > 0.
ec_seg_distance: 0.2
# [điểm] Cỡ cụm nhỏ nhất khi gom cụm. >= 1.
ec_cluster_min_size: 5
# [điểm] Cụm có <= số điểm này không được đánh dấu (lọc nhiễu). >= 0. Tăng: bỏ vật nhỏ.
size_of_cluster_rejection: 5
# [m] Điểm trong FOV cách tâm robot dưới mức này luôn bị xoá. >= 0.
forced_clearing_distance: 0.1
# [bool] true: cloud dưới number_points_considered_as_blocked điểm thì bỏ qua xoá (coi camera bị che).
# false: cloud ít điểm như vậy thì xoá hết điểm trong FOV ("không thấy gì").
enable_near_blocked_protection: true
number_points_considered_as_blocked: 5 # [điểm] >= 0.
# [bool] VoxelGrid 5 cm trên cloud gộp trước khi xoá/đánh dấu (nhẹ CPU).
use_voxelized_observation: true
# [bool] Chỉ hỗ trợ true (lưu điểm theo toạ độ global). false thì nav từ chối khởi động.
use_global_frame_to_mark: true
# [s] Cloud chờ TF đúng stamp tối đa bao lâu rồi bỏ. >= 0. Không bao giờ dùng TF mới nhất.
transform_tolerance: 0.2
# [bool] true: xoá ô và điểm đã lưu nằm dưới footprint robot mỗi chu kỳ. false: chỉ dùng khi chẩn đoán.
footprint_clearing_enabled: true
# [-] Cách gộp lên costmap chung: 1 = lấy max (không hạ cost của layer khác), 0 = ghi đè trong vùng
# cập nhật. Giá trị khác: layer không tác động gì lên costmap.
combination_method: 1
# Danh sách nguồn, cách nhau bằng dấu cách. Rỗng = layer không đánh dấu gì. Khoá của từng nguồn
# (topic, FOV_W, FOV_V, min/max_detect_distance, min/max_obstacle_height...) KHÔNG đặt ở đây mà
# trong khối <plugin>/<tên nguồn>/ của config costmap.
observation_sources: ""
# track_unknown_space cố ý KHÔNG có ở đây: không đặt thì layer theo track_unknown_space của costmap.
debug:
stats: true # [bool] log đếm định kỳ (điểm cloud, điểm lưu, đánh dấu/xoá, thời gian).
stats_period: 5.0 # [s] chu kỳ in log đếm. > 0.

View File

@@ -1,13 +1,18 @@
# Giá trị mặc định của ObstacleLayer (cũng là phần ObstacleLayer bên trong VoxelLayer).
# Plugin đọc file này TRƯỚC, rồi khoá cùng tên trong khối <costmap>/<plugin> của config costmap đè lên.
# Đây là bản đóng gói kèm gói robot_costmap_2d; robot chạy bản trong
# pnkx_nav_core/config/runtime/config/obstacle_layer_params.yaml.
# Khoá theo từng nguồn (topic, sensor_frame, data_type, clearing, marking, obstacle_range,
# raytrace_range...) KHÔNG đặt ở đây: plugin chỉ đọc chúng trong khối <plugin>/<tên source>/.
obstacle_layer:
track_unknown_space: true # [bool] true = ô chưa quan sát giữ NO_INFORMATION; false = coi là free.
transform_tolerance: 0.2 # [s] độ trễ TF tối đa khi đổi điểm sensor sang frame costmap. Nhỏ quá
# thì điểm bị bỏ khi TF trễ; lớn quá thì điểm được đặt sai chỗ khi robot quay.
max_obstacle_height: 2.0 # [m] điểm cao hơn mức này không được đánh dấu.
footprint_clearing_enabled: true # [bool] xoá vật cản nằm trong footprint robot (chính thân robot).
combination_method: 1 # [-] 0 = ghi đè lên master costmap; 1 = lấy max với master.
track_unknown_space: true
transform_tolerance: 0.2
topic: "map"
sensor_frame: laser_frame
observation_persistence: 0.0
expected_update_rate: 0.0
data_type: PointCloud
min_obstacle_height: 0.0
max_obstacle_height: 2.0
inf_is_valid: false
clearing: false
marking: true
obstacle_range: 2.5
raytrace_range: 3.0
footprint_clearing_enabled: true
combination_method: 1

View File

@@ -50,13 +50,9 @@
#include <pcl/search/kdtree.h>
#include <pcl/segmentation/extract_clusters.h>
#include <robot_costmap_2d/utils.h>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <filesystem>
#include <limits>
#include <sstream>
#include <stdexcept>
@@ -83,26 +79,42 @@ Eigen::Isometry3d toIsometry(const tf3::TransformStampedMsg& t)
return iso;
}
// Steps 1 and 3 of the costmap layer config flow for one key: the value in the layer's default
// file, overridden by "<costmap>/<plugin>/<key>", which Costmap2DROBOT::copyParentParameters() has
// filled from the shared "<plugin>:" block. A value that does not convert to T is a configuration
// error: getParam() would otherwise replace it with 0, false or "" without a word.
template <typename T>
T readParam(const YAML::Node& file_node, const std::string& file_key, const robot::NodeHandle& nh,
const std::string& key, const T& fallback)
// The source keeps parameters in the plugin namespace. Costmap2DROBOT only copies the keys of
// known layer types from the shared namespace into "<costmap>/<plugin>", so read the scoped
// value first and fall back to the shared block with the plugin's own name.
class ParamReader
{
T value = loadParam(file_node, file_key, fallback);
if (nh.hasParam(key) && !nh.getParam(key, value, value))
throw std::invalid_argument("DepthCameraObstacleLayer: '" + nh.getNamespace() + "/" + key +
"' does not convert to the type the layer reads");
return value;
}
public:
ParamReader(const robot::NodeHandle& scoped, const robot::NodeHandle& shared)
: scoped_(scoped), shared_(shared)
{
}
template <typename T>
T readParam(const YAML::Node& file_node, const robot::NodeHandle& nh, const std::string& key, const T& fallback)
{
return readParam(file_node, key, nh, key, fallback);
}
ParamReader child(const std::string& ns) const
{
return ParamReader(robot::NodeHandle(scoped_, ns), robot::NodeHandle(shared_, ns));
}
bool has(const std::string& key) const
{
return scoped_.hasParam(key) || shared_.hasParam(key);
}
template <typename T>
T get(const std::string& key, const T& default_value) const
{
T value = default_value;
if (scoped_.hasParam(key))
scoped_.getParam(key, value, default_value);
else if (shared_.hasParam(key))
shared_.getParam(key, value, default_value);
return value;
}
private:
robot::NodeHandle scoped_;
robot::NodeHandle shared_;
};
void requireRange(bool ok, const std::string& what)
{
@@ -238,56 +250,33 @@ void DepthCameraObstacleLayer::onInitialize()
void DepthCameraObstacleLayer::loadParameters()
{
// Step 1 of the config flow: the default file, like the other layers. A missing file or block
// stops the costmap from being built instead of running on C++ defaults.
const std::string config_file_name = "depth_camera_obstacle_layer_params.yaml";
const char* env_config = std::getenv("PNKX_NAV_CORE_CONFIG_DIR");
const std::string folder = (env_config && std::filesystem::exists(env_config)) ? env_config : "";
YAML::Node config;
try
{
config = YAML::LoadFile(getSourceFile(folder, config_file_name));
}
catch (const YAML::BadFile&)
{
throw std::runtime_error("DepthCameraObstacleLayer " + name_ + ": cannot open the default file " +
config_file_name);
}
YAML::Node layer = config["depth_camera_obstacle_layer"];
if (!layer.IsMap())
throw std::runtime_error("DepthCameraObstacleLayer " + name_ + ": " + config_file_name +
" has no depth_camera_obstacle_layer: block");
// Step 3: "<costmap>/<plugin>", filled by copyParentParameters() from the shared block.
robot::NodeHandle nh("~");
const robot::NodeHandle priv_nh(nh, name_);
const std::string short_name = name_.substr(name_.find_last_of('/') + 1);
const ParamReader p(robot::NodeHandle(nh, name_), robot::NodeHandle(nh, short_name));
// Not in the default file on purpose: unset, the layer follows the costmap's track_unknown_space.
const bool track_unknown_space =
readParam(layer, priv_nh, "track_unknown_space", layered_costmap_->isTrackingUnknown());
const bool track_unknown_space = p.get("track_unknown_space", layered_costmap_->isTrackingUnknown());
default_value_ = track_unknown_space ? NO_INFORMATION : FREE_SPACE;
enabled_ = readParam(layer, priv_nh, "enabled", true);
footprint_clearing_enabled_ = readParam(layer, priv_nh, "footprint_clearing_enabled", true);
combination_method_ = readParam(layer, priv_nh, "combination_method", 1);
enable_near_blocked_protection_ = readParam(layer, priv_nh, "enable_near_blocked_protection", true);
number_points_considered_as_blocked_ = readParam(layer, priv_nh, "number_points_considered_as_blocked", 5);
forced_clearing_distance_ = readParam(layer, priv_nh, "forced_clearing_distance", 0.1);
ec_seg_distance_ = readParam(layer, priv_nh, "ec_seg_distance", 0.2);
ec_cluster_min_size_ = readParam(layer, priv_nh, "ec_cluster_min_size", 5);
size_of_cluster_rejection_ = readParam(layer, priv_nh, "size_of_cluster_rejection", 5);
voxel_resolution_ = readParam(layer, priv_nh, "voxel_resolution", 0.01);
check_radius_ = readParam(layer, priv_nh, "check_radius", 0.1);
number_clearing_threshold_ = readParam(layer, priv_nh, "number_clearing_threshold", 2);
use_voxelized_observation_ = readParam(layer, priv_nh, "use_voxelized_observation", true);
transform_tolerance_ = readParam(layer, priv_nh, "transform_tolerance", 0.2);
const bool use_global_frame_to_mark = readParam(layer, priv_nh, "use_global_frame_to_mark", true);
if (layer["clear_touches_bounds"] || priv_nh.hasParam("clear_touches_bounds"))
enabled_ = p.get("enabled", true);
footprint_clearing_enabled_ = p.get("footprint_clearing_enabled", true);
combination_method_ = p.get("combination_method", 1);
enable_near_blocked_protection_ = p.get("enable_near_blocked_protection", true);
number_points_considered_as_blocked_ = p.get("number_points_considered_as_blocked", 5);
forced_clearing_distance_ = p.get("forced_clearing_distance", 0.1);
ec_seg_distance_ = p.get("ec_seg_distance", 0.2);
ec_cluster_min_size_ = p.get("ec_cluster_min_size", 5);
size_of_cluster_rejection_ = p.get("size_of_cluster_rejection", 5);
voxel_resolution_ = p.get("voxel_resolution", 0.01);
check_radius_ = p.get("check_radius", 0.1);
number_clearing_threshold_ = p.get("number_clearing_threshold", 2);
use_voxelized_observation_ = p.get("use_voxelized_observation", true);
transform_tolerance_ = p.get("transform_tolerance", 0.2);
const bool use_global_frame_to_mark = p.get("use_global_frame_to_mark", true);
if (p.has("clear_touches_bounds"))
robot::log_warning("DepthCameraObstacleLayer %s: clear_touches_bounds is obsolete and ignored: a cleared "
"cell now always resets its master cell\n", name_.c_str());
YAML::Node debug = layer["debug"];
debug_stats_ = readParam(debug, "stats", priv_nh, "debug/stats", true);
debug_stats_period_ = readParam(debug, "stats_period", priv_nh, "debug/stats_period", 5.0);
debug_stats_ = p.get("debug/stats", true);
debug_stats_period_ = p.get("debug/stats_period", 5.0);
// The source's local mode keys points by costmap index, so markings move with a rolling
// window (its README shows it). Only the global mode is ported.
@@ -306,29 +295,26 @@ void DepthCameraObstacleLayer::loadParameters()
marking_height_under_ground_ = 100.0;
marking_height_above_ground_ = -100.0;
std::stringstream ss(readParam(layer, priv_nh, "observation_sources", std::string("")));
std::stringstream ss(p.get("observation_sources", std::string("")));
std::string name;
while (ss >> name)
{
// Like obstacle_layer_params.yaml, the default file has no block per source, so a source key
// comes from "<costmap>/<plugin>/<source>/" or falls back to the C++ default below.
YAML::Node source_defaults = layer[name];
const robot::NodeHandle s(priv_nh, name);
const ParamReader s = p.child(name);
std::unique_ptr<Source> src(new Source());
src->name = name;
src->topic = readParam(source_defaults, s, "topic", name);
src->sensor_frame = readParam(source_defaults, s, "sensor_frame", std::string(""));
src->sensor_frame_is_optical = readParam(source_defaults, s, "sensor_frame_is_optical", false);
src->observation_keep_time = readParam(source_defaults, s, "observation_persistence", 0.0);
src->expected_update_rate = readParam(source_defaults, s, "expected_update_rate", 0.0);
src->min_obstacle_height = readParam(source_defaults, s, "min_obstacle_height", 0.0);
src->max_obstacle_height = readParam(source_defaults, s, "max_obstacle_height", 2.0);
src->marking = readParam(source_defaults, s, "marking", true);
src->fov_v = readParam(source_defaults, s, "FOV_V", 1.0);
src->fov_w = readParam(source_defaults, s, "FOV_W", 1.5);
src->min_detect_distance = readParam(source_defaults, s, "min_detect_distance", 0.15);
src->max_detect_distance = readParam(source_defaults, s, "max_detect_distance", 2.5);
if (readParam(source_defaults, s, "inf_is_valid", false))
src->topic = s.get("topic", name);
src->sensor_frame = s.get("sensor_frame", std::string(""));
src->sensor_frame_is_optical = s.get("sensor_frame_is_optical", false);
src->observation_keep_time = s.get("observation_persistence", 0.0);
src->expected_update_rate = s.get("expected_update_rate", 0.0);
src->min_obstacle_height = s.get("min_obstacle_height", 0.0);
src->max_obstacle_height = s.get("max_obstacle_height", 2.0);
src->marking = s.get("marking", true);
src->fov_v = s.get("FOV_V", 1.0);
src->fov_w = s.get("FOV_W", 1.5);
src->min_detect_distance = s.get("min_detect_distance", 0.15);
src->max_detect_distance = s.get("max_detect_distance", 2.5);
if (s.get("inf_is_valid", false))
robot::log_warning("DepthCameraObstacleLayer: inf_is_valid is not applicable to PointCloud observations\n");
const std::string what = "source " + name + ": ";

View File

@@ -41,7 +41,6 @@
#include <robot_costmap_2d/footprint.h>
#include <boost/thread.hpp>
#include <boost/dll/alias.hpp>
#include <stdexcept>
using robot_costmap_2d::LETHAL_OBSTACLE;
@@ -81,8 +80,7 @@ void InflationLayer::onInitialize()
need_reinflation_ = false;
std::string config_file_name = "inflation_layer_params.yaml";
// std::cout << "InflationLayer: " << config_file_name << std::endl;
if (!getParams(config_file_name, priv_nh))
throw std::runtime_error("InflationLayer " + name_ + ": cannot open the default file " + config_file_name);
getParams(config_file_name, priv_nh);
matchSize();
}

View File

@@ -42,7 +42,6 @@
#include <tf3/exceptions.h>
#include <boost/dll/alias.hpp>
#include <stdexcept>
using robot_costmap_2d::NO_INFORMATION;
@@ -67,8 +66,7 @@ void ObstacleLayer::onInitialize()
stop_receiving_data_ = false;
global_frame_ = layered_costmap_->getGlobalFrameID();
std::string config_file_name = "obstacle_layer_params.yaml";
if (!getParams(config_file_name, priv_nh))
throw std::runtime_error("ObstacleLayer " + name_ + ": cannot open the default file " + config_file_name);
getParams(config_file_name, priv_nh);
}
ObstacleLayer::~ObstacleLayer()

View File

@@ -43,7 +43,6 @@
#include <robot_tf3_geometry_msgs/tf3_geometry_msgs.h>
#include <boost/dll/alias.hpp>
#include <stdexcept>
#include <fstream>
#include <cxxabi.h>
@@ -72,8 +71,7 @@ void StaticLayer::onInitialize()
global_frame_ = layered_costmap_->getGlobalFrameID();
std::string config_file_name = "static_layer_params.yaml";
if (!getParams(config_file_name, priv_nh))
throw std::runtime_error("StaticLayer " + name_ + ": cannot open the default file " + config_file_name);
getParams(config_file_name, priv_nh);
robot::log_warning("Initializing static layer with map topic \"%s\" in frame \"%s\"", map_topic_.c_str(), global_frame_.c_str());
}

View File

@@ -45,8 +45,6 @@
#include <cmath>
#include <cstdint>
#include <cstring>
#include <stdexcept>
#include <string>
#define VOXEL_BITS 16
@@ -67,8 +65,7 @@ void VoxelLayer::onInitialize()
ObstacleLayer::onInitialize();
std::string config_file_name = "voxel_layer_params.yaml";
if (!getParams(config_file_name, priv_nh))
throw std::runtime_error("VoxelLayer " + name_ + ": cannot open the default file " + config_file_name);
getParams(config_file_name, priv_nh);
}
VoxelLayer::~VoxelLayer()
@@ -95,14 +92,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);
int size_z = loadParam(layer, "z_voxels", 10);
size_z_ = loadParam(layer, "z_voxels", 10);
origin_z_ = loadParam(layer, "origin_z", 0.0);
z_resolution_ = loadParam(layer, "z_resolution", 0.2);
// 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);
unknown_threshold_ = loadParam(layer, "unknown_threshold", 15.0) + (VOXEL_BITS - size_z_);
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"))
@@ -110,40 +107,25 @@ 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) {

View File

@@ -48,9 +48,6 @@
#include <tf3/convert.h>
#include <tf3/utils.h>
#include <exception>
#include <initializer_list>
#include <sstream>
#include <stdexcept>
#include <boost/dll/import.hpp>
@@ -66,26 +63,10 @@ void move_parameter(robot::NodeHandle& old_h, robot::NodeHandle& new_h, std::str
if (!old_h.hasParam(name))
return;
// A failed getParam() writes its default (0, false, "") into value; copying that would replace
// the layer's own default with a silent zero. A key of the wrong type is a configuration error.
if (!old_h.getParam(name, value, value))
throw std::invalid_argument("'" + old_h.getNamespace() + "/" + name +
"' does not convert to the type the layer reads");
old_h.getParam(name, value);
new_h.setParam(name, value);
}
// Moves each key of names that exists under old_h, read as T.
template <class T>
void move_parameters(robot::NodeHandle& old_h, robot::NodeHandle& new_h,
std::initializer_list<const char*> names)
{
for (const char* name : names)
{
T value{};
move_parameter(old_h, new_h, name, value);
}
}
Costmap2DROBOT::Costmap2DROBOT(const std::string& name, tf3::BufferCore& tf) :
layered_costmap_(NULL),
name_(name),
@@ -128,17 +109,6 @@ void Costmap2DROBOT::getParams(const std::string& config_file_name,const std::st
robot::NodeHandle priv_nh(nh, name);
// A costmap missing a layer, the layers after it or its update thread still looks alive to the
// planner, which then drives on a map that never marks obstacles. Refuse to build it instead:
// NavigationRuntime::buildCostmaps() turns the exception into an initialization error and the
// host never reports READY. The destructor does not run when the constructor throws, so the
// layered costmap (and the layers already added to it) is released here.
const auto fail = [this](const std::string& what) {
delete layered_costmap_;
layered_costmap_ = NULL;
throw std::runtime_error("costmap '" + name_ + "': " + what);
};
std::string global_frame =
loadParam(layer, "global_frame", std::string("map"));
std::string robot_base_frame =
@@ -254,22 +224,44 @@ void Costmap2DROBOT::getParams(const std::string& config_file_name,const std::st
{
my_list.clear();
YAML::Node my_plugins = priv_nh.getParamValue("plugins");
if (!my_plugins || !my_plugins.IsSequence())
fail("plugins: must be a list of {name, type} maps");
for (size_t i = 0; i < my_plugins.size(); ++i)
if (my_plugins && my_plugins.IsSequence())
{
YAML::Node plugin_i = my_plugins[i].as<YAML::Node>();
// Checked before reading the fields: indexing a scalar entry throws a bare YAML error.
if (!plugin_i.IsMap() || !plugin_i["name"] || !plugin_i["type"])
fail("plugins: entry " + std::to_string(i) + " must be a map with a name and a type");
for (size_t i = 0; i < my_plugins.size(); ++i)
{
YAML::Node plugin_i = my_plugins[i].as<YAML::Node>();
PluginConfig p;
p.type = plugin_i["type"].as<std::string>();
p.name = plugin_i["name"].as<std::string>();
for (const auto& known : my_list)
if (known.name == p.name)
fail("plugins: the name '" + p.name + "' is used twice; each layer needs its own name");
my_list.push_back(p);
PluginConfig p;
p.type = plugin_i["type"].as<std::string>();
p.name = plugin_i["name"].as<std::string>();
my_list.push_back(p);
if (!plugin_i.IsMap())
{
std::cerr << "Plugins must be specified as maps. We'll use the default recovery behaviors instead." << std::endl;
return;
}
if (!plugin_i["name"] || !plugin_i["type"])
{
std::cerr << "Plugins must have a name and a type. Using the default recovery behaviors instead." << std::endl;
return;
}
// check for recovery behaviors with the same name
std::string name_i = plugin_i["name"].as<std::string>();
for (size_t j = i + 1; j < my_plugins.size(); ++j)
{
YAML::Node plugin_j = my_plugins[j].as<YAML::Node>();
if (plugin_j.IsMap() && plugin_j["name"])
{
std::string name_j = plugin_j["name"].as<std::string>();
if (name_i == name_j)
{
std::cerr << "A plugin with the name " << name_i << " already exists, this is not allowed. Using the default recovery behaviors instead." << std::endl;
return;
}
}
}
}
}
}
else
@@ -301,10 +293,10 @@ void Costmap2DROBOT::getParams(const std::string& config_file_name,const std::st
plugin->initialize(layered_costmap_,name_ + "/" + info.name, &tf_);
layered_costmap_->addPlugin(plugin);
}
catch (const std::exception& ex)
catch (std::exception &ex)
{
// Covers a missing library or symbol as well as a layer rejecting its parameters.
fail("layer '" + info.name + "' (" + info.type + "): " + ex.what());
robot::log_error("Failed to create the %s, are you sure it is properly registered and that the containing library is built? Exception: %s\n", info.name.c_str(), ex.what());
return;
}
}
@@ -361,11 +353,8 @@ void Costmap2DROBOT::getParams(const std::string& config_file_name,const std::st
}
catch (const YAML::BadFile& e)
{
// costmap_params.yaml is read before layered_costmap_ exists; delete is a no-op on NULL.
delete layered_costmap_;
layered_costmap_ = NULL;
throw std::runtime_error("costmap '" + name_ + "': cannot open the default file " + config_file_name +
" under $PNKX_NAV_CORE_CONFIG_DIR/config: " + e.what());
std::cerr << "Cannot open YAML file: " << e.what() << std::endl;
return;
}
}
@@ -374,81 +363,132 @@ void Costmap2DROBOT::copyParentParameters(const std::string& costmap_name,
const std::string& plugin_type,
robot::NodeHandle& nh)
{
// Step 2 of the layer config flow. A layer reads its default file, then overrides each key found
// in "<costmap>/<plugin>". This copies the keys of the shared "<plugin>:" block there first, so the
// lists below must hold every key the layer reads with hasParam(): a key missing here is ignored
// without a word when it is set in the shared block. A copied key overwrites the same key in
// "<costmap>/<plugin>". Types follow what the layer reads.
robot::NodeHandle costmap_nh(nh, costmap_name);
robot::NodeHandle costmap_plugin_nh(costmap_nh, plugin_name);
robot::NodeHandle plugin_nh(nh, plugin_name);
// observation_sources, then the keys of each source under "<plugin>/<source>/".
const auto move_sources = [&](const auto& move_source_keys) {
std::string topics_string;
move_parameter(plugin_nh, costmap_plugin_nh, "observation_sources", topics_string);
std::stringstream ss(topics_string);
std::string source;
while (ss >> source)
if(plugin_type == "StaticLayer")
{
std::string map_topic;
int unknown_cost_value;
int lethal_cost_threshold;
bool track_unknown_space;
move_parameter(plugin_nh, costmap_plugin_nh, "map_topic", map_topic);
move_parameter(plugin_nh, costmap_plugin_nh, "unknown_cost_value", unknown_cost_value);
move_parameter(plugin_nh, costmap_plugin_nh, "lethal_cost_threshold", lethal_cost_threshold);
move_parameter(plugin_nh, costmap_plugin_nh, "track_unknown_space", track_unknown_space);
}
else if(plugin_type == "VoxelLayer")
{
double origin_z;
double z_resolution;
int z_voxels;
int mark_threshold;
int unknown_threshold;
bool publish_voxel_map;
move_parameter(plugin_nh, costmap_plugin_nh, "origin_z", origin_z);
move_parameter(plugin_nh, costmap_plugin_nh, "z_resolution", z_resolution);
move_parameter(plugin_nh, costmap_plugin_nh, "z_voxels", z_voxels);
move_parameter(plugin_nh, costmap_plugin_nh, "mark_threshold", mark_threshold);
move_parameter(plugin_nh, costmap_plugin_nh, "unknown_threshold", unknown_threshold);
move_parameter(plugin_nh, costmap_plugin_nh, "publish_voxel_map", publish_voxel_map);
if(plugin_nh.hasParam("observation_sources"))
{
robot::NodeHandle plugin_nh_element(plugin_nh, source);
robot::NodeHandle costmap_plugin_nh_element(costmap_plugin_nh, source);
move_source_keys(plugin_nh_element, costmap_plugin_nh_element);
}
};
std::string topics_string;
move_parameter(plugin_nh, costmap_plugin_nh, "observation_sources", topics_string);
robot::log_error("topics_string: %s", topics_string.c_str());
std::stringstream ss(topics_string);
std::string source;
while (ss >> source)
{
robot::NodeHandle plugin_nh_element(plugin_nh, source);
robot::NodeHandle costmap_plugin_nh_element(costmap_plugin_nh, source);
std::string topic;
std::string data_type;
bool clearing;
bool marking;
bool inf_is_valid;
std::string sensor_frame;
double observation_persistence;
double expected_update_rate;
double min_obstacle_height;
double max_obstacle_height;
double obstacle_range;
double raytrace_range;
if (plugin_type == "StaticLayer")
{
move_parameters<std::string>(plugin_nh, costmap_plugin_nh, {"map_topic", "base_frame_id"});
move_parameters<int>(plugin_nh, costmap_plugin_nh, {"unknown_cost_value", "lethal_cost_threshold"});
move_parameters<bool>(plugin_nh, costmap_plugin_nh,
{"enabled", "track_unknown_space", "first_map_only", "subscribe_to_updates",
"use_maximum", "trinary_costmap"});
}
else if (plugin_type == "ObstacleLayer" || plugin_type == "VoxelLayer")
{
// VoxelLayer runs ObstacleLayer::getParams() first, so it reads these keys too.
move_parameters<double>(plugin_nh, costmap_plugin_nh, {"max_obstacle_height", "transform_tolerance"});
move_parameters<int>(plugin_nh, costmap_plugin_nh, {"combination_method"});
move_parameters<bool>(plugin_nh, costmap_plugin_nh, {"track_unknown_space", "footprint_clearing_enabled"});
if (plugin_type == "VoxelLayer")
{
move_parameters<double>(plugin_nh, costmap_plugin_nh, {"origin_z", "z_resolution", "unknown_threshold"});
move_parameters<int>(plugin_nh, costmap_plugin_nh, {"z_voxels", "mark_threshold"});
move_parameters<bool>(plugin_nh, costmap_plugin_nh, {"enabled"});
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "topic", topic);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "sensor_frame", sensor_frame);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "observation_persistence", observation_persistence);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "expected_update_rate", expected_update_rate);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "data_type", data_type);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "clearing", clearing);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "marking", marking);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "inf_is_valid", inf_is_valid);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "min_obstacle_height", min_obstacle_height);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "max_obstacle_height", max_obstacle_height);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "obstacle_range", obstacle_range);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "raytrace_range", raytrace_range);
robot::log_info("topic: %s data_type: %s clearing: %d marking: %d inf_is_valid: %d min_obstacle_height: %f max_obstacle_height: %f", topic.c_str(), data_type.c_str(), clearing, marking, inf_is_valid, min_obstacle_height, max_obstacle_height);
}
}
move_sources([](robot::NodeHandle& from, robot::NodeHandle& to) {
move_parameters<std::string>(from, to, {"topic", "sensor_frame", "data_type"});
move_parameters<double>(from, to, {"observation_persistence", "expected_update_rate", "min_obstacle_height",
"max_obstacle_height", "obstacle_range", "raytrace_range"});
move_parameters<bool>(from, to, {"clearing", "marking", "inf_is_valid"});
});
}
else if (plugin_type == "InflationLayer")
else if(plugin_type == "ObstacleLayer")
{
move_parameters<double>(plugin_nh, costmap_plugin_nh, {"cost_scaling_factor", "inflation_radius"});
move_parameters<bool>(plugin_nh, costmap_plugin_nh, {"enabled", "inflate_unknown"});
double max_obstacle_height;
double raytrace_range;
double obstacle_range;
bool track_unknown_space;
move_parameter(plugin_nh, costmap_plugin_nh, "max_obstacle_height", max_obstacle_height);
move_parameter(plugin_nh, costmap_plugin_nh, "raytrace_range", raytrace_range);
move_parameter(plugin_nh, costmap_plugin_nh, "obstacle_range", obstacle_range);
move_parameter(plugin_nh, costmap_plugin_nh, "track_unknown_space", track_unknown_space);
if(plugin_nh.hasParam("observation_sources"))
{
std::string topics_string;
move_parameter(plugin_nh, costmap_plugin_nh, "observation_sources", topics_string);
robot::log_error("topics_string: %s", topics_string.c_str());
std::stringstream ss(topics_string);
std::string source;
while (ss >> source)
{
robot::NodeHandle plugin_nh_element(plugin_nh, source);
robot::NodeHandle costmap_plugin_nh_element(costmap_plugin_nh, source);
std::string topic;
std::string data_type;
bool clearing;
bool marking;
bool inf_is_valid;
std::string sensor_frame;
double observation_persistence;
double expected_update_rate;
double min_obstacle_height;
double max_obstacle_height;
double obstacle_range;
double raytrace_range;
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "topic", topic);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "sensor_frame", sensor_frame);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "observation_persistence", observation_persistence);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "expected_update_rate", expected_update_rate);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "data_type", data_type);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "clearing", clearing);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "marking", marking);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "inf_is_valid", inf_is_valid);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "min_obstacle_height", min_obstacle_height);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "max_obstacle_height", max_obstacle_height);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "obstacle_range", obstacle_range);
move_parameter(plugin_nh_element, costmap_plugin_nh_element, "raytrace_range", raytrace_range);
robot::log_info("topic: %s data_type: %s clearing: %d marking: %d inf_is_valid: %d min_obstacle_height: %f max_obstacle_height: %f", topic.c_str(), data_type.c_str(), clearing, marking, inf_is_valid, min_obstacle_height, max_obstacle_height);
}
}
}
else if (plugin_type == "DepthCameraObstacleLayer")
else if(plugin_type == "InflationLayer")
{
move_parameters<bool>(plugin_nh, costmap_plugin_nh,
{"track_unknown_space", "enabled", "footprint_clearing_enabled",
"enable_near_blocked_protection", "use_voxelized_observation", "use_global_frame_to_mark",
"clear_touches_bounds", "debug/stats"});
move_parameters<int>(plugin_nh, costmap_plugin_nh,
{"combination_method", "number_points_considered_as_blocked", "ec_cluster_min_size",
"size_of_cluster_rejection", "number_clearing_threshold"});
move_parameters<double>(plugin_nh, costmap_plugin_nh,
{"forced_clearing_distance", "ec_seg_distance", "voxel_resolution", "check_radius",
"transform_tolerance", "debug/stats_period"});
move_sources([](robot::NodeHandle& from, robot::NodeHandle& to) {
move_parameters<std::string>(from, to, {"topic", "sensor_frame"});
move_parameters<bool>(from, to, {"sensor_frame_is_optical", "marking", "inf_is_valid"});
move_parameters<double>(from, to, {"observation_persistence", "expected_update_rate", "min_obstacle_height",
"max_obstacle_height", "FOV_V", "FOV_W", "min_detect_distance",
"max_detect_distance"});
});
double cost_scaling_factor;
double inflation_radius;
move_parameter(plugin_nh, costmap_plugin_nh, "cost_scaling_factor", cost_scaling_factor);
move_parameter(plugin_nh, costmap_plugin_nh, "inflation_radius", inflation_radius);
}
}
void Costmap2DROBOT::setUnpaddedRobotFootprintPolygon(const robot_geometry_msgs::Polygon& footprint)

View File

@@ -4,12 +4,9 @@
#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;
@@ -20,18 +17,6 @@ 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)
{
@@ -459,28 +444,4 @@ 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);
}