15 #ifndef NAV2_COSTMAP_2D__ASYMMETRIC_INFLATION_LAYER_HPP_
16 #define NAV2_COSTMAP_2D__ASYMMETRIC_INFLATION_LAYER_HPP_
24 #include <unordered_map>
27 #include "rclcpp/rclcpp.hpp"
28 #include "nav2_costmap_2d/inflation_layer.hpp"
29 #include "nav_msgs/msg/path.hpp"
36 std::pair<double, double> start;
37 std::pair<double, double> end;
40 enum class Side : int8_t
94 double robot_x,
double robot_y,
double robot_yaw,
double * min_x,
95 double * min_y,
double * max_x,
double * max_y)
override;
112 int min_i,
int min_j,
int max_i,
int max_j)
override;
158 double cx,
double cy,
159 const std::vector<size_t> & candidates,
160 const std::vector<AsymmetricPathSegment> & local_path_segments);
171 std::unordered_map<uint64_t, std::vector<size_t>>
173 const std::vector<AsymmetricPathSegment> & local_path_segments);
192 int roi_min_i,
int roi_min_j,
int roi_width,
int roi_height,
193 const std::unordered_map<uint64_t, std::vector<size_t>> & spatial_hash,
194 const std::vector<AsymmetricPathSegment> & local_path_segments);
213 unsigned char * master_array,
215 int min_i,
int min_j,
int max_i,
int max_j,
216 int roi_min_i,
int roi_min_j,
217 unsigned int size_x);
229 const std::vector<rclcpp::Parameter> & parameters);
236 const std::vector<rclcpp::Parameter> & parameters);
245 std::string plan_topic_;
250 double current_robot_x_{0.0};
251 double current_robot_y_{0.0};
252 bool asymmetry_active_{
false};
259 nav2::Subscription<nav_msgs::msg::Path>::SharedPtr path_sub_;
260 nav_msgs::msg::Path::ConstSharedPtr latest_global_path_;
261 std::mutex path_mutex_;
Costmap layer that inflates obstacles asymmetrically relative to the global path, biasing the navigab...
void matchSize() override
Match the size of the master costmap.
void updateCosts(nav2_costmap_2d::Costmap2D &master_grid, int min_i, int min_j, int max_i, int max_j) override
Update the costs in the master costmap.
Side computeObstacleSide(double cx, double cy, const std::vector< size_t > &candidates, const std::vector< AsymmetricPathSegment > &local_path_segments)
Classify an obstacle cell as left (+1), right (-1), or neutral (0) relative to the closest path segme...
void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y) override
Update the bounds of the master costmap by this layer's update dimensions.
rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback(const std::vector< rclcpp::Parameter > ¶meters)
Validate parameter updates (pre-set callback). Returns success/failure without mutating any state.
void applyInflation(unsigned char *master_array, const MatrixXfRM &distance_map, int min_i, int min_j, int max_i, int max_j, int roi_min_i, int roi_min_j, unsigned int size_x)
Apply disfavored-side costs from a distance map with max(old, new) semantics.
void activate() override
Activate the layer; registers the parameter validation/update callbacks.
void updateParametersCallback(const std::vector< rclcpp::Parameter > ¶meters)
Apply parameter updates (post-set callback) after they have been validated. Recomputes caches when ge...
tf2::Duration transform_tolerance_
Timeout for path-frame TF lookups.
std::vector< AsymmetricPathSegment > extractLocalPathSegments(nav2_costmap_2d::Costmap2D &master_grid)
Extract global path segments that overlap the local costmap window.
void deactivate() override
Deactivate the layer; removes the parameter validation/update callbacks.
std::unordered_map< uint64_t, std::vector< size_t > > buildPathSpatialHash(const std::vector< AsymmetricPathSegment > &local_path_segments)
Build a spatial hash mapping 2D bucket keys to path segment indices.
void onInitialize() override
Initialization process of layer on startup.
double cost_scaling_factor_right_
Exponential decay rate for cells on the RIGHT side of the path.
double goal_distance_threshold_
Distance to goal where asymmetry disables to prevent docking oscillations.
MatrixXfRM seedDistanceMap(nav2_costmap_2d::Costmap2D &master_grid, int roi_min_i, int roi_min_j, int roi_width, int roi_height, const std::unordered_map< uint64_t, std::vector< size_t >> &spatial_hash, const std::vector< AsymmetricPathSegment > &local_path_segments)
Build a distance map seeded from disfavored-side obstacle boundary cells.
double cost_scaling_factor_left_
Exponential decay rate for cells on the LEFT side of the path.
void globalPathCallback(const nav_msgs::msg::Path::ConstSharedPtr msg)
Callback for incoming global path messages.
void computeAsymmetricCaches()
Pre-compute cost_lut_disfavored_ using c_side (the smaller per-side scaling factor)
void onFootprintChanged() override
Process updates on footprint changes to the inflation layer.
std::vector< unsigned char > cost_lut_disfavored_
Cost LUT for the disfavored side, built with c_side (the smaller per-side scaling factor)
A 2D costmap provides a mapping between points in the world and their associated "costs".
Layer to convolve costmap by robot's radius or footprint using Eigen-based Felzenszwalb-Huttenlocher ...
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixXfRM
Row-major float matrix type for efficient row-wise access.