Compare commits
6 Commits
feature/de
...
3539afbfb4
| Author | SHA1 | Date | |
|---|---|---|---|
| 3539afbfb4 | |||
| 757b381659 | |||
| 9b93a45b45 | |||
| e40e9c0104 | |||
| 3b89add5ee | |||
| 64974d48b7 |
@@ -337,6 +337,7 @@ if(BUILD_COSTMAP_TESTS)
|
||||
target_link_libraries(depth_camera_obstacle_layer_test PRIVATE
|
||||
plugins
|
||||
robot_costmap_2d
|
||||
yaml-cpp
|
||||
GTest::GTest
|
||||
GTest::Main
|
||||
)
|
||||
|
||||
12
README.md
12
README.md
@@ -472,10 +472,12 @@ phản chiếu các điểm đó theo từng ô (cột có điểm là `LETHAL`,
|
||||
hiện tại có ít hơn `number_clearing_threshold` điểm trong bán kính `check_radius`,
|
||||
hoặc nếu điểm cách tâm robot dưới `forced_clearing_distance`. Cloud có
|
||||
`<= number_points_considered_as_blocked` điểm thì xóa hết trong khối nhìn, trừ khi
|
||||
bật `enable_near_blocked_protection`.
|
||||
bật `enable_near_blocked_protection`. Bật `occlusion_guard` thì tia nhìn quyết định thêm:
|
||||
điểm có vật gần hơn che trên tia nhìn tới nó được **giữ**, điểm mà camera nhìn xuyên qua
|
||||
(thấy nền phía sau) bị **xóa** dù còn điểm khác trong `check_radius`.
|
||||
3. **Đánh dấu:** gom cụm Euclidean (`ec_seg_distance`); cụm có `<= size_of_cluster_rejection`
|
||||
điểm bị bỏ; điểm của cụm còn lại nằm trong khối nhìn và cách mọi mặt khối nhìn hơn
|
||||
12 cm thì được lưu.
|
||||
`attach_distance` (mặc định 12 cm) thì được lưu.
|
||||
4. Điểm ra ngoài cửa sổ costmap (rolling window) bị bỏ; điểm dưới footprint robot bị xóa khi
|
||||
bật `footprint_clearing_enabled`.
|
||||
|
||||
@@ -505,7 +507,8 @@ Tham số chung của layer:
|
||||
| `footprint_clearing_enabled` | `true` | Xóa ô và điểm đã lưu nằm dưới footprint robot. |
|
||||
| `combination_method` | `1` | Như các layer khác. |
|
||||
| `use_global_frame_to_mark` | `true` | Chỉ hỗ trợ `true`; `false` báo lỗi. |
|
||||
| `debug/stats` | `true` | Log `[debug/stats]` định kỳ: số điểm, số điểm đánh dấu/xóa, TF chờ/bỏ, thời gian. |
|
||||
| `occlusion_guard` | `false` | `true`: giữ điểm bị vật gần hơn che, xóa điểm mà camera nhìn xuyên qua. Dựng một ảnh khoảng cách nhỏ (bin 0.01 theo tang góc) từ cả cloud trước lọc chiều cao. Hằng số đã kiểm offline trên 10 bag robot KIT (22–23/10/2026). `false`: chỉ phép kd-tree như gói gốc. |
|
||||
| `debug/stats` | `true` | Log `[debug/stats]` định kỳ: số điểm, số điểm đánh dấu/xóa, TF chờ/bỏ, `kept_occluded` / `cleared_seen_through` của `occlusion_guard`, thời gian. |
|
||||
| `debug/stats_period` | `5.0 s` | Chu kỳ log trên. |
|
||||
|
||||
Tham số của từng source (camera):
|
||||
@@ -518,6 +521,7 @@ Tham số của từng source (camera):
|
||||
| `FOV_W`, `FOV_V` | `1.5`, `1.0 rad` | Góc nhìn ngang/dọc của khối nhìn. Tính từ `camera_info`. |
|
||||
| `min_detect_distance`, `max_detect_distance` | `0.15`, `2.5 m` | Mặt gần/xa của khối nhìn. Ngoài khoảng này không đánh dấu, không xóa. |
|
||||
| `min_obstacle_height`, `max_obstacle_height` | `0.0`, `2.0 m` | Lọc độ cao trong frame global. |
|
||||
| `attach_distance` | `0.12 m` | Điểm cách bất kỳ mặt khối nhìn dưới mức này không được đánh dấu (mép vật bị cắt, nhiễu mép ảnh). Giảm: vật thấp sát mép dưới FOV được đánh dấu; quá nhỏ (0.05) làm tăng ô ma trước mũi robot. Miền `[0, (max_detect_distance - min_detect_distance) / 2)`. |
|
||||
| `marking` | `true` | `false`: bỏ qua source. |
|
||||
| `observation_persistence` | `0.0 s` | `0`: chỉ dùng cloud mới nhất. |
|
||||
| `expected_update_rate` | `0.0 s` | Quá lâu không có cloud thì costmap báo không current. `0`: tắt. |
|
||||
@@ -530,6 +534,8 @@ Giới hạn đã biết:
|
||||
hai.
|
||||
- Khối nhìn đối xứng và trùng mép ảnh; dải mép ảnh không có depth (lọc mép, dải stereo
|
||||
bên trái) vẫn được coi là "nhìn thấy trống".
|
||||
- `occlusion_guard` chỉ có tác dụng trong khối nhìn: vết của vật động đã ra ngoài FOV vẫn được
|
||||
giữ như trên. Điểm bị che được giữ tới khi camera nhìn lại được chỗ đó.
|
||||
- Layer không dùng ảnh depth (`DepthCameraData`): host phải đổi ảnh sang `PointCloud2` trước khi đẩy vào.
|
||||
|
||||
### 5.7. InflationLayer
|
||||
|
||||
54
config/depth_camera_obstacle_layer_params.yaml
Normal file
54
config/depth_camera_obstacle_layer_params.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
# 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] Chống xoá khi bị che, dùng tia nhìn của ảnh depth (cả sàn, trước lọc chiều cao).
|
||||
# true: điểm đã lưu mà có vật gần hơn nằm trên tia nhìn tới nó thì GIỮ (người đi ngang trước thùng
|
||||
# không còn xoá thùng); điểm mà camera nhìn xuyên qua thấy nền phía sau thì XOÁ, kể cả khi còn điểm
|
||||
# khác trong check_radius (vết của vật vừa dịch đi biến nhanh hơn).
|
||||
# false: chỉ dùng phép kd-tree như gói gốc. Bật thì tốn thêm một ảnh khoảng cách nhỏ mỗi cloud.
|
||||
# Vết nằm NGOÀI FOV vẫn không xoá được dù bật hay tắt.
|
||||
occlusion_guard: false
|
||||
# [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, attach_distance...) KHÔNG
|
||||
# đặt ở đây mà trong khối <plugin>/<tên nguồn>/ của config costmap. attach_distance [m] mặc định
|
||||
# 0.12 như gói gốc: điểm cách mặt khối nhìn dưới mức này không được đánh dấu.
|
||||
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.
|
||||
@@ -1,18 +1,13 @@
|
||||
# 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
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
* getType() is its own DEPTH_CAMERA_LAYER, which SensorGateway feeds PointCloud2 and
|
||||
* DepthCameraData; no ROS publishers or dynamic_reconfigure; `sensor_frame_is_optical` builds the frustum in a Z-forward
|
||||
* optical frame; markings that leave the rolling window are dropped (B6).
|
||||
* Additions over the source, both off by default so the source behaviour stays the default:
|
||||
* the attach band width is a per-source parameter (`attach_distance`, the source hard-codes
|
||||
* 0.12 m), and `occlusion_guard` adds depth-ray evidence to the clearing (keep a stored point a
|
||||
* nearer return hides, clear one the camera sees past).
|
||||
*********************************************************************/
|
||||
#ifndef ROBOT_COSTMAP_2D_DEPTH_CAMERA_OBSTACLE_LAYER_H_
|
||||
#define ROBOT_COSTMAP_2D_DEPTH_CAMERA_OBSTACLE_LAYER_H_
|
||||
@@ -52,7 +56,7 @@ namespace robot_costmap_2d
|
||||
*
|
||||
* Same construction as costmap_depth_camera::Observation: 8 vertices from the configured
|
||||
* FOV and detect range in the sensor frame, transformed to the global frame, then 6 inward
|
||||
* normals (inside test) and 6 plane equations (12 cm "attach" band test).
|
||||
* normals (inside test) and 6 plane equations ("attach" band test).
|
||||
*/
|
||||
struct DepthCameraFrustum
|
||||
{
|
||||
@@ -61,6 +65,9 @@ struct DepthCameraFrustum
|
||||
std::array<Eigen::Vector3f, 6> normals; ///< near right bottom left far top
|
||||
std::array<Eigen::Vector4f, 6> planes; ///< a, b, c, d of each face
|
||||
double max_detect_distance = 2.5; ///< [m]
|
||||
/// [m] Points this close to a face are not marked: an object cut by the image edge or the
|
||||
/// noisy image border. 0.12 in the source; a wide band hides low objects near the lower FOV edge.
|
||||
float attach_distance = 0.12f;
|
||||
|
||||
/**
|
||||
* @brief Build the frustum.
|
||||
@@ -69,17 +76,62 @@ struct DepthCameraFrustum
|
||||
* @param min_d, max_d near / far plane distance along the viewing axis [m]
|
||||
* @param optical true: sensor frame is Z forward, X right, Y down (REP 103 optical);
|
||||
* false: X forward, Y left, Z up (camera_link), as the source assumes
|
||||
* @param attach_d width of the attach band [m], see attach_distance
|
||||
*/
|
||||
void build(const Eigen::Isometry3d& T_global_sensor, double fov_w, double fov_v, double min_d,
|
||||
double max_d, bool optical);
|
||||
double max_d, bool optical, double attach_d = 0.12);
|
||||
|
||||
/// Inside all 6 faces (FrustumUtils::isInsideFRUSTUMwoAttach without the band test).
|
||||
bool inside(const Eigen::Vector3f& p) const;
|
||||
|
||||
/// Within 0.12 m of a face plane and within max_detect_distance + 0.5 m of the origin in XY.
|
||||
/// Within attach_distance of a face plane and within max_detect_distance + 0.5 m of the origin in XY.
|
||||
bool nearFace(const Eigen::Vector3f& p) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Nearest depth return per viewing ray of one observation, for the occlusion guard.
|
||||
*
|
||||
* Rays are binned by their tangent (x / z and y / z in the optical frame); each bin keeps the
|
||||
* smallest range it saw. It is built from the whole cloud before the height gate: the floor the
|
||||
* gate drops is exactly what shows that a stored point is no longer there.
|
||||
*/
|
||||
struct DepthCameraRangeImage
|
||||
{
|
||||
/// What the returns around the ray to a stored point say about it.
|
||||
enum class Evidence
|
||||
{
|
||||
kNone, ///< no usable return around the ray, or a return at the point itself
|
||||
kOccluded, ///< something nearer hides the point: clearing must keep it
|
||||
kSeenThrough, ///< the camera sees past the point: it is gone
|
||||
};
|
||||
|
||||
/// Empty image covering the frustum of a sensor at T_global_sensor.
|
||||
void reset(const Eigen::Isometry3d& T_global_sensor, double fov_w, double fov_v, bool optical);
|
||||
/// Adds one return given in the sensor frame.
|
||||
void addSensorPoint(const Eigen::Vector3f& p);
|
||||
/// Evidence about a point given in the global frame; kNone while the image is empty.
|
||||
Evidence test(const Eigen::Vector3f& p_global) const;
|
||||
bool empty() const
|
||||
{
|
||||
return min_range_.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
Eigen::Vector3f toOptical(const Eigen::Vector3f& p) const;
|
||||
/// Bin of a point in optical coordinates; false when it is too close or outside the image.
|
||||
bool bin(const Eigen::Vector3f& q, int& u, int& v) const;
|
||||
std::size_t index(int u, int v) const
|
||||
{
|
||||
return static_cast<std::size_t>(v + half_v_) * (2 * half_u_ + 1) + static_cast<std::size_t>(u + half_u_);
|
||||
}
|
||||
|
||||
Eigen::Isometry3f sensor_from_global_ = Eigen::Isometry3f::Identity();
|
||||
bool optical_ = true;
|
||||
int half_u_ = 0;
|
||||
int half_v_ = 0;
|
||||
std::vector<float> min_range_; ///< [m] (2 half_u + 1) x (2 half_v + 1), +inf where nothing returned
|
||||
};
|
||||
|
||||
/// FrustumUtils::isInsideFRUSTUMs: inside at least one frustum.
|
||||
bool insideAnyFrustum(const std::vector<DepthCameraFrustum>& frustums, const Eigen::Vector3f& p);
|
||||
|
||||
@@ -132,6 +184,7 @@ private:
|
||||
robot::Time stamp;
|
||||
std::vector<Eigen::Vector3f> points;
|
||||
DepthCameraFrustum frustum;
|
||||
DepthCameraRangeImage range; ///< whole cloud before the gate; empty unless occlusion_guard
|
||||
};
|
||||
|
||||
/// ObservationBuffer of the source, one per entry of observation_sources.
|
||||
@@ -149,6 +202,7 @@ private:
|
||||
double fov_v = 1.0; ///< [rad]
|
||||
double min_detect_distance = 0.15; ///< [m]
|
||||
double max_detect_distance = 2.5; ///< [m]
|
||||
double attach_distance = 0.12; ///< [m] marking-free band near each frustum face
|
||||
bool marking = true;
|
||||
|
||||
std::list<Observation> observations; ///< newest first
|
||||
@@ -164,8 +218,10 @@ private:
|
||||
void purgeStale(Source& source) const;
|
||||
bool sourceIsCurrent(const Source& source) const;
|
||||
|
||||
/// range_images[i] belongs to frustums[i]; null when that observation has no range image.
|
||||
void clearMarkingByKdtree(const std::vector<Eigen::Vector3f>& cloud,
|
||||
const std::vector<DepthCameraFrustum>& frustums, double robot_x,
|
||||
const std::vector<DepthCameraFrustum>& frustums,
|
||||
const std::vector<const DepthCameraRangeImage*>& range_images, double robot_x,
|
||||
double robot_y, double* min_x, double* min_y, double* max_x,
|
||||
double* max_y);
|
||||
void processCluster(const std::vector<DepthCameraFrustum>& frustums,
|
||||
@@ -220,6 +276,7 @@ private:
|
||||
// Additions of this port.
|
||||
bool debug_stats_ = true; ///< debug/stats: periodic counters log
|
||||
double debug_stats_period_ = 5.0; ///< [s]
|
||||
bool occlusion_guard_ = false; ///< depth-ray evidence in the clearing, see clearMarkingByKdtree
|
||||
|
||||
/// (ix, iy) of the cell corner -> {height index -> label}, global frame (use_global_frame_to_mark).
|
||||
std::map<std::pair<int, int>, std::map<int, float>> pc_3d_map_global_;
|
||||
@@ -237,6 +294,8 @@ private:
|
||||
std::size_t tf_waits = 0;
|
||||
std::size_t tf_drops = 0;
|
||||
std::size_t dropped_out_of_window = 0;
|
||||
std::size_t kept_occluded = 0; ///< points the kd-tree test would clear, kept as hidden
|
||||
std::size_t cleared_seen_through = 0; ///< points the kd-tree test would keep, cleared as seen past
|
||||
double bounds_ms_sum = 0.0;
|
||||
double bounds_ms_max = 0.0;
|
||||
} stats_;
|
||||
|
||||
@@ -50,9 +50,13 @@
|
||||
#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>
|
||||
@@ -62,13 +66,26 @@ namespace robot_costmap_2d
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// Distance of the "attach" band around each frustum face, hard-coded in the source [m].
|
||||
constexpr float kAttachDistance = 0.12f;
|
||||
// Stored columns farther than this from the robot are not tested for clearing [m].
|
||||
constexpr double kClearingSkipDistance = 10.0;
|
||||
// VoxelGrid leaf of the combined observation, hard-coded in the source [m].
|
||||
constexpr float kObservationLeaf = 0.05f;
|
||||
|
||||
// Occlusion guard. The values were checked on 10 KIT robot bags (22-23/10/2026) with an offline
|
||||
// replay of this layer; change them only with a new replay.
|
||||
// Ray bin in tangent units: 0.01 is ~0.57 deg, ~1.7 px of the D410 at fx = 300.
|
||||
constexpr float kRangeBin = 0.01f;
|
||||
// Returns and stored points closer than this along the viewing axis carry no evidence [m].
|
||||
constexpr float kRangeMinDepth = 0.1f;
|
||||
// Depth noise band around a stored point at range r: kRangeMargin + kRangeMarginPerSqM * r^2 [m].
|
||||
// Stereo depth error grows with r^2.
|
||||
constexpr float kRangeMargin = 0.05f;
|
||||
constexpr float kRangeMarginPerSqM = 0.02f;
|
||||
// Of the 3 x 3 bins around the ray: this many nearer bins hide the point...
|
||||
constexpr int kOccludingBins = 2;
|
||||
// ...and this many farther bins, the centre one among them, show that the camera sees past it.
|
||||
constexpr int kSeeThroughBins = 6;
|
||||
|
||||
Eigen::Isometry3d toIsometry(const tf3::TransformStampedMsg& t)
|
||||
{
|
||||
const auto& q = t.transform.rotation;
|
||||
@@ -79,43 +96,6 @@ Eigen::Isometry3d toIsometry(const tf3::TransformStampedMsg& t)
|
||||
return iso;
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
public:
|
||||
ParamReader(const robot::NodeHandle& scoped, const robot::NodeHandle& shared)
|
||||
: scoped_(scoped), shared_(shared)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!ok)
|
||||
@@ -128,9 +108,10 @@ void requireRange(bool ok, const std::string& what)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
void DepthCameraFrustum::build(const Eigen::Isometry3d& T_global_sensor, double fov_w, double fov_v,
|
||||
double min_d, double max_d, bool optical)
|
||||
double min_d, double max_d, bool optical, double attach_d)
|
||||
{
|
||||
max_detect_distance = max_d;
|
||||
attach_distance = static_cast<float>(attach_d);
|
||||
const double tw = std::tan(fov_w / 2.0);
|
||||
const double tv = std::tan(fov_v / 2.0);
|
||||
// findFrustumVertex(): X forward, +Y left, +Z up. TL = +Y +Z, BR = -Y -Z.
|
||||
@@ -197,7 +178,7 @@ bool DepthCameraFrustum::nearFace(const Eigen::Vector3f& p) const
|
||||
{
|
||||
const float dis = std::fabs(pl[0] * p.x() + pl[1] * p.y() + pl[2] * p.z() + pl[3]) /
|
||||
std::sqrt(pl[0] * pl[0] + pl[1] * pl[1] + pl[2] * pl[2]);
|
||||
if (dis <= kAttachDistance &&
|
||||
if (dis <= attach_distance &&
|
||||
std::hypot(p.x() - origin.x(), p.y() - origin.y()) < max_detect_distance + 0.5)
|
||||
return true;
|
||||
}
|
||||
@@ -227,6 +208,84 @@ bool attachedToFrustums(const std::vector<DepthCameraFrustum>& frustums, const E
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Range image (occlusion guard, an addition of this port)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
void DepthCameraRangeImage::reset(const Eigen::Isometry3d& T_global_sensor, double fov_w, double fov_v,
|
||||
bool optical)
|
||||
{
|
||||
sensor_from_global_ = T_global_sensor.inverse().cast<float>();
|
||||
optical_ = optical;
|
||||
// One spare bin on each side: a ray on the frustum edge still has all its 3 x 3 neighbours.
|
||||
half_u_ = static_cast<int>(std::ceil(std::tan(fov_w / 2.0) / kRangeBin)) + 1;
|
||||
half_v_ = static_cast<int>(std::ceil(std::tan(fov_v / 2.0) / kRangeBin)) + 1;
|
||||
min_range_.assign(static_cast<std::size_t>(2 * half_u_ + 1) * static_cast<std::size_t>(2 * half_v_ + 1),
|
||||
std::numeric_limits<float>::infinity());
|
||||
}
|
||||
|
||||
Eigen::Vector3f DepthCameraRangeImage::toOptical(const Eigen::Vector3f& p) const
|
||||
{
|
||||
// Same axes as DepthCameraFrustum::build: camera_link X forward, Y left, Z up.
|
||||
return optical_ ? p : Eigen::Vector3f(-p.y(), -p.z(), p.x());
|
||||
}
|
||||
|
||||
bool DepthCameraRangeImage::bin(const Eigen::Vector3f& q, int& u, int& v) const
|
||||
{
|
||||
if (min_range_.empty() || !(q.z() > kRangeMinDepth))
|
||||
return false;
|
||||
const float fu = q.x() / q.z() / kRangeBin;
|
||||
const float fv = q.y() / q.z() / kRangeBin;
|
||||
if (!(std::fabs(fu) <= half_u_ + 0.5f) || !(std::fabs(fv) <= half_v_ + 0.5f))
|
||||
return false;
|
||||
u = static_cast<int>(std::lround(fu));
|
||||
v = static_cast<int>(std::lround(fv));
|
||||
return std::abs(u) <= half_u_ && std::abs(v) <= half_v_;
|
||||
}
|
||||
|
||||
void DepthCameraRangeImage::addSensorPoint(const Eigen::Vector3f& p)
|
||||
{
|
||||
const Eigen::Vector3f q = toOptical(p);
|
||||
int u, v;
|
||||
if (!bin(q, u, v))
|
||||
return;
|
||||
float& slot = min_range_[index(u, v)];
|
||||
slot = std::min(slot, q.norm());
|
||||
}
|
||||
|
||||
DepthCameraRangeImage::Evidence DepthCameraRangeImage::test(const Eigen::Vector3f& p_global) const
|
||||
{
|
||||
const Eigen::Vector3f q = toOptical(sensor_from_global_ * p_global);
|
||||
int u, v;
|
||||
if (!bin(q, u, v))
|
||||
return Evidence::kNone;
|
||||
const float r = q.norm();
|
||||
const float margin = kRangeMargin + kRangeMarginPerSqM * r * r;
|
||||
int nearer = 0, farther = 0;
|
||||
for (int du = -1; du <= 1; ++du)
|
||||
{
|
||||
for (int dv = -1; dv <= 1; ++dv)
|
||||
{
|
||||
const int a = u + du, b = v + dv;
|
||||
if (std::abs(a) > half_u_ || std::abs(b) > half_v_)
|
||||
continue;
|
||||
// Only the nearest return of a bin counts: a bin that grazes the floor spans tens of
|
||||
// centimetres of range, so its farthest return says nothing. +inf (no return) counts for neither.
|
||||
const float m = min_range_[index(a, b)];
|
||||
if (m < r - margin)
|
||||
++nearer;
|
||||
else if (std::isfinite(m) && m > r + margin)
|
||||
++farther;
|
||||
}
|
||||
}
|
||||
const float centre = min_range_[index(u, v)];
|
||||
if (nearer >= kOccludingBins || centre < r - margin)
|
||||
return Evidence::kOccluded;
|
||||
if (farther >= kSeeThroughBins && std::isfinite(centre) && centre > r + margin)
|
||||
return Evidence::kSeenThrough;
|
||||
return Evidence::kNone;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Layer
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@@ -250,33 +309,103 @@ 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");
|
||||
|
||||
// ===== 1. Defaults from the layer's file =====
|
||||
// track_unknown_space is not in the file on purpose: unset, the layer follows the costmap.
|
||||
bool track_unknown_space = loadParam(layer, "track_unknown_space", layered_costmap_->isTrackingUnknown());
|
||||
enabled_ = loadParam(layer, "enabled", true);
|
||||
footprint_clearing_enabled_ = loadParam(layer, "footprint_clearing_enabled", true);
|
||||
combination_method_ = loadParam(layer, "combination_method", 1);
|
||||
enable_near_blocked_protection_ = loadParam(layer, "enable_near_blocked_protection", true);
|
||||
number_points_considered_as_blocked_ = loadParam(layer, "number_points_considered_as_blocked", 5);
|
||||
forced_clearing_distance_ = loadParam(layer, "forced_clearing_distance", 0.1);
|
||||
ec_seg_distance_ = loadParam(layer, "ec_seg_distance", 0.2);
|
||||
ec_cluster_min_size_ = loadParam(layer, "ec_cluster_min_size", 5);
|
||||
size_of_cluster_rejection_ = loadParam(layer, "size_of_cluster_rejection", 5);
|
||||
voxel_resolution_ = loadParam(layer, "voxel_resolution", 0.01);
|
||||
check_radius_ = loadParam(layer, "check_radius", 0.1);
|
||||
number_clearing_threshold_ = loadParam(layer, "number_clearing_threshold", 2);
|
||||
use_voxelized_observation_ = loadParam(layer, "use_voxelized_observation", true);
|
||||
transform_tolerance_ = loadParam(layer, "transform_tolerance", 0.2);
|
||||
bool use_global_frame_to_mark = loadParam(layer, "use_global_frame_to_mark", true);
|
||||
std::string topics_string = loadParam(layer, "observation_sources", std::string(""));
|
||||
debug_stats_ = loadParam(layer["debug"], "stats", true);
|
||||
debug_stats_period_ = loadParam(layer["debug"], "stats_period", 5.0);
|
||||
occlusion_guard_ = loadParam(layer, "occlusion_guard", false);
|
||||
|
||||
// ===== 2. Override from "<costmap>/<plugin>", which copyParentParameters() filled from the
|
||||
// shared "<plugin>:" block (only when the key exists) =====
|
||||
// getParam() gets the current value as its default: a value of the wrong type then keeps the
|
||||
// file default instead of becoming 0/false/"". A wrong type in the shared block already stopped
|
||||
// copyParentParameters().
|
||||
robot::NodeHandle nh("~");
|
||||
const std::string short_name = name_.substr(name_.find_last_of('/') + 1);
|
||||
const ParamReader p(robot::NodeHandle(nh, name_), robot::NodeHandle(nh, short_name));
|
||||
robot::NodeHandle priv_nh(nh, name_);
|
||||
if (priv_nh.hasParam("track_unknown_space"))
|
||||
priv_nh.getParam("track_unknown_space", track_unknown_space, track_unknown_space);
|
||||
if (priv_nh.hasParam("enabled"))
|
||||
priv_nh.getParam("enabled", enabled_, enabled_);
|
||||
if (priv_nh.hasParam("footprint_clearing_enabled"))
|
||||
priv_nh.getParam("footprint_clearing_enabled", footprint_clearing_enabled_, footprint_clearing_enabled_);
|
||||
if (priv_nh.hasParam("combination_method"))
|
||||
priv_nh.getParam("combination_method", combination_method_, combination_method_);
|
||||
if (priv_nh.hasParam("enable_near_blocked_protection"))
|
||||
priv_nh.getParam("enable_near_blocked_protection", enable_near_blocked_protection_,
|
||||
enable_near_blocked_protection_);
|
||||
if (priv_nh.hasParam("number_points_considered_as_blocked"))
|
||||
priv_nh.getParam("number_points_considered_as_blocked", number_points_considered_as_blocked_,
|
||||
number_points_considered_as_blocked_);
|
||||
if (priv_nh.hasParam("forced_clearing_distance"))
|
||||
priv_nh.getParam("forced_clearing_distance", forced_clearing_distance_, forced_clearing_distance_);
|
||||
if (priv_nh.hasParam("ec_seg_distance"))
|
||||
priv_nh.getParam("ec_seg_distance", ec_seg_distance_, ec_seg_distance_);
|
||||
if (priv_nh.hasParam("ec_cluster_min_size"))
|
||||
priv_nh.getParam("ec_cluster_min_size", ec_cluster_min_size_, ec_cluster_min_size_);
|
||||
if (priv_nh.hasParam("size_of_cluster_rejection"))
|
||||
priv_nh.getParam("size_of_cluster_rejection", size_of_cluster_rejection_, size_of_cluster_rejection_);
|
||||
if (priv_nh.hasParam("voxel_resolution"))
|
||||
priv_nh.getParam("voxel_resolution", voxel_resolution_, voxel_resolution_);
|
||||
if (priv_nh.hasParam("check_radius"))
|
||||
priv_nh.getParam("check_radius", check_radius_, check_radius_);
|
||||
if (priv_nh.hasParam("number_clearing_threshold"))
|
||||
priv_nh.getParam("number_clearing_threshold", number_clearing_threshold_, number_clearing_threshold_);
|
||||
if (priv_nh.hasParam("use_voxelized_observation"))
|
||||
priv_nh.getParam("use_voxelized_observation", use_voxelized_observation_, use_voxelized_observation_);
|
||||
if (priv_nh.hasParam("transform_tolerance"))
|
||||
priv_nh.getParam("transform_tolerance", transform_tolerance_, transform_tolerance_);
|
||||
if (priv_nh.hasParam("use_global_frame_to_mark"))
|
||||
priv_nh.getParam("use_global_frame_to_mark", use_global_frame_to_mark, use_global_frame_to_mark);
|
||||
if (priv_nh.hasParam("observation_sources"))
|
||||
priv_nh.getParam("observation_sources", topics_string, topics_string);
|
||||
if (priv_nh.hasParam("debug/stats"))
|
||||
priv_nh.getParam("debug/stats", debug_stats_, debug_stats_);
|
||||
if (priv_nh.hasParam("debug/stats_period"))
|
||||
priv_nh.getParam("debug/stats_period", debug_stats_period_, debug_stats_period_);
|
||||
if (priv_nh.hasParam("occlusion_guard"))
|
||||
priv_nh.getParam("occlusion_guard", occlusion_guard_, occlusion_guard_);
|
||||
|
||||
const bool track_unknown_space = p.get("track_unknown_space", layered_costmap_->isTrackingUnknown());
|
||||
default_value_ = track_unknown_space ? NO_INFORMATION : FREE_SPACE;
|
||||
|
||||
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"))
|
||||
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 "
|
||||
"cell now always resets its master cell\n", name_.c_str());
|
||||
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.
|
||||
@@ -295,26 +424,61 @@ void DepthCameraObstacleLayer::loadParameters()
|
||||
marking_height_under_ground_ = 100.0;
|
||||
marking_height_above_ground_ = -100.0;
|
||||
|
||||
std::stringstream ss(p.get("observation_sources", std::string("")));
|
||||
std::stringstream ss(topics_string);
|
||||
std::string name;
|
||||
while (ss >> name)
|
||||
{
|
||||
const ParamReader s = p.child(name);
|
||||
std::unique_ptr<Source> src(new Source());
|
||||
src->name = name;
|
||||
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))
|
||||
|
||||
// ===== 1. Defaults. Like obstacle_layer_params.yaml, the file has no block per source, so
|
||||
// these are the C++ defaults unless the file gains one =====
|
||||
src->topic = loadParam(layer[name], "topic", name);
|
||||
src->sensor_frame = loadParam(layer[name], "sensor_frame", std::string(""));
|
||||
src->sensor_frame_is_optical = loadParam(layer[name], "sensor_frame_is_optical", false);
|
||||
src->observation_keep_time = loadParam(layer[name], "observation_persistence", 0.0);
|
||||
src->expected_update_rate = loadParam(layer[name], "expected_update_rate", 0.0);
|
||||
src->min_obstacle_height = loadParam(layer[name], "min_obstacle_height", 0.0);
|
||||
src->max_obstacle_height = loadParam(layer[name], "max_obstacle_height", 2.0);
|
||||
src->marking = loadParam(layer[name], "marking", true);
|
||||
src->fov_v = loadParam(layer[name], "FOV_V", 1.0);
|
||||
src->fov_w = loadParam(layer[name], "FOV_W", 1.5);
|
||||
src->min_detect_distance = loadParam(layer[name], "min_detect_distance", 0.15);
|
||||
src->max_detect_distance = loadParam(layer[name], "max_detect_distance", 2.5);
|
||||
src->attach_distance = loadParam(layer[name], "attach_distance", 0.12);
|
||||
bool inf_is_valid = loadParam(layer[name], "inf_is_valid", false);
|
||||
|
||||
// ===== 2. Override from "<costmap>/<plugin>/<source>" =====
|
||||
robot::NodeHandle source_nh(priv_nh, name);
|
||||
if (source_nh.hasParam("topic"))
|
||||
source_nh.getParam("topic", src->topic, src->topic);
|
||||
if (source_nh.hasParam("sensor_frame"))
|
||||
source_nh.getParam("sensor_frame", src->sensor_frame, src->sensor_frame);
|
||||
if (source_nh.hasParam("sensor_frame_is_optical"))
|
||||
source_nh.getParam("sensor_frame_is_optical", src->sensor_frame_is_optical, src->sensor_frame_is_optical);
|
||||
if (source_nh.hasParam("observation_persistence"))
|
||||
source_nh.getParam("observation_persistence", src->observation_keep_time, src->observation_keep_time);
|
||||
if (source_nh.hasParam("expected_update_rate"))
|
||||
source_nh.getParam("expected_update_rate", src->expected_update_rate, src->expected_update_rate);
|
||||
if (source_nh.hasParam("min_obstacle_height"))
|
||||
source_nh.getParam("min_obstacle_height", src->min_obstacle_height, src->min_obstacle_height);
|
||||
if (source_nh.hasParam("max_obstacle_height"))
|
||||
source_nh.getParam("max_obstacle_height", src->max_obstacle_height, src->max_obstacle_height);
|
||||
if (source_nh.hasParam("marking"))
|
||||
source_nh.getParam("marking", src->marking, src->marking);
|
||||
if (source_nh.hasParam("FOV_V"))
|
||||
source_nh.getParam("FOV_V", src->fov_v, src->fov_v);
|
||||
if (source_nh.hasParam("FOV_W"))
|
||||
source_nh.getParam("FOV_W", src->fov_w, src->fov_w);
|
||||
if (source_nh.hasParam("min_detect_distance"))
|
||||
source_nh.getParam("min_detect_distance", src->min_detect_distance, src->min_detect_distance);
|
||||
if (source_nh.hasParam("max_detect_distance"))
|
||||
source_nh.getParam("max_detect_distance", src->max_detect_distance, src->max_detect_distance);
|
||||
if (source_nh.hasParam("attach_distance"))
|
||||
source_nh.getParam("attach_distance", src->attach_distance, src->attach_distance);
|
||||
if (source_nh.hasParam("inf_is_valid"))
|
||||
source_nh.getParam("inf_is_valid", inf_is_valid, inf_is_valid);
|
||||
if (inf_is_valid)
|
||||
robot::log_warning("DepthCameraObstacleLayer: inf_is_valid is not applicable to PointCloud observations\n");
|
||||
|
||||
const std::string what = "source " + name + ": ";
|
||||
@@ -322,6 +486,10 @@ void DepthCameraObstacleLayer::loadParameters()
|
||||
requireRange(src->fov_v > 0.0 && src->fov_v < M_PI, what + "FOV_V must be in (0, pi) [rad]");
|
||||
requireRange(src->min_detect_distance >= 0.0 && src->max_detect_distance > src->min_detect_distance,
|
||||
what + "need 0 <= min_detect_distance < max_detect_distance [m]");
|
||||
// At half the frustum depth the near and far bands meet and nothing along the axis is marked.
|
||||
requireRange(src->attach_distance >= 0.0 &&
|
||||
src->attach_distance < (src->max_detect_distance - src->min_detect_distance) / 2.0,
|
||||
what + "attach_distance must be in [0, (max_detect_distance - min_detect_distance) / 2) [m]");
|
||||
requireRange(src->min_obstacle_height <= src->max_obstacle_height,
|
||||
what + "min_obstacle_height must be <= max_obstacle_height [m]");
|
||||
requireRange(src->observation_keep_time >= 0.0 && src->expected_update_rate >= 0.0,
|
||||
@@ -333,14 +501,14 @@ void DepthCameraObstacleLayer::loadParameters()
|
||||
src->last_updated = robot::Time::now();
|
||||
|
||||
robot::log_info("DepthCameraObstacleLayer %s: source %s topic=%s sensor_frame=%s optical=%s "
|
||||
"FOV_W=%.3f FOV_V=%.3f rad detect=[%.2f, %.2f] m height=[%.2f, %.2f] m "
|
||||
"FOV_W=%.3f FOV_V=%.3f rad detect=[%.2f, %.2f] m height=[%.2f, %.2f] m attach=%.3f m "
|
||||
"persistence=%.2f s expected_update_rate=%.2f s marking=%s\n",
|
||||
name_.c_str(), name.c_str(), src->topic.c_str(),
|
||||
src->sensor_frame.empty() ? "(cloud frame)" : src->sensor_frame.c_str(),
|
||||
src->sensor_frame_is_optical ? "true" : "false", src->fov_w, src->fov_v,
|
||||
src->min_detect_distance, src->max_detect_distance, src->min_obstacle_height,
|
||||
src->max_obstacle_height, src->observation_keep_time, src->expected_update_rate,
|
||||
src->marking ? "true" : "false");
|
||||
src->max_obstacle_height, src->attach_distance, src->observation_keep_time,
|
||||
src->expected_update_rate, src->marking ? "true" : "false");
|
||||
sources_.push_back(std::move(src));
|
||||
}
|
||||
if (sources_.empty())
|
||||
@@ -352,7 +520,7 @@ void DepthCameraObstacleLayer::loadParameters()
|
||||
"ec_seg_distance=%.2f m ec_cluster_min_size=%d size_of_cluster_rejection=%d "
|
||||
"forced_clearing_distance=%.2f m near_blocked_protection=%s (%d pts) "
|
||||
"voxelized_observation=%s transform_tolerance=%.2f s combination_method=%d "
|
||||
"footprint_clearing=%s marking_height=[%.2f, %.2f] m debug/stats=%s\n",
|
||||
"footprint_clearing=%s marking_height=[%.2f, %.2f] m occlusion_guard=%s debug/stats=%s\n",
|
||||
name_.c_str(), global_frame_.c_str(), rolling_window_ ? "true" : "false",
|
||||
track_unknown_space ? "true" : "false", voxel_resolution_, check_radius_,
|
||||
number_clearing_threshold_, ec_seg_distance_, ec_cluster_min_size_,
|
||||
@@ -360,7 +528,8 @@ void DepthCameraObstacleLayer::loadParameters()
|
||||
enable_near_blocked_protection_ ? "true" : "false", number_points_considered_as_blocked_,
|
||||
use_voxelized_observation_ ? "true" : "false", transform_tolerance_, combination_method_,
|
||||
footprint_clearing_enabled_ ? "true" : "false",
|
||||
marking_height_under_ground_, marking_height_above_ground_, debug_stats_ ? "on" : "off");
|
||||
marking_height_under_ground_, marking_height_above_ground_,
|
||||
occlusion_guard_ ? "true" : "false", debug_stats_ ? "on" : "off");
|
||||
}
|
||||
|
||||
void DepthCameraObstacleLayer::handleImpl(const void* data, const std::type_info& type,
|
||||
@@ -447,7 +616,14 @@ bool DepthCameraObstacleLayer::bufferCloud(Source& source, const robot_sensor_ms
|
||||
obs.stamp = cloud.header.stamp;
|
||||
// Frustum vertices are given in the sensor frame, then everything is in the global frame.
|
||||
obs.frustum.build(T_origin, source.fov_w, source.fov_v, source.min_detect_distance,
|
||||
source.max_detect_distance, source.sensor_frame_is_optical);
|
||||
source.max_detect_distance, source.sensor_frame_is_optical, source.attach_distance);
|
||||
// Occlusion guard: nearest return per ray from every point, before the height gate below.
|
||||
Eigen::Isometry3f T_sensor_cloud = Eigen::Isometry3f::Identity();
|
||||
if (occlusion_guard_)
|
||||
{
|
||||
obs.range.reset(T_origin, source.fov_w, source.fov_v, source.sensor_frame_is_optical);
|
||||
T_sensor_cloud = (T_origin.inverse() * T_cloud).cast<float>();
|
||||
}
|
||||
|
||||
const std::size_t size = static_cast<std::size_t>(cloud.width) * cloud.height;
|
||||
obs.points.reserve(size);
|
||||
@@ -459,6 +635,8 @@ bool DepthCameraObstacleLayer::bufferCloud(Source& source, const robot_sensor_ms
|
||||
// The source relies on dense clouds; NaN would only disappear later in PCL. Drop it here.
|
||||
if (!std::isfinite(*iter_x) || !std::isfinite(*iter_y) || !std::isfinite(*iter_z))
|
||||
continue;
|
||||
if (occlusion_guard_)
|
||||
obs.range.addSensorPoint(T_sensor_cloud * Eigen::Vector3f(*iter_x, *iter_y, *iter_z));
|
||||
const Eigen::Vector3d g = T_cloud * Eigen::Vector3d(*iter_x, *iter_y, *iter_z);
|
||||
if (g.z() <= source.max_obstacle_height && g.z() >= source.min_obstacle_height)
|
||||
obs.points.push_back(g.cast<float>());
|
||||
@@ -518,6 +696,8 @@ void DepthCameraObstacleLayer::updateBounds(double robot_x, double robot_y, doub
|
||||
|
||||
bool current = true;
|
||||
std::vector<DepthCameraFrustum> frustums;
|
||||
// Points into source->observations, which nothing changes until the end of this cycle.
|
||||
std::vector<const DepthCameraRangeImage*> range_images;
|
||||
std::vector<Eigen::Vector3f> combined;
|
||||
for (const auto& source : sources_)
|
||||
{
|
||||
@@ -528,6 +708,7 @@ void DepthCameraObstacleLayer::updateBounds(double robot_x, double robot_y, doub
|
||||
for (const Observation& obs : source->observations)
|
||||
{
|
||||
frustums.push_back(obs.frustum);
|
||||
range_images.push_back(obs.range.empty() ? nullptr : &obs.range);
|
||||
combined.insert(combined.end(), obs.points.begin(), obs.points.end());
|
||||
}
|
||||
current = sourceIsCurrent(*source) && current;
|
||||
@@ -565,7 +746,7 @@ void DepthCameraObstacleLayer::updateBounds(double robot_x, double robot_y, doub
|
||||
points.emplace_back(pt.x, pt.y, pt.z);
|
||||
stats_.cloud_points += points.size();
|
||||
|
||||
clearMarkingByKdtree(points, frustums, robot_x, robot_y, min_x, min_y, max_x, max_y);
|
||||
clearMarkingByKdtree(points, frustums, range_images, robot_x, robot_y, min_x, min_y, max_x, max_y);
|
||||
|
||||
if (cloud->points.size() > 5)
|
||||
{
|
||||
@@ -602,6 +783,7 @@ void DepthCameraObstacleLayer::updateBounds(double robot_x, double robot_y, doub
|
||||
|
||||
void DepthCameraObstacleLayer::clearMarkingByKdtree(const std::vector<Eigen::Vector3f>& cloud,
|
||||
const std::vector<DepthCameraFrustum>& frustums,
|
||||
const std::vector<const DepthCameraRangeImage*>& range_images,
|
||||
double robot_x, double robot_y, double* min_x,
|
||||
double* min_y, double* max_x, double* max_y)
|
||||
{
|
||||
@@ -679,6 +861,34 @@ void DepthCameraObstacleLayer::clearMarkingByKdtree(const std::vector<Eigen::Vec
|
||||
q.z = search.z();
|
||||
erase = kdtree.radiusSearch(q, check_radius_, indices, sq_distances) < number_clearing_threshold_;
|
||||
}
|
||||
// The kd-tree test cannot tell "gone" from "hidden by something nearer": a person walking in
|
||||
// front of a box cleared the box. With the guard, the depth rays decide where they can.
|
||||
if (occlusion_guard_ && !bypass_clearing)
|
||||
{
|
||||
// The middle of the cell, not its corner: indices are truncated toward zero, so the corner
|
||||
// can lie outside a small object and its ray would see the floor behind it.
|
||||
const Eigen::Vector3f centre(static_cast<float>(wx + std::copysign(0.5 * resolution, wx)),
|
||||
static_cast<float>(wy + std::copysign(0.5 * resolution, wy)), search.z());
|
||||
bool occluded = false, seen_through = false;
|
||||
for (std::size_t i = 0; i < frustums.size() && i < range_images.size(); ++i)
|
||||
{
|
||||
if (range_images[i] == nullptr || !frustums[i].inside(search))
|
||||
continue;
|
||||
const DepthCameraRangeImage::Evidence evidence = range_images[i]->test(centre);
|
||||
occluded = occluded || evidence == DepthCameraRangeImage::Evidence::kOccluded;
|
||||
seen_through = seen_through || evidence == DepthCameraRangeImage::Evidence::kSeenThrough;
|
||||
}
|
||||
if (erase && occluded)
|
||||
{
|
||||
erase = false;
|
||||
++stats_.kept_occluded;
|
||||
}
|
||||
else if (!erase && seen_through && !occluded)
|
||||
{
|
||||
erase = true;
|
||||
++stats_.cleared_seen_through;
|
||||
}
|
||||
}
|
||||
if (!erase)
|
||||
continue;
|
||||
heights.erase(it);
|
||||
@@ -871,11 +1081,13 @@ void DepthCameraObstacleLayer::logStats()
|
||||
if (debug_stats_ && stats_.cycles > 0)
|
||||
robot::log_info("[debug/stats] DepthCameraObstacleLayer %s: cycles=%zu cloud_pts/cycle=%.0f stored=%zu "
|
||||
"columns=%zu marked=%zu cleared=%zu footprint_cleared=%zu clear_all_cycles=%zu bypass_cycles=%zu "
|
||||
"tf_wait=%zu tf_drop=%zu out_of_window=%zu bounds_ms avg=%.1f max=%.1f\n",
|
||||
"tf_wait=%zu tf_drop=%zu out_of_window=%zu kept_occluded=%zu cleared_seen_through=%zu "
|
||||
"bounds_ms avg=%.1f max=%.1f\n",
|
||||
name_.c_str(), stats_.cycles, static_cast<double>(stats_.cloud_points) / stats_.cycles,
|
||||
storedPoints(), pc_3d_map_global_.size(), stats_.marked, stats_.cleared, stats_.footprint_cleared,
|
||||
stats_.cleared_all_frames, stats_.bypassed_frames, stats_.tf_waits, stats_.tf_drops,
|
||||
stats_.dropped_out_of_window, stats_.bounds_ms_sum / stats_.cycles, stats_.bounds_ms_max);
|
||||
stats_.dropped_out_of_window, stats_.kept_occluded, stats_.cleared_seen_through,
|
||||
stats_.bounds_ms_sum / stats_.cycles, stats_.bounds_ms_max);
|
||||
stats_ = Stats();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <robot_costmap_2d/footprint.h>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/dll/alias.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
using robot_costmap_2d::LETHAL_OBSTACLE;
|
||||
@@ -80,7 +81,8 @@ void InflationLayer::onInitialize()
|
||||
need_reinflation_ = false;
|
||||
std::string config_file_name = "inflation_layer_params.yaml";
|
||||
// std::cout << "InflationLayer: " << config_file_name << std::endl;
|
||||
getParams(config_file_name, priv_nh);
|
||||
if (!getParams(config_file_name, priv_nh))
|
||||
throw std::runtime_error("InflationLayer " + name_ + ": cannot open the default file " + config_file_name);
|
||||
|
||||
matchSize();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <tf3/exceptions.h>
|
||||
#include <boost/dll/alias.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
using robot_costmap_2d::NO_INFORMATION;
|
||||
@@ -66,7 +67,8 @@ void ObstacleLayer::onInitialize()
|
||||
stop_receiving_data_ = false;
|
||||
global_frame_ = layered_costmap_->getGlobalFrameID();
|
||||
std::string config_file_name = "obstacle_layer_params.yaml";
|
||||
getParams(config_file_name, priv_nh);
|
||||
if (!getParams(config_file_name, priv_nh))
|
||||
throw std::runtime_error("ObstacleLayer " + name_ + ": cannot open the default file " + config_file_name);
|
||||
}
|
||||
|
||||
ObstacleLayer::~ObstacleLayer()
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <robot_tf3_geometry_msgs/tf3_geometry_msgs.h>
|
||||
|
||||
#include <boost/dll/alias.hpp>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
#include <cxxabi.h>
|
||||
|
||||
@@ -71,7 +72,8 @@ void StaticLayer::onInitialize()
|
||||
|
||||
global_frame_ = layered_costmap_->getGlobalFrameID();
|
||||
std::string config_file_name = "static_layer_params.yaml";
|
||||
getParams(config_file_name, priv_nh);
|
||||
if (!getParams(config_file_name, priv_nh))
|
||||
throw std::runtime_error("StaticLayer " + name_ + ": cannot open the default file " + config_file_name);
|
||||
robot::log_warning("Initializing static layer with map topic \"%s\" in frame \"%s\"", map_topic_.c_str(), global_frame_.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -48,6 +48,9 @@
|
||||
#include <tf3/convert.h>
|
||||
#include <tf3/utils.h>
|
||||
#include <exception>
|
||||
#include <initializer_list>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/dll/import.hpp>
|
||||
|
||||
@@ -63,10 +66,26 @@ void move_parameter(robot::NodeHandle& old_h, robot::NodeHandle& new_h, std::str
|
||||
if (!old_h.hasParam(name))
|
||||
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);
|
||||
}
|
||||
|
||||
// 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),
|
||||
@@ -109,6 +128,17 @@ 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 =
|
||||
@@ -224,44 +254,22 @@ 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())
|
||||
{
|
||||
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)
|
||||
{
|
||||
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");
|
||||
|
||||
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);
|
||||
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
|
||||
@@ -293,10 +301,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 (std::exception &ex)
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
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;
|
||||
// Covers a missing library or symbol as well as a layer rejecting its parameters.
|
||||
fail("layer '" + info.name + "' (" + info.type + "): " + ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,8 +361,11 @@ void Costmap2DROBOT::getParams(const std::string& config_file_name,const std::st
|
||||
}
|
||||
catch (const YAML::BadFile& e)
|
||||
{
|
||||
std::cerr << "Cannot open YAML file: " << e.what() << std::endl;
|
||||
return;
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,132 +374,81 @@ 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);
|
||||
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"))
|
||||
{
|
||||
|
||||
// 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);
|
||||
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_source_keys(plugin_nh_element, costmap_plugin_nh_element);
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
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"))
|
||||
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")
|
||||
{
|
||||
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)
|
||||
// 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")
|
||||
{
|
||||
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_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_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;
|
||||
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);
|
||||
move_parameters<double>(plugin_nh, costmap_plugin_nh, {"cost_scaling_factor", "inflation_radius"});
|
||||
move_parameters<bool>(plugin_nh, costmap_plugin_nh, {"enabled", "inflate_unknown"});
|
||||
}
|
||||
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", "occlusion_guard"});
|
||||
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", "attach_distance"});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Costmap2DROBOT::setUnpaddedRobotFootprintPolygon(const robot_geometry_msgs::Polygon& footprint)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -84,6 +99,33 @@ std::vector<Eigen::Vector3d> join(std::vector<Eigen::Vector3d> a, const std::vec
|
||||
return a;
|
||||
}
|
||||
|
||||
// Dense vertical sheet at x (odom): with step / x <= 0.01 every ray bin it covers gets a return,
|
||||
// unlike object(), whose 6 cm gaps let the rays through.
|
||||
std::vector<Eigen::Vector3d> sheet(double x, double y0, double y1, double z0, double z1, double step = .01)
|
||||
{
|
||||
std::vector<Eigen::Vector3d> pts;
|
||||
for (double y = y0; y <= y1 + 1e-9; y += step)
|
||||
for (double z = z0; z <= z1 + 1e-9; z += step)
|
||||
pts.emplace_back(x, y, z);
|
||||
return pts;
|
||||
}
|
||||
|
||||
// Far backdrop 2 m ahead, behind everything the guard tests store.
|
||||
std::vector<Eigen::Vector3d> backdrop()
|
||||
{
|
||||
return sheet(2.0, -.10, .60, .05, .60, .015);
|
||||
}
|
||||
|
||||
// 21 x 21 returns 5 mm apart, centred on (x, y0, z0) of a camera_link frame (X forward).
|
||||
std::vector<Eigen::Vector3f> patch(float x, float y0, float z0)
|
||||
{
|
||||
std::vector<Eigen::Vector3f> pts;
|
||||
for (int i = -10; i <= 10; ++i)
|
||||
for (int j = -10; j <= 10; ++j)
|
||||
pts.emplace_back(x, y0 + i * .005f, z0 + j * .005f);
|
||||
return pts;
|
||||
}
|
||||
|
||||
YAML::Node baseConfig()
|
||||
{
|
||||
YAML::Node cfg;
|
||||
@@ -137,6 +179,18 @@ TEST(DepthCameraFrustum, AttachBandIsTwelveCentimetresFromEveryFace)
|
||||
EXPECT_FALSE(f.nearFace(Eigen::Vector3f(1, half_w - .3f, 0)));
|
||||
}
|
||||
|
||||
TEST(DepthCameraFrustum, AttachDistanceFollowsTheParameter)
|
||||
{
|
||||
DepthCameraFrustum f;
|
||||
f.build(Eigen::Isometry3d::Identity(), kFovW, kFovV, .15, 2.5, false, .08);
|
||||
EXPECT_FALSE(f.nearFace(Eigen::Vector3f(.25f, 0, 0))); // 10 cm past the near plane
|
||||
EXPECT_TRUE(f.nearFace(Eigen::Vector3f(.20f, 0, 0))); // 5 cm past it
|
||||
const float half_w = std::tan(kFovW / 2);
|
||||
// 5 cm / 15 cm inside the left face along y: ~4 cm / ~12 cm from its plane.
|
||||
EXPECT_TRUE(f.nearFace(Eigen::Vector3f(1, half_w - .05f, 0)));
|
||||
EXPECT_FALSE(f.nearFace(Eigen::Vector3f(1, half_w - .15f, 0)));
|
||||
}
|
||||
|
||||
TEST(DepthCameraFrustum, OpticalFrameGivesTheSamePyramid)
|
||||
{
|
||||
DepthCameraFrustum link, optical;
|
||||
@@ -162,6 +216,49 @@ TEST(DepthCameraFrustum, AttachedUnlessWellInsideAnotherFrustum)
|
||||
EXPECT_FALSE(attachedToFrustums({a}, Eigen::Vector3f(1, 0, 0)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Range image (occlusion guard)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
TEST(DepthCameraRangeImage, NearerReturnsHideAndFartherReturnsShowThrough)
|
||||
{
|
||||
using Evidence = DepthCameraRangeImage::Evidence;
|
||||
DepthCameraRangeImage image;
|
||||
EXPECT_EQ(image.test(Eigen::Vector3f(1, 0, 0)), Evidence::kNone); // never built
|
||||
image.reset(Eigen::Isometry3d::Identity(), kFovW, kFovV, false); // X forward
|
||||
for (const Eigen::Vector3f& p : patch(1, 0, 0))
|
||||
image.addSensorPoint(p);
|
||||
EXPECT_EQ(image.test(Eigen::Vector3f(2, 0, 0)), Evidence::kOccluded); // behind the patch
|
||||
EXPECT_EQ(image.test(Eigen::Vector3f(.5f, 0, 0)), Evidence::kSeenThrough); // in front of it
|
||||
EXPECT_EQ(image.test(Eigen::Vector3f(1, 0, 0)), Evidence::kNone); // on it
|
||||
EXPECT_EQ(image.test(Eigen::Vector3f(1, .5f, 0)), Evidence::kNone); // no return on that ray
|
||||
EXPECT_EQ(image.test(Eigen::Vector3f(.05f, 0, 0)), Evidence::kNone); // too close to judge
|
||||
}
|
||||
|
||||
TEST(DepthCameraRangeImage, OpticalFrameGivesTheSameEvidence)
|
||||
{
|
||||
using Evidence = DepthCameraRangeImage::Evidence;
|
||||
Eigen::Isometry3d T = Eigen::Isometry3d::Identity();
|
||||
T.linear() << 0, 0, 1, -1, 0, 0, 0, -1, 0; // optical axes expressed in camera_link
|
||||
DepthCameraRangeImage link, optical;
|
||||
link.reset(Eigen::Isometry3d::Identity(), kFovW, kFovV, false);
|
||||
optical.reset(T, kFovW, kFovV, true);
|
||||
const Eigen::Isometry3f optical_from_link = T.inverse().cast<float>();
|
||||
// Off-centre patch (left and up), so a mirrored axis would answer for the wrong ray.
|
||||
for (const Eigen::Vector3f& p : patch(1, .3f, .1f))
|
||||
{
|
||||
link.addSensorPoint(p);
|
||||
optical.addSensorPoint(optical_from_link * p);
|
||||
}
|
||||
const Eigen::Vector3f behind(2, .6f, .2f), mirrored(2, -.6f, -.2f), in_front(.5f, .15f, .05f);
|
||||
EXPECT_EQ(link.test(behind), Evidence::kOccluded);
|
||||
EXPECT_EQ(link.test(mirrored), Evidence::kNone);
|
||||
EXPECT_EQ(link.test(in_front), Evidence::kSeenThrough);
|
||||
EXPECT_EQ(optical.test(behind), Evidence::kOccluded);
|
||||
EXPECT_EQ(optical.test(mirrored), Evidence::kNone);
|
||||
EXPECT_EQ(optical.test(in_front), Evidence::kSeenThrough);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Layer
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@@ -295,6 +392,122 @@ TEST_F(DepthCameraLayerTest, AttachBandIsNotMarked)
|
||||
EXPECT_EQ(layer.storedPoints(), wall_points);
|
||||
}
|
||||
|
||||
class DepthCameraAttachTest : public DepthCameraLayerTest
|
||||
{
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override
|
||||
{
|
||||
cfg["depth_cam"]["attach_distance"] = .08;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DepthCameraAttachTest, NarrowerAttachBandMarksCloserToTheFaces)
|
||||
{
|
||||
// The scene of AttachBandIsNotMarked: 10 cm past the near plane is outside an 8 cm band.
|
||||
frame(wall());
|
||||
const std::size_t wall_points = layer.storedPoints();
|
||||
ASSERT_GT(wall_points, 0u);
|
||||
frame(join(object(.25, .10, .19), wall()));
|
||||
EXPECT_GT(layer.storedPoints(), wall_points);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Occlusion guard
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
class DepthCameraGuardTest : public DepthCameraLayerTest
|
||||
{
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override
|
||||
{
|
||||
cfg["number_clearing_threshold"] = 1; // as on the KIT robot
|
||||
cfg["occlusion_guard"] = guard();
|
||||
}
|
||||
virtual bool guard() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class DepthCameraNoGuardTest : public DepthCameraGuardTest
|
||||
{
|
||||
protected:
|
||||
bool guard() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// A box 1.42 m ahead, then a screen 1 m ahead that hides it (a person walking past it).
|
||||
std::vector<Eigen::Vector3d> hiddenBox()
|
||||
{
|
||||
return object(1.42, .13, .30);
|
||||
}
|
||||
std::vector<Eigen::Vector3d> screen()
|
||||
{
|
||||
return sheet(1.0, -.02, .22, .16, .36);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraNoGuardTest, HiddenBoxIsClearedWithoutTheGuard)
|
||||
{
|
||||
frame(hiddenBox());
|
||||
ASSERT_EQ(master(1.41, .11), LETHAL_OBSTACLE);
|
||||
frame(screen()); // no cloud point near the box: the kd-tree test clears it
|
||||
EXPECT_NE(master(1.41, .11), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraGuardTest, HiddenBoxIsKeptWithTheGuard)
|
||||
{
|
||||
frame(hiddenBox());
|
||||
ASSERT_EQ(master(1.41, .11), LETHAL_OBSTACLE);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
frame(screen());
|
||||
EXPECT_EQ(master(1.41, .11), LETHAL_OBSTACLE);
|
||||
frame(backdrop()); // the screen is gone and the camera sees past the box: now it goes
|
||||
EXPECT_NE(master(1.41, .11), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
// A box in front of the backdrop moves 18 cm to the left. Its old column y = .22 (corner .20)
|
||||
// still has a point of the moved box (y = .28) within check_radius, so only the rays show that
|
||||
// the column is empty. Checked at (1.01, .21): stored corners sit on cell edges, and corner .20
|
||||
// is the only one that lands in that master cell (corner .15 falls back into the .10 cell).
|
||||
std::vector<Eigen::Vector3d> boxBefore()
|
||||
{
|
||||
return object(1.02, .16, .30);
|
||||
}
|
||||
std::vector<Eigen::Vector3d> boxAfter()
|
||||
{
|
||||
return object(1.02, .34, .30);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraNoGuardTest, MovedBoxLeavesAGhostWithoutTheGuard)
|
||||
{
|
||||
frame(join(boxBefore(), backdrop()));
|
||||
ASSERT_EQ(master(1.01, .21), LETHAL_OBSTACLE);
|
||||
frame(join(boxAfter(), backdrop()));
|
||||
EXPECT_EQ(master(1.01, .21), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraGuardTest, MovedBoxLeavesNoGhostWithTheGuard)
|
||||
{
|
||||
frame(join(boxBefore(), backdrop()));
|
||||
ASSERT_EQ(master(1.01, .21), LETHAL_OBSTACLE);
|
||||
frame(join(boxAfter(), backdrop()));
|
||||
EXPECT_NE(master(1.01, .21), LETHAL_OBSTACLE);
|
||||
EXPECT_EQ(master(1.01, .26), LETHAL_OBSTACLE); // the moved box itself (its y = .28 column)
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraGuardTest, SolidBoxSeenAgainIsKept)
|
||||
{
|
||||
// A real surface returns on every ray at its own range: no evidence, the kd-tree test keeps it.
|
||||
const std::vector<Eigen::Vector3d> box = sheet(1.02, .05, .20, .22, .38);
|
||||
frame(join(box, backdrop()));
|
||||
ASSERT_EQ(master(), LETHAL_OBSTACLE);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
frame(join(box, backdrop()));
|
||||
EXPECT_EQ(master(), LETHAL_OBSTACLE);
|
||||
}
|
||||
|
||||
TEST_F(DepthCameraLayerTest, WaitsForTheMeasurementTfThenDropsAfterTheTolerance)
|
||||
{
|
||||
frame(object(), 0, false); // no TF at this stamp yet
|
||||
@@ -444,4 +657,27 @@ TEST(DepthCameraLayerConfig, RejectsUnportedModeAndOutOfRangeValues)
|
||||
cfg = baseConfig();
|
||||
cfg["voxel_resolution"] = 0.0;
|
||||
expectThrow(cfg);
|
||||
cfg = baseConfig();
|
||||
cfg["depth_cam"]["attach_distance"] = -.01;
|
||||
expectThrow(cfg);
|
||||
cfg = baseConfig();
|
||||
cfg["depth_cam"]["attach_distance"] = 1.2; // near and far bands would meet: (2.5 - .15) / 2
|
||||
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