refactor(depth): keep DepthCameraObstacleLayer, drop the legacy depth clearing
Two depth-image clearing designs lived in this package: the frustum ray
clearing inherited from dev_cam_intel (DepthCameraData sources of
ObstacleLayer/VoxelLayer, frustum_* and column_* keys) and the observed_volume
evidence clearing (ROC) on top of it. Both are replaced on the robot by
DepthCameraObstacleLayer, a port of costmap_depth_camera that takes the
filtered PointCloud2 directly, so both are removed and the tree is rebuilt
from main (a63c084) plus the plugin.
- observation.h / observation_buffer: DepthFrustumConfig, DepthCameraObservation
and the depth buffering API are gone; buffers hold point clouds only.
- ObstacleLayer/VoxelLayer: no frustum ray casting, column clearing or depth
ray cache. A DepthCameraData source or frustum_clearing_enabled: true now
fails at startup with a message pointing to DepthCameraObstacleLayer
instead of silently dropping the camera; DepthCameraData reaching the layer
through the gateway is ignored.
- copyParentParameters no longer forwards the frustum_* / column_* keys.
- ROC files (depth_evidence_store, depth_visibility, depth_frame_pairer) and
their tests are not carried over; CloudProcessingConfig goes with them.
- PCL is needed by the plugin library only. The plugin test moves under
BUILD_COSTMAP_TESTS; BUILD_DEPTH_MARKING_TESTS is gone.
- README documents DepthCameraObstacleLayer and its known limits.
The plugin code is unchanged from the version running on the KIT robot.
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
#ifndef ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_
|
||||
#define ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Measured points that marked each voxel of a depth-only VoxelLayer.
|
||||
*
|
||||
* The observed_volume clearing certifies these points instead of the whole voxel box:
|
||||
* the occupancy of a depth-only layer is exactly what the camera saw, so the part of a
|
||||
* voxel the camera never saw carries no occupancy of its own. Keys use a
|
||||
* window-independent cell index, so a rolling origin shift needs no copy; callers drop
|
||||
* keys that left the window with eraseIf().
|
||||
*
|
||||
* Per voxel it keeps the 6 per-axis extreme points (min/max x, y, z) and fills the
|
||||
* remaining slots with the most recent points.
|
||||
*/
|
||||
class DepthEvidenceStore
|
||||
{
|
||||
public:
|
||||
static constexpr unsigned int kExtremeSlots = 6;
|
||||
static constexpr unsigned int kMaxPoints = 16;
|
||||
|
||||
struct VoxelKey
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
unsigned int z;
|
||||
bool operator==(const VoxelKey& other) const
|
||||
{
|
||||
return x == other.x && y == other.y && z == other.z;
|
||||
}
|
||||
};
|
||||
|
||||
explicit DepthEvidenceStore(unsigned int points_per_voxel = 8);
|
||||
|
||||
/// Clamped to [kExtremeSlots, kMaxPoints]; drops all stored evidence.
|
||||
void setPointsPerVoxel(unsigned int points_per_voxel);
|
||||
unsigned int pointsPerVoxel() const { return points_per_voxel_; }
|
||||
|
||||
/// Records a marking point [global frame, m]. fresh = true drops points left over from
|
||||
/// an earlier occupancy of the voxel (it was not MARKED before this point). A marking
|
||||
/// point also restarts the voxel's re-observe miss count.
|
||||
void add(const VoxelKey& key, const Eigen::Vector3f& point, bool fresh);
|
||||
/// Re-observe-or-clear: adds weight to the voxel's miss count and returns the new count;
|
||||
/// 0 when the voxel has no evidence.
|
||||
float addMiss(const VoxelKey& key, float weight);
|
||||
void resetMiss(const VoxelKey& key);
|
||||
|
||||
/// Distinct evidence points of one voxel. Returns false when the voxel has none.
|
||||
bool points(const VoxelKey& key, std::vector<Eigen::Vector3d>& out) const;
|
||||
|
||||
void erase(const VoxelKey& key);
|
||||
void eraseIf(const std::function<bool(const VoxelKey&)>& predicate);
|
||||
void clear();
|
||||
std::size_t size() const { return entries_.size(); }
|
||||
|
||||
private:
|
||||
struct KeyHash
|
||||
{
|
||||
std::size_t operator()(const VoxelKey& key) const noexcept
|
||||
{
|
||||
return (static_cast<std::size_t>(static_cast<uint32_t>(key.x)) * 73856093u) ^
|
||||
(static_cast<std::size_t>(static_cast<uint32_t>(key.y)) * 19349663u) ^
|
||||
(static_cast<std::size_t>(key.z) * 83492791u);
|
||||
}
|
||||
};
|
||||
|
||||
struct Entry
|
||||
{
|
||||
std::array<Eigen::Vector3f, kMaxPoints> points;
|
||||
unsigned char count = 0; ///< valid slots, extremes included
|
||||
unsigned char next_recent = 0; ///< ring position among the recent slots
|
||||
float miss = 0.f; ///< re-observe misses since last marked or confirmed
|
||||
};
|
||||
|
||||
unsigned int points_per_voxel_;
|
||||
std::unordered_map<VoxelKey, Entry, KeyHash> entries_;
|
||||
};
|
||||
|
||||
} // namespace robot_costmap_2d
|
||||
|
||||
#endif // ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_
|
||||
@@ -1,166 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <robot_costmap_2d/observation.h>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
// A source pair owns immutable measurement messages; the update thread alone
|
||||
// acknowledges applied frames. Queue timeout/freshness never expires occupancy.
|
||||
class DepthFramePairer
|
||||
{
|
||||
public:
|
||||
using Clock = std::chrono::steady_clock;
|
||||
struct Candidate
|
||||
{
|
||||
uint64_t stamp{0};
|
||||
robot_sensor_msgs::PointCloud2::ConstPtr cloud;
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr depth;
|
||||
};
|
||||
struct Counts
|
||||
{
|
||||
uint64_t applied{0}, expired{0}, overflow{0}, stale{0}, duplicate{0}, invalid{0}, tf_wait{0};
|
||||
};
|
||||
|
||||
explicit DepthFramePairer(const DepthFrustumConfig& config, double expected_period)
|
||||
: config_(config), expected_period_(expected_period), started_(robot::Time::now()), last_clock_(started_)
|
||||
{
|
||||
if (!std::isfinite(expected_period_) || expected_period_ < 0 ||
|
||||
!config_.pair_queue_size || !std::isfinite(config_.pair_max_wait_s) || config_.pair_max_wait_s <= 0 ||
|
||||
!std::isfinite(config_.observation_max_age_s) || config_.observation_max_age_s <= 0)
|
||||
throw std::invalid_argument("invalid depth pair queue/age configuration");
|
||||
}
|
||||
|
||||
void addCloud(const robot_sensor_msgs::PointCloud2& cloud)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
observeClock();
|
||||
if (cloud.header.stamp.isZero()) { ++counts_.invalid; return; }
|
||||
const auto key = cloud.header.stamp.toNSec();
|
||||
if (key <= applied_stamp_) { ++counts_.duplicate; return; }
|
||||
auto& p = pending_[key];
|
||||
if (p.cloud) { ++counts_.duplicate; return; }
|
||||
if (!p.depth) p.arrival = Clock::now();
|
||||
p.cloud = boost::make_shared<robot_sensor_msgs::PointCloud2>(cloud);
|
||||
expire();
|
||||
}
|
||||
void addDepth(robot_sensor_msgs::DepthCameraData::ConstPtr depth)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
observeClock();
|
||||
if (!depth || depth->depth.header.stamp.isZero()) { ++counts_.invalid; return; }
|
||||
const auto key = depth->depth.header.stamp.toNSec();
|
||||
if (key <= applied_stamp_) { ++counts_.duplicate; return; }
|
||||
auto& p = pending_[key];
|
||||
if (p.depth) { ++counts_.duplicate; return; }
|
||||
if (!p.cloud) p.arrival = Clock::now();
|
||||
p.depth = std::move(depth);
|
||||
expire();
|
||||
}
|
||||
bool next(Candidate& out)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
observeClock(); expire();
|
||||
for (auto it = pending_.begin(); it != pending_.end();)
|
||||
{
|
||||
auto& p = it->second;
|
||||
if (!p.cloud || !p.depth) { ++it; continue; }
|
||||
if (p.cloud->header.frame_id != p.depth->depth.header.frame_id ||
|
||||
p.depth->depth.header.stamp != p.depth->camera_info.header.stamp ||
|
||||
p.depth->depth.header.stamp != p.depth->header.stamp)
|
||||
{
|
||||
++counts_.invalid;
|
||||
it = pending_.erase(it);
|
||||
continue;
|
||||
}
|
||||
out = {it->first, p.cloud, p.depth};
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void applied(uint64_t stamp)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
applied_stamp_ = std::max(applied_stamp_, stamp);
|
||||
last_applied_ = robot::Time::now();
|
||||
++counts_.applied;
|
||||
for (auto it = pending_.begin(); it != pending_.end() && it->first <= applied_stamp_;)
|
||||
it = pending_.erase(it);
|
||||
}
|
||||
void discard(uint64_t stamp)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
pending_.erase(stamp); ++counts_.invalid;
|
||||
}
|
||||
void noteTfWait()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_); ++counts_.tf_wait;
|
||||
}
|
||||
bool isCurrent()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
observeClock();
|
||||
const auto last = last_applied_.isZero() ? started_ : last_applied_;
|
||||
return expected_period_ <= 0 || (robot::Time::now() - last).toSec() <= expected_period_;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
const auto watermark = applied_stamp_;
|
||||
resetUnlocked(robot::Time::now());
|
||||
applied_stamp_ = watermark; // map resets must not replay a cached old frame
|
||||
}
|
||||
Counts counts() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_); return counts_;
|
||||
}
|
||||
|
||||
private:
|
||||
struct Pending
|
||||
{
|
||||
robot_sensor_msgs::PointCloud2::ConstPtr cloud;
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr depth;
|
||||
Clock::time_point arrival;
|
||||
};
|
||||
void resetUnlocked(const robot::Time& now)
|
||||
{
|
||||
pending_.clear(); applied_stamp_ = 0; last_applied_ = robot::Time();
|
||||
started_ = now; last_clock_ = now;
|
||||
}
|
||||
void observeClock()
|
||||
{
|
||||
const auto now = robot::Time::now();
|
||||
if (now < last_clock_) resetUnlocked(now);
|
||||
last_clock_ = now;
|
||||
}
|
||||
void expire()
|
||||
{
|
||||
const auto now = Clock::now();
|
||||
const double measurement_now = robot::Time::now().toSec();
|
||||
for (auto it = pending_.begin(); it != pending_.end();)
|
||||
{
|
||||
const double age = measurement_now - static_cast<double>(it->first) * 1e-9;
|
||||
if (age > config_.observation_max_age_s || age < -.05)
|
||||
{ ++counts_.stale; it = pending_.erase(it); }
|
||||
else if (std::chrono::duration<double>(now - it->second.arrival).count() > config_.pair_max_wait_s)
|
||||
{ ++counts_.expired; it = pending_.erase(it); }
|
||||
else ++it;
|
||||
}
|
||||
while (pending_.size() > config_.pair_queue_size)
|
||||
{ pending_.erase(pending_.begin()); ++counts_.overflow; }
|
||||
}
|
||||
DepthFrustumConfig config_;
|
||||
double expected_period_;
|
||||
robot::Time started_, last_clock_, last_applied_;
|
||||
uint64_t applied_stamp_{0};
|
||||
std::map<uint64_t, Pending> pending_;
|
||||
Counts counts_;
|
||||
mutable std::mutex mutex_;
|
||||
};
|
||||
} // namespace robot_costmap_2d
|
||||
@@ -1,68 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <robot_costmap_2d/observation.h>
|
||||
#include <tf3/compat.h>
|
||||
#include <Eigen/Geometry>
|
||||
#include <vector>
|
||||
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
enum class DepthVisibility { Free, Unknown, Surface };
|
||||
enum class DepthVisibilityReason { Free, OutsideView, InvalidDepth, Surface, EmptyRegion };
|
||||
/// What one frame says about a marked voxel under the re-observe-or-clear rule, weakest first.
|
||||
enum class DepthObservation { OutOfView, NoReturn, SeenThrough, Occluded, Confirmed };
|
||||
struct DepthVisibilityResult
|
||||
{
|
||||
DepthVisibility state{DepthVisibility::Unknown};
|
||||
DepthVisibilityReason reason{DepthVisibilityReason::OutsideView};
|
||||
};
|
||||
|
||||
// Pure geometry/measurement helper. It never mutates occupancy or queries TF.
|
||||
class DepthVisibilityChecker
|
||||
{
|
||||
public:
|
||||
bool prepare(robot_sensor_msgs::DepthCameraData::ConstPtr data,
|
||||
const tf3::TransformStampedMsg& global_from_camera,
|
||||
double min_height, double max_height, const DepthFrustumConfig& config);
|
||||
DepthVisibilityResult classify(const Eigen::Vector3d& lower,
|
||||
const Eigen::Vector3d& upper) const;
|
||||
|
||||
/**
|
||||
* @brief Certifies the measured evidence points of one voxel [global frame, m].
|
||||
*
|
||||
* Free only when every point projects with its projection_margin_px patch fully inside
|
||||
* the usable image, every patch pixel holds valid depth, and that depth lies behind the
|
||||
* point by more than free_margin_m. Any pixel in front keeps the voxel (Surface); an
|
||||
* invalid pixel or a point out of view keeps it as Unknown. An empty list is Unknown.
|
||||
*/
|
||||
DepthVisibilityResult classifyPoints(const std::vector<Eigen::Vector3d>& points) const;
|
||||
|
||||
/**
|
||||
* @brief Re-observes the measured evidence points of one voxel [global frame, m].
|
||||
*
|
||||
* Per point, its projection_margin_px patch decides: a valid pixel within confirm_tolerance_m
|
||||
* of the point is Confirmed; otherwise a valid pixel in front is Occluded; otherwise one
|
||||
* behind is SeenThrough; otherwise NoReturn. A point outside the trusted depth range, the
|
||||
* usable image or the stereo band is OutOfView. The voxel takes its strongest point result.
|
||||
*/
|
||||
DepthObservation observePoints(const std::vector<Eigen::Vector3d>& points) const;
|
||||
|
||||
/// True when a global-frame point projects at least border_px inside the usable image
|
||||
/// (the clear_left/right border strips and the stereo band are not usable). Used to gate
|
||||
/// evidence marking, so every marked point can be re-checked later.
|
||||
bool projectsInside(const Eigen::Vector3d& point, unsigned int border_px) const;
|
||||
|
||||
private:
|
||||
/// Raw depth at a pixel [m]; NaN for an unsupported encoding. Caller checks bounds.
|
||||
double depthAt(int u, int v) const;
|
||||
/// First usable image column for a point at depth z [m] > 0: the left border strip or the
|
||||
/// stereo no-disparity band, whichever is wider.
|
||||
int usableLeft(double z) const;
|
||||
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr data_;
|
||||
Eigen::Isometry3d camera_from_global_{Eigen::Isometry3d::Identity()};
|
||||
double min_height_{0}, max_height_{0};
|
||||
DepthFrustumConfig config_;
|
||||
unsigned int bytes_per_pixel_{0};
|
||||
};
|
||||
} // namespace robot_costmap_2d
|
||||
@@ -34,7 +34,6 @@
|
||||
|
||||
#include <robot_geometry_msgs/Point.h>
|
||||
#include <robot_sensor_msgs/PointCloud2.h>
|
||||
#include <robot_sensor_msgs/DepthCameraData.h>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <utility>
|
||||
@@ -42,184 +41,6 @@
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A depth frame and its per-source frustum-clearing configuration.
|
||||
*
|
||||
* The message is shared so returning buffered observations does not copy the
|
||||
* full depth image on every costmap update.
|
||||
*/
|
||||
/// Per-observation-source configuration of the depth-image frustum clearing,
|
||||
/// loaded by ObstacleLayer from the source's YAML/ROS params and carried with
|
||||
/// each DepthCameraObservation.
|
||||
struct DepthFrustumConfig
|
||||
{
|
||||
unsigned int pixel_step = 0;
|
||||
double min_range = 0.0;
|
||||
double max_range = 0.0;
|
||||
/// 3D clearing rays stop this far [m] before the measured surface.
|
||||
/// Negative: legacy 2 * costmap resolution.
|
||||
double skip_distance = -1.0;
|
||||
/// Full-column clearing from the per-pixel-column nearest in-band return.
|
||||
bool column_clearing = false;
|
||||
/// Height band [m] used for the in-band test; floor returns below min do
|
||||
/// not shorten the beam. max < 0: use the layer max_obstacle_height.
|
||||
double column_min_height = 0.10;
|
||||
double column_max_height = -1.0;
|
||||
/// Column beams stop this far [m] before the nearest in-band return.
|
||||
double column_skip_distance = 0.02;
|
||||
/// Full columns are only cleared beyond this distance [m]. Negative:
|
||||
/// derive each frame from the camera intrinsics and mounting pose.
|
||||
double column_cover_distance = -1.0;
|
||||
/// Depth-image columns at the LEFT edge excluded from clearing [px]. Covers
|
||||
/// the stereo no-disparity strip that is permanently invalid there: those
|
||||
/// pixels carry no free-space evidence, so clearing through them erases
|
||||
/// obstacles that rotate out of the FOV on that side. Set to the measured
|
||||
/// width of the black strip in the raw depth image (a few px margin). 0
|
||||
/// disables. Invalid pixels ELSEWHERE still clear (needed for ghost removal).
|
||||
unsigned int clear_left_border_px = 0;
|
||||
/// Same as clear_left_border_px but for the RIGHT edge, for cameras whose
|
||||
/// stereo no-disparity strip sits on the right instead of the left. Measured
|
||||
/// from the last image column inward. 0 disables.
|
||||
unsigned int clear_right_border_px = 0;
|
||||
// Opt-in observed-volume mode. Legacy range/column keys are not used by it.
|
||||
bool observed_volume_clearing = false;
|
||||
double voxel_z_resolution_m = 0.0625; // depth-only grid: low objects must not occupy an entire 20 cm slab
|
||||
std::string paired_marking_source;
|
||||
unsigned int pair_queue_size = 4;
|
||||
double pair_max_wait_s = 0.25;
|
||||
double observation_max_age_s = 0.5;
|
||||
double valid_min_z_m = 0.1;
|
||||
double valid_max_z_m = 3.0;
|
||||
double free_margin_m = 0.02;
|
||||
unsigned int projection_margin_px = 1;
|
||||
/// Certify the measured evidence points of each marked voxel instead of the whole
|
||||
/// voxel box. A box cut by the image edge can never be certified, while the points
|
||||
/// that marked it were inside the image when they were seen.
|
||||
bool evidence_points_enabled = false;
|
||||
/// [points] evidence kept per voxel: 6 per-axis extremes plus the most recent ones.
|
||||
unsigned int evidence_points_per_voxel = 8;
|
||||
/// [px] with evidence points, marking drops points that project closer than this to
|
||||
/// the usable image edge, so each kept point has a full projection patch in view.
|
||||
unsigned int marking_border_px = 0;
|
||||
/// With evidence points, a valid return deeper than valid_max_z_m counts as behind a point
|
||||
/// that lies at least free_margin_m inside the trusted range: the ray passed the point.
|
||||
bool far_return_is_behind = false;
|
||||
/// Re-observe-or-clear rule (needs evidence points). A marked voxel in view must be measured
|
||||
/// again at one of its points each frame; seen through for miss_frames frames in a row frees
|
||||
/// it. Occluded, out-of-view and no-return frames keep it, so nothing expires out of the FOV.
|
||||
/// false: a voxel is freed only when every pixel of every point proves free space.
|
||||
bool reobserve_clearing = false;
|
||||
/// [m] Re-observe: |measured - point depth| within this means the surface is still there.
|
||||
/// Nearer than that is an occluder, deeper is free space seen through. Replaces free_margin_m.
|
||||
double confirm_tolerance_m = 0.05;
|
||||
/// [frames] Re-observe: seen-through frames in a row that free a voxel.
|
||||
unsigned int miss_frames = 3;
|
||||
/// [0..1] Re-observe: miss added by a frame whose patch pixels are all invalid. 0 keeps invalid
|
||||
/// depth as unknown; > 0 lets voxels in view expire where the camera returns nothing.
|
||||
double no_return_weight = 0.0;
|
||||
/// [m] Stereo baseline of the left no-disparity band, fx * baseline / z + stereo_band_margin_px
|
||||
/// wide at depth z. Points inside it cannot be re-checked: they are out of view and are not
|
||||
/// marked. 0 disables (only clear_left_border_px applies).
|
||||
double stereo_baseline_m = 0.0;
|
||||
/// [px] Added to the stereo band width.
|
||||
unsigned int stereo_band_margin_px = 10;
|
||||
};
|
||||
|
||||
class DepthCameraObservation
|
||||
{
|
||||
public:
|
||||
DepthCameraObservation()
|
||||
: data_handle_(),
|
||||
data_(nullptr),
|
||||
topic_()
|
||||
{
|
||||
}
|
||||
|
||||
DepthCameraObservation(
|
||||
const robot_sensor_msgs::DepthCameraData& data,
|
||||
std::string topic,
|
||||
const robot::Time& received_time,
|
||||
const DepthFrustumConfig& frustum)
|
||||
: data_handle_(boost::make_shared<robot_sensor_msgs::DepthCameraData>(data)),
|
||||
data_(data_handle_.get()),
|
||||
topic_(std::move(topic)),
|
||||
received_time_(received_time),
|
||||
frustum_(frustum)
|
||||
{
|
||||
}
|
||||
|
||||
DepthCameraObservation(
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr data,
|
||||
std::string topic,
|
||||
const robot::Time& received_time,
|
||||
const DepthFrustumConfig& frustum)
|
||||
: data_handle_(std::move(data)),
|
||||
data_(data_handle_.get()),
|
||||
topic_(std::move(topic)),
|
||||
received_time_(received_time),
|
||||
frustum_(frustum)
|
||||
{
|
||||
}
|
||||
|
||||
DepthCameraObservation(const DepthCameraObservation& other)
|
||||
: data_handle_(other.data_handle_),
|
||||
data_(data_handle_.get()),
|
||||
topic_(other.topic_),
|
||||
received_time_(other.received_time_),
|
||||
frustum_(other.frustum_)
|
||||
{
|
||||
}
|
||||
|
||||
DepthCameraObservation(DepthCameraObservation&& other) noexcept
|
||||
: data_handle_(std::move(other.data_handle_)),
|
||||
data_(data_handle_.get()),
|
||||
topic_(std::move(other.topic_)),
|
||||
received_time_(other.received_time_),
|
||||
frustum_(other.frustum_)
|
||||
{
|
||||
other.data_ = nullptr;
|
||||
other.frustum_ = DepthFrustumConfig();
|
||||
}
|
||||
|
||||
DepthCameraObservation& operator=(const DepthCameraObservation& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
data_handle_ = other.data_handle_;
|
||||
data_ = data_handle_.get();
|
||||
topic_ = other.topic_;
|
||||
received_time_ = other.received_time_;
|
||||
frustum_ = other.frustum_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DepthCameraObservation& operator=(DepthCameraObservation&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
data_handle_ = std::move(other.data_handle_);
|
||||
data_ = data_handle_.get();
|
||||
topic_ = std::move(other.topic_);
|
||||
received_time_ = other.received_time_;
|
||||
frustum_ = other.frustum_;
|
||||
|
||||
other.data_ = nullptr;
|
||||
other.frustum_ = DepthFrustumConfig();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~DepthCameraObservation() = default;
|
||||
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr data_handle_;
|
||||
const robot_sensor_msgs::DepthCameraData* data_;
|
||||
std::string topic_;
|
||||
robot::Time received_time_;
|
||||
DepthFrustumConfig frustum_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Stores an observation in terms of a point cloud and the origin of the source
|
||||
* @note Tried to make members and constructor arguments const but the compiler would not accept the default
|
||||
|
||||
@@ -50,14 +50,6 @@
|
||||
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
// Opt-in per source: legacy callers keep their TF and cloud policy.
|
||||
struct CloudProcessingConfig
|
||||
{
|
||||
bool transform_at_stamp{false};
|
||||
bool voxel_filter_enabled{false};
|
||||
double voxel_leaf_size{0.05}; // [m], applied after height/range gates
|
||||
};
|
||||
|
||||
/**
|
||||
* @class ObservationBuffer
|
||||
* @brief Takes in point clouds from sensors, transforms them to the desired frame, and stores them
|
||||
@@ -83,12 +75,6 @@ public:
|
||||
double min_obstacle_height, double max_obstacle_height, double obstacle_range,
|
||||
double raytrace_range, tf3::BufferCore& tf3_buffer, std::string global_frame,
|
||||
std::string sensor_frame, double tf_tolerance);
|
||||
|
||||
ObservationBuffer(std::string topic_name, double observation_keep_time, double expected_update_rate,
|
||||
double min_obstacle_height, double max_obstacle_height, double obstacle_range,
|
||||
double raytrace_range, const DepthFrustumConfig& frustum_config,
|
||||
tf3::BufferCore& tf3_buffer, std::string global_frame,
|
||||
std::string sensor_frame, double tf_tolerance);
|
||||
|
||||
|
||||
/**
|
||||
@@ -112,32 +98,12 @@ public:
|
||||
*/
|
||||
void bufferCloud(const robot_sensor_msgs::PointCloud2& cloud);
|
||||
|
||||
// Configure before receiving samples. Empty valid clouds return true;
|
||||
// missing TF/malformed observations return false and do not refresh the buffer.
|
||||
void setCloudProcessingConfig(const CloudProcessingConfig& config);
|
||||
bool tryBufferCloud(const robot_sensor_msgs::PointCloud2& cloud);
|
||||
bool tryBufferCloudWithTransform(const robot_sensor_msgs::PointCloud2& cloud,
|
||||
const tf3::TransformStampedMsg& transform);
|
||||
const std::string& sensorFrame() const { return sensor_frame_; }
|
||||
|
||||
/**
|
||||
* @brief Store the newest depth frame without converting it to PointCloud2.
|
||||
*/
|
||||
void bufferDepthCamera(const robot_sensor_msgs::DepthCameraData& depth);
|
||||
|
||||
void bufferDepthCamera(robot_sensor_msgs::DepthCameraData::ConstPtr depth);
|
||||
|
||||
/**
|
||||
* @brief Pushes copies of all current observations onto the end of the vector passed in
|
||||
* @param observations The vector to be filled
|
||||
*/
|
||||
void getObservations(std::vector<Observation>& observations);
|
||||
|
||||
/**
|
||||
* @brief Append the current depth observation, if it has not expired.
|
||||
*/
|
||||
void getDepthObservations(std::vector<DepthCameraObservation>& observations);
|
||||
|
||||
/**
|
||||
* @brief Check if the observation buffer is being update at its expected rate
|
||||
* @return True if it is being updated at the expected rate, false otherwise
|
||||
@@ -171,10 +137,6 @@ private:
|
||||
*/
|
||||
void purgeStaleObservations();
|
||||
|
||||
void purgeStaleDepthObservations();
|
||||
bool tryBufferCloudImpl(const robot_sensor_msgs::PointCloud2& cloud,
|
||||
const tf3::TransformStampedMsg* prepared_transform);
|
||||
|
||||
tf3::BufferCore& tf3_buffer_;
|
||||
const robot::Duration observation_keep_time_;
|
||||
const robot::Duration expected_update_rate_;
|
||||
@@ -182,15 +144,11 @@ private:
|
||||
std::string global_frame_;
|
||||
std::string sensor_frame_;
|
||||
std::list<Observation> observation_list_;
|
||||
std::list<DepthCameraObservation> depth_observation_list_;
|
||||
// DepthCameraObservation depth_observation_;
|
||||
std::string topic_name_;
|
||||
double min_obstacle_height_, max_obstacle_height_;
|
||||
boost::recursive_mutex lock_; ///< @brief A lock for accessing data in callbacks safely
|
||||
double obstacle_range_, raytrace_range_;
|
||||
double tf_tolerance_;
|
||||
DepthFrustumConfig frustum_config_;
|
||||
CloudProcessingConfig cloud_processing_config_;
|
||||
};
|
||||
} // namespace robot_costmap_2d
|
||||
#endif // ROBOT_COSTMAP_2D_OBSERVATION_BUFFER_H_
|
||||
|
||||
@@ -42,14 +42,12 @@
|
||||
#include <robot_costmap_2d/costmap_layer.h>
|
||||
#include <robot_costmap_2d/layered_costmap.h>
|
||||
#include <robot_costmap_2d/observation_buffer.h>
|
||||
#include <robot_costmap_2d/depth_frame_pairer.h>
|
||||
#include <robot_costmap_2d/footprint.h>
|
||||
|
||||
#include <robot_nav_msgs/OccupancyGrid.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <robot_sensor_msgs/DepthCameraData.h>
|
||||
#include <robot_sensor_msgs/LaserScan.h>
|
||||
#include <robot_laser_geometry/laser_geometry.hpp>
|
||||
#include <robot_sensor_msgs/PointCloud.h>
|
||||
@@ -132,12 +130,6 @@ protected:
|
||||
void pointCloud2Callback(const robot_sensor_msgs::PointCloud2& message,
|
||||
const boost::shared_ptr<robot_costmap_2d::ObservationBuffer>& buffer);
|
||||
|
||||
/**
|
||||
* @brief Buffer a depth image and its camera model for frustum clearing.
|
||||
*/
|
||||
void depthImageCallback(robot_sensor_msgs::DepthCameraData::ConstPtr message,
|
||||
const boost::shared_ptr<robot_costmap_2d::ObservationBuffer>& buffer);
|
||||
|
||||
/**
|
||||
* @brief Get the observations used to mark space
|
||||
* @param marking_observations A reference to a vector that will be populated with the observations
|
||||
@@ -152,13 +144,6 @@ protected:
|
||||
*/
|
||||
bool getClearingObservations(std::vector<robot_costmap_2d::Observation>& clearing_observations) const;
|
||||
|
||||
/**
|
||||
* @brief Collect fresh depth frames from every configured frustum-clearing source.
|
||||
* @return True when every configured depth source is current.
|
||||
*/
|
||||
bool getFrustumClearingObservations(
|
||||
std::vector<robot_costmap_2d::DepthCameraObservation>& frustum_clearing_observations) const;
|
||||
|
||||
/**
|
||||
* @brief Clear freespace based on one observation
|
||||
* @param clearing_observation The observation used to raytrace
|
||||
@@ -187,9 +172,6 @@ protected:
|
||||
std::vector<boost::shared_ptr<robot_costmap_2d::ObservationBuffer> > marking_buffers_; ///< @brief Used to store observation buffers used for marking obstacles
|
||||
std::vector<boost::shared_ptr<robot_costmap_2d::ObservationBuffer> > clearing_buffers_; ///< @brief Used to store observation buffers used for clearing obstacles
|
||||
|
||||
std::vector<boost::shared_ptr<robot_costmap_2d::ObservationBuffer> > depth_observation_buffers_;
|
||||
std::vector<boost::shared_ptr<robot_costmap_2d::ObservationBuffer> > depth_clearing_buffers_;
|
||||
|
||||
// Used only for testing purposes
|
||||
std::vector<robot_costmap_2d::Observation> static_clearing_observations_, static_marking_observations_;
|
||||
|
||||
@@ -198,24 +180,6 @@ protected:
|
||||
|
||||
int combination_method_;
|
||||
std::vector<CallBackInfo> callback_infos_;
|
||||
std::vector<CallBackInfo> callback_depth_infos_;
|
||||
std::string depth_camera_data_topic_;
|
||||
mutable std::mutex depth_camera_data_mutex_;
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr pending_depth_camera_data_;
|
||||
|
||||
struct PairedDepthSource
|
||||
{
|
||||
PairedDepthSource(const DepthFrustumConfig& config, double expected_period)
|
||||
: config(config), pairer(config, expected_period) {}
|
||||
std::string cloud_topic, depth_topic;
|
||||
boost::shared_ptr<ObservationBuffer> marking_buffer, depth_buffer;
|
||||
double min_height{0}, max_height{0};
|
||||
DepthFrustumConfig config;
|
||||
DepthFramePairer pairer;
|
||||
};
|
||||
std::vector<boost::shared_ptr<PairedDepthSource>> paired_depth_sources_;
|
||||
bool pairedDepthCurrent() const;
|
||||
void resetPairedDepth();
|
||||
|
||||
private:
|
||||
bool getParams(const std::string& config_file_name, robot::NodeHandle &nh);
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include <robot_sensor_msgs/PointCloud2.h>
|
||||
#include <robot_sensor_msgs/point_cloud_conversion.h>
|
||||
#include <robot_costmap_2d/obstacle_layer.h>
|
||||
#include <robot_costmap_2d/depth_evidence_store.h>
|
||||
#include <robot_voxel_grid/voxel_grid.h>
|
||||
|
||||
#include <limits>
|
||||
@@ -58,9 +57,6 @@
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
|
||||
class DepthVisibilityChecker;
|
||||
enum class DepthObservation;
|
||||
|
||||
class VoxelLayer : public ObstacleLayer
|
||||
{
|
||||
public:
|
||||
@@ -77,17 +73,12 @@ public:
|
||||
double* max_x, double* max_y);
|
||||
|
||||
void updateOrigin(double new_origin_x, double new_origin_y);
|
||||
// Diagnostic snapshot; caller must hold the layer/update lock, as with getCharMap().
|
||||
VoxelGrid voxelSnapshot();
|
||||
bool isDiscretized()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual void matchSize();
|
||||
virtual void reset();
|
||||
/// Recovery clear. Also drops the voxels and evidence points of the cleared cells: the
|
||||
/// base class only writes the 2D cells, and the next column update re-derived the obstacle.
|
||||
void clearArea(int start_x, int start_y, int end_x, int end_y, bool invert_area = false) override;
|
||||
|
||||
LayerType getType() const override
|
||||
{
|
||||
@@ -103,103 +94,15 @@ private:
|
||||
void clearNonLethal(double wx, double wy, double w_size_x, double w_size_y, bool clear_no_info);
|
||||
virtual void raytraceFreespace(const robot_costmap_2d::Observation& clearing_observation, double* min_x, double* min_y,
|
||||
double* max_x, double* max_y);
|
||||
// bool raytraceDepthFrustum(double* min_x, double* min_y, double* max_x, double* max_y);
|
||||
bool raytraceDepthFrustum(const robot_costmap_2d::DepthCameraObservation& observation,
|
||||
double* min_x, double* min_y, double* max_x, double* max_y);
|
||||
bool readDepthMeters(const robot_sensor_msgs::Image& depth, unsigned int u, unsigned int v,
|
||||
double& depth_m, bool& is_valid) const;
|
||||
void updateDepthRayCache(unsigned int width, unsigned int height, unsigned int pixel_step,
|
||||
double fx, double fy, double cx, double cy);
|
||||
bool clipRaytraceEndpoint(double ox, double oy, double oz, double& wx, double& wy, double& wz);
|
||||
bool clearVoxelRay(double ox, double oy, double oz, double wx, double wy, double wz,
|
||||
double raytrace_range, unsigned int cell_raytrace_range,
|
||||
double* min_x, double* min_y, double* max_x, double* max_y);
|
||||
bool clearDepthColumns(double ox, double oy, double cover_distance, double far_distance,
|
||||
double min_range, double max_range, double skip_dist,
|
||||
double* min_x, double* min_y, double* max_x, double* max_y);
|
||||
bool clipColumnSegment(double& sx, double& sy, double& ex, double& ey) const;
|
||||
/// Paired depth marking: the checker of the same frame gates marking at the image
|
||||
/// border and the store records evidence points. Null for every other source.
|
||||
struct PairedMarking
|
||||
{
|
||||
const DepthVisibilityChecker* checker;
|
||||
const DepthFrustumConfig* config;
|
||||
};
|
||||
void markObservation(const Observation& observation, double* min_x, double* min_y,
|
||||
double* max_x, double* max_y, const PairedMarking* paired = nullptr);
|
||||
void processPairedDepth(double* min_x, double* min_y, double* max_x, double* max_y);
|
||||
struct VisibilityCounts
|
||||
{
|
||||
uint64_t free{0}, unknown{0}, surface{0}, frames{0};
|
||||
uint64_t by_evidence{0}; ///< decisions made from evidence points
|
||||
uint64_t border_dropped{0}; ///< marking points dropped at the image border
|
||||
/// re-observe-or-clear outcomes per voxel and frame
|
||||
uint64_t confirmed{0}, occluded{0}, seen_through{0}, no_return{0}, out_of_view{0};
|
||||
} visibility_counts_;
|
||||
/// Re-observe-or-clear: applies one frame's observation to the voxel's miss count.
|
||||
/// Returns true when the voxel is to be freed.
|
||||
bool reobserveFrees(DepthObservation observation, const DepthEvidenceStore::VoxelKey& key,
|
||||
const DepthFrustumConfig& config);
|
||||
|
||||
/// Window-independent key: local cell index plus the cells the rolling origin moved.
|
||||
DepthEvidenceStore::VoxelKey evidenceKey(unsigned int x, unsigned int y, unsigned int z) const
|
||||
{
|
||||
return {static_cast<int>(x) + evidence_offset_x_, static_cast<int>(y) + evidence_offset_y_, z};
|
||||
}
|
||||
/// Drops evidence of voxels that left the window or are no longer MARKED.
|
||||
void pruneDepthEvidence();
|
||||
/// Frees every voxel of the column and its evidence points; the 2D cell is left to the caller.
|
||||
void clearDepthColumn(unsigned int x, unsigned int y);
|
||||
/// Paired depth only: the voxels under the footprint, which ObstacleLayer frees in 2D only.
|
||||
void clearFootprintVoxels();
|
||||
DepthEvidenceStore depth_evidence_;
|
||||
int evidence_offset_x_ = 0;
|
||||
int evidence_offset_y_ = 0;
|
||||
uint64_t frames_since_evidence_prune_ = 0;
|
||||
|
||||
|
||||
bool publish_voxel_;
|
||||
robot_voxel_grid::VoxelGrid robot_voxel_grid_;
|
||||
double z_resolution_, origin_z_;
|
||||
/// Scratch for the full-column clearing pass (config lives per observation
|
||||
/// source in DepthFrustumConfig): per depth-image pixel column, the nearest
|
||||
/// return inside the obstacle height band certifies "no obstacle in this
|
||||
/// direction closer than d". Cells along that 2D beam get their whole voxel
|
||||
/// column cleared, removing marked voxels the per-pixel 3D rays cannot
|
||||
/// reach (above the vertical FOV at close range).
|
||||
struct DepthColumnStat
|
||||
{
|
||||
double min_band_dist = -1.0; ///< horizontal distance of nearest in-band return; < 0 = none
|
||||
double azimuth = 0.0; ///< beam direction in the global frame
|
||||
double best_row_delta = std::numeric_limits<double>::infinity();
|
||||
bool has_ray = false; ///< column had at least one readable pixel
|
||||
bool in_border = false; ///< column lies in a left/right no-disparity strip
|
||||
};
|
||||
std::vector<DepthColumnStat> depth_column_stats_;
|
||||
unsigned int unknown_threshold_, mark_threshold_, size_z_;
|
||||
robot_sensor_msgs::PointCloud clearing_endpoints_;
|
||||
std::vector<unsigned char> rolling_costmap_scratch_;
|
||||
std::vector<unsigned int> rolling_voxel_scratch_;
|
||||
|
||||
struct DepthRay
|
||||
{
|
||||
unsigned int u;
|
||||
unsigned int v;
|
||||
unsigned int col; ///< pixel-column index in the cache (border column included)
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
std::vector<DepthRay> depth_ray_cache_;
|
||||
unsigned int cached_column_count_ = 0;
|
||||
unsigned int cached_depth_width_ = 0;
|
||||
unsigned int cached_depth_height_ = 0;
|
||||
unsigned int cached_depth_pixel_step_ = 0;
|
||||
double cached_fx_ = 0.0;
|
||||
double cached_fy_ = 0.0;
|
||||
double cached_cx_ = 0.0;
|
||||
double cached_cy_ = 0.0;
|
||||
|
||||
inline bool worldToMap3DFloat(double wx, double wy, double wz, double& mx, double& my, double& mz)
|
||||
{
|
||||
if (wx < origin_x_ || wy < origin_y_ || wz < origin_z_)
|
||||
|
||||
Reference in New Issue
Block a user