EasyNav Costmap Stack
Loading...
Searching...
No Matches
InflationFilter.hpp
Go to the documentation of this file.
1/*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2008, 2013, Willow Garage, Inc.
6 * Copyright 2025 Intelligent Robotics Lab
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of Willow Garage, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 * Author: Eitan Marder-Eppstein
37 * David V. Lu!!
38 * Francisco Martín Rico
39 *********************************************************************/
40
41
42#ifndef EASYNAV_PLANNER__FILTERS__IINFLATIONFILTER_HPP_
43#define EASYNAV_PLANNER__FILTERS__IINFLATIONFILTER_HPP_
44
45#include <expected>
46#include <string>
47#include <map>
48#include <vector>
49#include <mutex>
50#include <memory>
51
52#include "pluginlib/class_loader.hpp"
53
56#include "easynav_common/types/NavState.hpp"
57
59
60namespace easynav
61{
62
64{
65public:
74 CellData(unsigned int x, unsigned int y, unsigned int sx, unsigned int sy)
75 : x_(x), y_(y), src_x_(sx), src_y_(sy)
76 {
77 }
78 unsigned int x_, y_;
79 unsigned int src_x_, src_y_;
80};
81
83{
84public:
86
87 virtual std::expected<void, std::string> on_initialize();
88 virtual void update(NavState & nav_state);
89
100 void updateBounds(
101 double robot_x, double robot_y, double robot_yaw, double * min_x,
102 double * min_y,
103 double * max_x,
104 double * max_y);
113 void updateCosts(
114 easynav::Costmap2D & master_grid,
115 int min_i, int min_j, int max_i, int max_j);
116
120 void matchSize(easynav::Costmap2D & costmap);
121
125 inline unsigned char computeCost(double distance) const
126 {
127 unsigned char cost = 0;
128 if (distance == 0) {
129 cost = LETHAL_OBSTACLE;
130 } else if (distance * resolution_ <= inscribed_radius_) {
131 cost = INSCRIBED_INFLATED_OBSTACLE;
132 } else {
133 // make sure cost falls off by Euclidean distance
134 double factor =
135 exp(-1.0 * cost_scaling_factor_ * (distance * resolution_ - inscribed_radius_));
136 cost = static_cast<unsigned char>((INSCRIBED_INFLATED_OBSTACLE - 1) * factor);
137 }
138 return cost;
139 }
140
142 {
144 }
145
147 {
148 return inflation_radius_;
149 }
150
151protected:
160 inline double distanceLookup(
161 unsigned int mx, unsigned int my, unsigned int src_x,
162 unsigned int src_y)
163 {
164 unsigned int dx = (mx > src_x) ? mx - src_x : src_x - mx;
165 unsigned int dy = (my > src_y) ? my - src_y : src_y - my;
166 return cached_distances_[dx * cache_length_ + dy];
167 }
168
177 inline unsigned char costLookup(
178 unsigned int mx, unsigned int my, unsigned int src_x,
179 unsigned int src_y)
180 {
181 unsigned int dx = (mx > src_x) ? mx - src_x : src_x - mx;
182 unsigned int dy = (my > src_y) ? my - src_y : src_y - my;
183 return cached_costs_[dx * cache_length_ + dy];
184 }
185
189 void computeCaches();
190
195
199 unsigned int cellDistance(easynav::Costmap2D & costmap, double world_dist)
200 {
201 return costmap.cellDistance(world_dist);
202 }
203
207 inline void enqueue(
208 unsigned int index, unsigned int mx, unsigned int my,
209 unsigned int src_x, unsigned int src_y);
210
211
216 std::vector<std::vector<CellData>> inflation_cells_;
217
219
220 std::vector<bool> seen_;
221
222 std::vector<unsigned char> cached_costs_;
223 std::vector<double> cached_distances_;
224 std::vector<std::vector<int>> distance_matrix_;
225 unsigned int cache_length_;
227
228 // Indicates that the entire costmap should be reinflated next time around.
230
231 bool matchedSize_ {false};
232};
233
234} // namespace easynav
235
236#endif // EASYNAV_PLANNER__FILTERS__IINFLATIONFILTER_HPP_
CellData(unsigned int x, unsigned int y, unsigned int sx, unsigned int sy)
Constructor for a CellData objects.
Definition InflationFilter.hpp:74
unsigned int y_
Definition InflationFilter.hpp:78
unsigned int x_
Definition InflationFilter.hpp:78
unsigned int src_x_
Definition InflationFilter.hpp:79
unsigned int src_y_
Definition InflationFilter.hpp:79
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition costmap_2d.hpp:69
unsigned int cellDistance(double world_dist)
Given distance in the world... convert it to cells.
Definition costmap_2d.cpp:289
CostmapFilter()
Definition CostmapFilter.cpp:32
std::vector< std::vector< int > > distance_matrix_
Definition InflationFilter.hpp:224
unsigned int cell_inflation_radius_
Definition InflationFilter.hpp:214
bool inflate_unknown_
Definition InflationFilter.hpp:213
void updateCosts(easynav::Costmap2D &master_grid, int min_i, int min_j, int max_i, int max_j)
Update the costs in the master costmap in the window.
Definition InflationFilter.cpp:161
void enqueue(unsigned int index, unsigned int mx, unsigned int my, unsigned int src_x, unsigned int src_y)
Enqueue new cells in cache distance update search.
Definition InflationFilter.cpp:297
double cost_scaling_factor_
Definition InflationFilter.hpp:212
double distanceLookup(unsigned int mx, unsigned int my, unsigned int src_x, unsigned int src_y)
Lookup pre-computed distances.
Definition InflationFilter.hpp:160
virtual void update(NavState &nav_state)
Definition InflationFilter.cpp:102
void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y)
Update the bounds of the master costmap by this layer's update dimensions.
Definition InflationFilter.cpp:128
bool inflate_around_unknown_
Definition InflationFilter.hpp:213
unsigned char computeCost(double distance) const
Given a distance, compute a cost.
Definition InflationFilter.hpp:125
void computeCaches()
Compute cached dsitances.
Definition InflationFilter.cpp:321
double resolution_
Definition InflationFilter.hpp:218
std::vector< unsigned char > cached_costs_
Definition InflationFilter.hpp:222
void matchSize(easynav::Costmap2D &costmap)
Match the size of the master costmap.
Definition InflationFilter.cpp:119
double last_min_x_
Definition InflationFilter.hpp:226
bool matchedSize_
Definition InflationFilter.hpp:231
unsigned char costLookup(unsigned int mx, unsigned int my, unsigned int src_x, unsigned int src_y)
Lookup pre-computed costs.
Definition InflationFilter.hpp:177
double inscribed_radius_
Definition InflationFilter.hpp:212
double getInflationRadius()
Definition InflationFilter.hpp:146
double getCostScalingFactor()
Definition InflationFilter.hpp:141
unsigned int cache_length_
Definition InflationFilter.hpp:225
double inflation_radius_
Definition InflationFilter.hpp:212
std::vector< bool > seen_
Definition InflationFilter.hpp:220
virtual std::expected< void, std::string > on_initialize()
Definition InflationFilter.cpp:77
double last_max_y_
Definition InflationFilter.hpp:226
bool need_reinflation_
Definition InflationFilter.hpp:229
unsigned int cellDistance(easynav::Costmap2D &costmap, double world_dist)
Compute cached dsitances.
Definition InflationFilter.hpp:199
InflationFilter()
Definition InflationFilter.cpp:59
double last_min_y_
Definition InflationFilter.hpp:226
int generateIntegerDistances()
Compute cached dsitances.
Definition InflationFilter.cpp:355
std::vector< double > cached_distances_
Definition InflationFilter.hpp:223
unsigned int cached_cell_inflation_radius_
Definition InflationFilter.hpp:215
double last_max_x_
Definition InflationFilter.hpp:226
std::vector< std::vector< CellData > > inflation_cells_
Definition InflationFilter.hpp:216
Provides a mapping for often used cost values.
Definition cost_values.hpp:41