22 #include "nav2_costmap_2d/footprint_collision_checker.hpp"
24 #include "nav2_costmap_2d/cost_values.hpp"
25 #include "nav2_costmap_2d/exceptions.hpp"
26 #include "nav2_costmap_2d/footprint.hpp"
27 #include "nav2_util/line_iterator.hpp"
29 using namespace std::chrono_literals;
34 template<
typename CostmapT>
40 template<
typename CostmapT>
47 template<
typename CostmapT>
51 unsigned int x0, x1, y0, y1;
52 double footprint_cost = 0.0;
55 if (!worldToMap(footprint[0].x, footprint[0].y, x0, y0)) {
56 return static_cast<double>(LETHAL_OBSTACLE);
60 unsigned int xstart = x0;
61 unsigned int ystart = y0;
64 for (
unsigned int i = 0; i < footprint.size() - 1; ++i) {
66 if (!
worldToMap(footprint[i + 1].x, footprint[i + 1].y, x1, y1)) {
67 return static_cast<double>(LETHAL_OBSTACLE);
70 footprint_cost = std::max(lineCost(x0, x1, y0, y1), footprint_cost);
77 if (footprint_cost ==
static_cast<double>(LETHAL_OBSTACLE)) {
78 return footprint_cost;
84 return std::max(lineCost(xstart, x1, ystart, y1), footprint_cost);
87 template<
typename CostmapT>
90 double line_cost = 0.0;
91 double point_cost = -1.0;
94 point_cost = pointCost(line.getX(), line.getY());
97 if (point_cost ==
static_cast<double>(LETHAL_OBSTACLE)) {
101 if (line_cost < point_cost) {
102 line_cost = point_cost;
109 template<
typename CostmapT>
111 double wx,
double wy,
unsigned int & mx,
unsigned int & my)
113 return costmap_->worldToMap(wx, wy, mx, my);
116 template<
typename CostmapT>
119 return static_cast<double>(costmap_->getCost(x, y));
122 template<
typename CostmapT>
128 template<
typename CostmapT>
130 double x,
double y,
double theta,
const Footprint & footprint)
132 double cos_th = cos(theta);
133 double sin_th = sin(theta);
134 Footprint oriented_footprint;
135 oriented_footprint.reserve(footprint.size());
136 geometry_msgs::msg::Point new_pt;
137 for (
unsigned int i = 0; i < footprint.size(); ++i) {
138 new_pt.x = x + (footprint[i].x * cos_th - footprint[i].y * sin_th);
139 new_pt.y = y + (footprint[i].x * sin_th + footprint[i].y * cos_th);
140 oriented_footprint.push_back(new_pt);
143 return footprintCost(oriented_footprint);
An iterator implementing Bresenham Ray-Tracing.
bool isValid() const
If the iterator is valid.