This commit is contained in:
2026-08-14 14:25:00 +07:00
parent 9f7e2f82f1
commit bb74601f09
3 changed files with 17 additions and 19 deletions

View File

@@ -174,6 +174,17 @@ public:
{ {
return robot_base_frame_; return robot_base_frame_;
} }
/** @brief Return the TF buffer shared by the costmap and navigation plugins.
*
* The returned reference is non-owning and remains valid only for the
* lifetime of this Costmap2DROBOT instance.
*/
inline tf3::BufferCore& getTfBuffer() noexcept
{
return tf_;
}
LayeredCostmap* getLayeredCostmap() const LayeredCostmap* getLayeredCostmap() const
{ {
return layered_costmap_; return layered_costmap_;

View File

@@ -602,33 +602,18 @@ bool VoxelLayer::raytraceDepthFrustum(const DepthCameraObservation& observation,
local_origin.point.y = 0.0; local_origin.point.y = 0.0;
local_origin.point.z = 0.0; local_origin.point.z = 0.0;
// Look up the sensor pose at the depth image's CAPTURE time, not the latest
// transform. The costmap update runs later than the frame was captured, so
// during rotation the latest pose orients the clearing frustum where the depth
// pixels were never measured from; the fan's free rays then sweep across and
// erase freshly marked cells, and the trailing side that gets erased flips
// with rotation direction. A stamped lookup keeps the frustum geometrically
// consistent with its own pixels. If the transform at that stamp is
// unavailable (stale / would extrapolate), skip clearing this cycle instead of
// clearing from a wrong pose. Falls back to latest only when the frame carries
// no stamp.
const robot::Time& depth_stamp = local_origin.header.stamp;
const tf3::Time query_time =
depth_stamp.isZero() ? tf3::Time() : tf3::Time(depth_stamp.sec, depth_stamp.nsec);
robot_geometry_msgs::PointStamped global_origin; robot_geometry_msgs::PointStamped global_origin;
tf3::TransformStampedMsg tfm; tf3::TransformStampedMsg tfm;
try try
{ {
tfm = tf_->lookupTransform(global_frame_, depth_frame, query_time); tfm = tf_->lookupTransform(global_frame_, depth_frame, tf3::Time());
tf3::doTransform(local_origin, global_origin, tfm); tf3::doTransform(local_origin, global_origin, tfm);
} }
catch (tf3::TransformException& ex) catch (tf3::TransformException& ex)
{ {
robot::log_error_throttle( robot::log_error_throttle(
5.0, "VoxelLayer depth topic [%s] TF exception from %s to %s at t=%.3f: %s\n", 5.0, "VoxelLayer depth topic [%s] TF exception from %s to %s: %s\n",
observation.topic_.c_str(), depth_frame.c_str(), global_frame_.c_str(), observation.topic_.c_str(), depth_frame.c_str(), global_frame_.c_str(), ex.what());
query_time.toSec(), ex.what());
return false; return false;
} }

View File

@@ -573,6 +573,7 @@ void Costmap2DROBOT::readFootprintFromConfig(const std::vector<robot_geometry_ms
void Costmap2DROBOT::setUnpaddedRobotFootprint(const std::vector<robot_geometry_msgs::Point>& points) void Costmap2DROBOT::setUnpaddedRobotFootprint(const std::vector<robot_geometry_msgs::Point>& points)
{ {
boost::recursive_mutex::scoped_lock lock(configuration_mutex_);
unpadded_footprint_ = points; unpadded_footprint_ = points;
padded_footprint_ = points; padded_footprint_ = points;
padFootprint(padded_footprint_, footprint_padding_); padFootprint(padded_footprint_, footprint_padding_);
@@ -604,6 +605,7 @@ void Costmap2DROBOT::mapUpdateLoop(double frequency)
void Costmap2DROBOT::updateMap() void Costmap2DROBOT::updateMap()
{ {
boost::recursive_mutex::scoped_lock lock(configuration_mutex_);
if (!stop_updates_) if (!stop_updates_)
{ {
// get global pose // get global pose