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:
46
config/depth_camera_obstacle_layer_params.yaml
Normal file
46
config/depth_camera_obstacle_layer_params.yaml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# 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.
|
||||||
@@ -50,9 +50,13 @@
|
|||||||
#include <pcl/search/kdtree.h>
|
#include <pcl/search/kdtree.h>
|
||||||
#include <pcl/segmentation/extract_clusters.h>
|
#include <pcl/segmentation/extract_clusters.h>
|
||||||
|
|
||||||
|
#include <robot_costmap_2d/utils.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <filesystem>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -79,42 +83,26 @@ Eigen::Isometry3d toIsometry(const tf3::TransformStampedMsg& t)
|
|||||||
return iso;
|
return iso;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The source keeps parameters in the plugin namespace. Costmap2DROBOT only copies the keys of
|
// Steps 1 and 3 of the costmap layer config flow for one key: the value in the layer's default
|
||||||
// known layer types from the shared namespace into "<costmap>/<plugin>", so read the scoped
|
// file, overridden by "<costmap>/<plugin>/<key>", which Costmap2DROBOT::copyParentParameters() has
|
||||||
// value first and fall back to the shared block with the plugin's own name.
|
// filled from the shared "<plugin>:" block. A value that does not convert to T is a configuration
|
||||||
class ParamReader
|
// 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)
|
||||||
{
|
{
|
||||||
public:
|
T value = loadParam(file_node, file_key, fallback);
|
||||||
ParamReader(const robot::NodeHandle& scoped, const robot::NodeHandle& shared)
|
if (nh.hasParam(key) && !nh.getParam(key, value, value))
|
||||||
: scoped_(scoped), shared_(shared)
|
throw std::invalid_argument("DepthCameraObstacleLayer: '" + nh.getNamespace() + "/" + key +
|
||||||
{
|
"' does not convert to the type the layer reads");
|
||||||
}
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
ParamReader child(const std::string& ns) const
|
template <typename T>
|
||||||
{
|
T readParam(const YAML::Node& file_node, const robot::NodeHandle& nh, const std::string& key, const T& fallback)
|
||||||
return ParamReader(robot::NodeHandle(scoped_, ns), robot::NodeHandle(shared_, ns));
|
{
|
||||||
}
|
return readParam(file_node, key, nh, key, fallback);
|
||||||
|
}
|
||||||
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)
|
void requireRange(bool ok, const std::string& what)
|
||||||
{
|
{
|
||||||
@@ -250,33 +238,56 @@ void DepthCameraObstacleLayer::onInitialize()
|
|||||||
|
|
||||||
void DepthCameraObstacleLayer::loadParameters()
|
void DepthCameraObstacleLayer::loadParameters()
|
||||||
{
|
{
|
||||||
robot::NodeHandle nh("~");
|
// Step 1 of the config flow: the default file, like the other layers. A missing file or block
|
||||||
const std::string short_name = name_.substr(name_.find_last_of('/') + 1);
|
// stops the costmap from being built instead of running on C++ defaults.
|
||||||
const ParamReader p(robot::NodeHandle(nh, name_), robot::NodeHandle(nh, short_name));
|
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");
|
||||||
|
|
||||||
const bool track_unknown_space = p.get("track_unknown_space", layered_costmap_->isTrackingUnknown());
|
// Step 3: "<costmap>/<plugin>", filled by copyParentParameters() from the shared block.
|
||||||
|
robot::NodeHandle nh("~");
|
||||||
|
const robot::NodeHandle priv_nh(nh, 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());
|
||||||
default_value_ = track_unknown_space ? NO_INFORMATION : FREE_SPACE;
|
default_value_ = track_unknown_space ? NO_INFORMATION : FREE_SPACE;
|
||||||
|
|
||||||
enabled_ = p.get("enabled", true);
|
enabled_ = readParam(layer, priv_nh, "enabled", true);
|
||||||
footprint_clearing_enabled_ = p.get("footprint_clearing_enabled", true);
|
footprint_clearing_enabled_ = readParam(layer, priv_nh, "footprint_clearing_enabled", true);
|
||||||
combination_method_ = p.get("combination_method", 1);
|
combination_method_ = readParam(layer, priv_nh, "combination_method", 1);
|
||||||
enable_near_blocked_protection_ = p.get("enable_near_blocked_protection", true);
|
enable_near_blocked_protection_ = readParam(layer, priv_nh, "enable_near_blocked_protection", true);
|
||||||
number_points_considered_as_blocked_ = p.get("number_points_considered_as_blocked", 5);
|
number_points_considered_as_blocked_ = readParam(layer, priv_nh, "number_points_considered_as_blocked", 5);
|
||||||
forced_clearing_distance_ = p.get("forced_clearing_distance", 0.1);
|
forced_clearing_distance_ = readParam(layer, priv_nh, "forced_clearing_distance", 0.1);
|
||||||
ec_seg_distance_ = p.get("ec_seg_distance", 0.2);
|
ec_seg_distance_ = readParam(layer, priv_nh, "ec_seg_distance", 0.2);
|
||||||
ec_cluster_min_size_ = p.get("ec_cluster_min_size", 5);
|
ec_cluster_min_size_ = readParam(layer, priv_nh, "ec_cluster_min_size", 5);
|
||||||
size_of_cluster_rejection_ = p.get("size_of_cluster_rejection", 5);
|
size_of_cluster_rejection_ = readParam(layer, priv_nh, "size_of_cluster_rejection", 5);
|
||||||
voxel_resolution_ = p.get("voxel_resolution", 0.01);
|
voxel_resolution_ = readParam(layer, priv_nh, "voxel_resolution", 0.01);
|
||||||
check_radius_ = p.get("check_radius", 0.1);
|
check_radius_ = readParam(layer, priv_nh, "check_radius", 0.1);
|
||||||
number_clearing_threshold_ = p.get("number_clearing_threshold", 2);
|
number_clearing_threshold_ = readParam(layer, priv_nh, "number_clearing_threshold", 2);
|
||||||
use_voxelized_observation_ = p.get("use_voxelized_observation", true);
|
use_voxelized_observation_ = readParam(layer, priv_nh, "use_voxelized_observation", true);
|
||||||
transform_tolerance_ = p.get("transform_tolerance", 0.2);
|
transform_tolerance_ = readParam(layer, priv_nh, "transform_tolerance", 0.2);
|
||||||
const bool use_global_frame_to_mark = p.get("use_global_frame_to_mark", true);
|
const bool use_global_frame_to_mark = readParam(layer, priv_nh, "use_global_frame_to_mark", true);
|
||||||
if (p.has("clear_touches_bounds"))
|
if (layer["clear_touches_bounds"] || priv_nh.hasParam("clear_touches_bounds"))
|
||||||
robot::log_warning("DepthCameraObstacleLayer %s: clear_touches_bounds is obsolete and ignored: a cleared "
|
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());
|
"cell now always resets its master cell\n", name_.c_str());
|
||||||
debug_stats_ = p.get("debug/stats", true);
|
YAML::Node debug = layer["debug"];
|
||||||
debug_stats_period_ = p.get("debug/stats_period", 5.0);
|
debug_stats_ = readParam(debug, "stats", priv_nh, "debug/stats", true);
|
||||||
|
debug_stats_period_ = readParam(debug, "stats_period", priv_nh, "debug/stats_period", 5.0);
|
||||||
|
|
||||||
// The source's local mode keys points by costmap index, so markings move with a rolling
|
// 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.
|
// window (its README shows it). Only the global mode is ported.
|
||||||
@@ -295,26 +306,29 @@ void DepthCameraObstacleLayer::loadParameters()
|
|||||||
marking_height_under_ground_ = 100.0;
|
marking_height_under_ground_ = 100.0;
|
||||||
marking_height_above_ground_ = -100.0;
|
marking_height_above_ground_ = -100.0;
|
||||||
|
|
||||||
std::stringstream ss(p.get("observation_sources", std::string("")));
|
std::stringstream ss(readParam(layer, priv_nh, "observation_sources", std::string("")));
|
||||||
std::string name;
|
std::string name;
|
||||||
while (ss >> name)
|
while (ss >> name)
|
||||||
{
|
{
|
||||||
const ParamReader s = p.child(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);
|
||||||
std::unique_ptr<Source> src(new Source());
|
std::unique_ptr<Source> src(new Source());
|
||||||
src->name = name;
|
src->name = name;
|
||||||
src->topic = s.get("topic", name);
|
src->topic = readParam(source_defaults, s, "topic", name);
|
||||||
src->sensor_frame = s.get("sensor_frame", std::string(""));
|
src->sensor_frame = readParam(source_defaults, s, "sensor_frame", std::string(""));
|
||||||
src->sensor_frame_is_optical = s.get("sensor_frame_is_optical", false);
|
src->sensor_frame_is_optical = readParam(source_defaults, s, "sensor_frame_is_optical", false);
|
||||||
src->observation_keep_time = s.get("observation_persistence", 0.0);
|
src->observation_keep_time = readParam(source_defaults, s, "observation_persistence", 0.0);
|
||||||
src->expected_update_rate = s.get("expected_update_rate", 0.0);
|
src->expected_update_rate = readParam(source_defaults, s, "expected_update_rate", 0.0);
|
||||||
src->min_obstacle_height = s.get("min_obstacle_height", 0.0);
|
src->min_obstacle_height = readParam(source_defaults, s, "min_obstacle_height", 0.0);
|
||||||
src->max_obstacle_height = s.get("max_obstacle_height", 2.0);
|
src->max_obstacle_height = readParam(source_defaults, s, "max_obstacle_height", 2.0);
|
||||||
src->marking = s.get("marking", true);
|
src->marking = readParam(source_defaults, s, "marking", true);
|
||||||
src->fov_v = s.get("FOV_V", 1.0);
|
src->fov_v = readParam(source_defaults, s, "FOV_V", 1.0);
|
||||||
src->fov_w = s.get("FOV_W", 1.5);
|
src->fov_w = readParam(source_defaults, s, "FOV_W", 1.5);
|
||||||
src->min_detect_distance = s.get("min_detect_distance", 0.15);
|
src->min_detect_distance = readParam(source_defaults, s, "min_detect_distance", 0.15);
|
||||||
src->max_detect_distance = s.get("max_detect_distance", 2.5);
|
src->max_detect_distance = readParam(source_defaults, s, "max_detect_distance", 2.5);
|
||||||
if (s.get("inf_is_valid", false))
|
if (readParam(source_defaults, s, "inf_is_valid", false))
|
||||||
robot::log_warning("DepthCameraObstacleLayer: inf_is_valid is not applicable to PointCloud observations\n");
|
robot::log_warning("DepthCameraObstacleLayer: inf_is_valid is not applicable to PointCloud observations\n");
|
||||||
|
|
||||||
const std::string what = "source " + name + ": ";
|
const std::string what = "source " + name + ": ";
|
||||||
|
|||||||
@@ -48,6 +48,8 @@
|
|||||||
#include <tf3/convert.h>
|
#include <tf3/convert.h>
|
||||||
#include <tf3/utils.h>
|
#include <tf3/utils.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <boost/dll/import.hpp>
|
#include <boost/dll/import.hpp>
|
||||||
@@ -64,10 +66,26 @@ void move_parameter(robot::NodeHandle& old_h, robot::NodeHandle& new_h, std::str
|
|||||||
if (!old_h.hasParam(name))
|
if (!old_h.hasParam(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
old_h.getParam(name, value);
|
// 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");
|
||||||
new_h.setParam(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) :
|
Costmap2DROBOT::Costmap2DROBOT(const std::string& name, tf3::BufferCore& tf) :
|
||||||
layered_costmap_(NULL),
|
layered_costmap_(NULL),
|
||||||
name_(name),
|
name_(name),
|
||||||
@@ -356,132 +374,81 @@ void Costmap2DROBOT::copyParentParameters(const std::string& costmap_name,
|
|||||||
const std::string& plugin_type,
|
const std::string& plugin_type,
|
||||||
robot::NodeHandle& nh)
|
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_nh(nh, costmap_name);
|
||||||
robot::NodeHandle costmap_plugin_nh(costmap_nh, plugin_name);
|
robot::NodeHandle costmap_plugin_nh(costmap_nh, plugin_name);
|
||||||
robot::NodeHandle plugin_nh(nh, plugin_name);
|
robot::NodeHandle plugin_nh(nh, plugin_name);
|
||||||
if(plugin_type == "StaticLayer")
|
|
||||||
{
|
// observation_sources, then the keys of each source under "<plugin>/<source>/".
|
||||||
std::string map_topic;
|
const auto move_sources = [&](const auto& move_source_keys) {
|
||||||
int unknown_cost_value;
|
std::string topics_string;
|
||||||
int lethal_cost_threshold;
|
move_parameter(plugin_nh, costmap_plugin_nh, "observation_sources", topics_string);
|
||||||
bool track_unknown_space;
|
std::stringstream ss(topics_string);
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "map_topic", map_topic);
|
std::string source;
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "unknown_cost_value", unknown_cost_value);
|
while (ss >> source)
|
||||||
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"))
|
|
||||||
{
|
{
|
||||||
std::string topics_string;
|
robot::NodeHandle plugin_nh_element(plugin_nh, source);
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "observation_sources", topics_string);
|
robot::NodeHandle costmap_plugin_nh_element(costmap_plugin_nh, source);
|
||||||
robot::log_error("topics_string: %s", topics_string.c_str());
|
move_source_keys(plugin_nh_element, costmap_plugin_nh_element);
|
||||||
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 == "ObstacleLayer")
|
|
||||||
|
if (plugin_type == "StaticLayer")
|
||||||
{
|
{
|
||||||
double max_obstacle_height;
|
move_parameters<std::string>(plugin_nh, costmap_plugin_nh, {"map_topic", "base_frame_id"});
|
||||||
double raytrace_range;
|
move_parameters<int>(plugin_nh, costmap_plugin_nh, {"unknown_cost_value", "lethal_cost_threshold"});
|
||||||
double obstacle_range;
|
move_parameters<bool>(plugin_nh, costmap_plugin_nh,
|
||||||
bool track_unknown_space;
|
{"enabled", "track_unknown_space", "first_map_only", "subscribe_to_updates",
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "max_obstacle_height", max_obstacle_height);
|
"use_maximum", "trinary_costmap"});
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "raytrace_range", raytrace_range);
|
}
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "obstacle_range", obstacle_range);
|
else if (plugin_type == "ObstacleLayer" || plugin_type == "VoxelLayer")
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "track_unknown_space", track_unknown_space);
|
{
|
||||||
if(plugin_nh.hasParam("observation_sources"))
|
// 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")
|
||||||
{
|
{
|
||||||
std::string topics_string;
|
move_parameters<double>(plugin_nh, costmap_plugin_nh, {"origin_z", "z_resolution", "unknown_threshold"});
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "observation_sources", topics_string);
|
move_parameters<int>(plugin_nh, costmap_plugin_nh, {"z_voxels", "mark_threshold"});
|
||||||
robot::log_error("topics_string: %s", topics_string.c_str());
|
move_parameters<bool>(plugin_nh, costmap_plugin_nh, {"enabled"});
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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 == "InflationLayer")
|
||||||
{
|
{
|
||||||
double cost_scaling_factor;
|
move_parameters<double>(plugin_nh, costmap_plugin_nh, {"cost_scaling_factor", "inflation_radius"});
|
||||||
double inflation_radius;
|
move_parameters<bool>(plugin_nh, costmap_plugin_nh, {"enabled", "inflate_unknown"});
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "cost_scaling_factor", cost_scaling_factor);
|
}
|
||||||
move_parameter(plugin_nh, costmap_plugin_nh, "inflation_radius", inflation_radius);
|
else if (plugin_type == "DepthCameraObstacleLayer")
|
||||||
|
{
|
||||||
|
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"});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Costmap2DROBOT::setUnpaddedRobotFootprintPolygon(const robot_geometry_msgs::Polygon& footprint)
|
void Costmap2DROBOT::setUnpaddedRobotFootprintPolygon(const robot_geometry_msgs::Polygon& footprint)
|
||||||
|
|||||||
@@ -4,9 +4,12 @@
|
|||||||
#include <robot_sensor_msgs/DepthCameraData.h>
|
#include <robot_sensor_msgs/DepthCameraData.h>
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace robot_costmap_2d;
|
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 double kFovV = 0.76;
|
||||||
constexpr char kTopic[] = "/camera/depth/points_proc";
|
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).
|
// 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)
|
tf3::TransformStampedMsg pose(robot::Time stamp, double yaw = 0)
|
||||||
{
|
{
|
||||||
@@ -444,4 +459,28 @@ TEST(DepthCameraLayerConfig, RejectsUnportedModeAndOutOfRangeValues)
|
|||||||
cfg = baseConfig();
|
cfg = baseConfig();
|
||||||
cfg["voxel_resolution"] = 0.0;
|
cfg["voxel_resolution"] = 0.0;
|
||||||
expectThrow(cfg);
|
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