4747#include " tf2_geometry_msgs/tf2_geometry_msgs.hpp"
4848#include " nav2_util/validate_messages.hpp"
4949
50+ #define EPSILON 1e-5
51+
5052PLUGINLIB_EXPORT_CLASS (nav2_costmap_2d::StaticLayer, nav2_costmap_2d::Layer)
5153
5254using nav2_costmap_2d::NO_INFORMATION;
@@ -196,9 +198,9 @@ StaticLayer::processMap(const nav_msgs::msg::OccupancyGrid & new_map)
196198 Costmap2D * master = layered_costmap_->getCostmap ();
197199 if (!layered_costmap_->isRolling () && (master->getSizeInCellsX () != size_x ||
198200 master->getSizeInCellsY () != size_y ||
199- master->getResolution () != new_map.info .resolution ||
200- master->getOriginX () != new_map.info .origin .position .x ||
201- master->getOriginY () != new_map.info .origin .position .y ||
201+ ! isEqual ( master->getResolution (), new_map.info .resolution , EPSILON) ||
202+ ! isEqual ( master->getOriginX (), new_map.info .origin .position .x , EPSILON) ||
203+ ! isEqual ( master->getOriginY (), new_map.info .origin .position .y , EPSILON) ||
202204 !layered_costmap_->isSizeLocked ()))
203205 {
204206 // Update the size of the layered costmap (and all layers, including this one)
@@ -212,9 +214,9 @@ StaticLayer::processMap(const nav_msgs::msg::OccupancyGrid & new_map)
212214 new_map.info .origin .position .y ,
213215 true );
214216 } else if (size_x_ != size_x || size_y_ != size_y || // NOLINT
215- resolution_ != new_map.info .resolution ||
216- origin_x_ != new_map.info .origin .position .x ||
217- origin_y_ != new_map.info .origin .position .y )
217+ ! isEqual ( resolution_, new_map.info .resolution , EPSILON) ||
218+ ! isEqual ( origin_x_, new_map.info .origin .position .x , EPSILON) ||
219+ ! isEqual ( origin_y_, new_map.info .origin .position .y , EPSILON) )
218220 {
219221 // only update the size of the costmap stored locally in this layer
220222 RCLCPP_INFO (
@@ -467,6 +469,18 @@ StaticLayer::updateCosts(
467469 current_ = true ;
468470}
469471
472+ /* *
473+ * @brief Check if two floating point numbers are equal within a given epsilon
474+ * @param a First number
475+ * @param b Second number
476+ * @param epsilon Tolerance for equality check
477+ * @return True if numbers are equal within the tolerance, false otherwise
478+ */
479+ bool StaticLayer::isEqual (double a, double b, double epsilon)
480+ {
481+ return std::abs (a - b) < epsilon;
482+ }
483+
470484/* *
471485 * @brief Callback executed when a parameter change is detected
472486 * @param event ParameterEvent message
0 commit comments