Apollo 11.0
自动驾驶开放平台
apollo::planning::GridSearch类 参考

#include <grid_search.h>

apollo::planning::GridSearch 的协作图:

Public 成员函数

 GridSearch (const PlannerOpenSpaceConfig &open_space_conf)
 
virtual ~GridSearch ()=default
 
bool GenerateAStarPath (const double sx, const double sy, const double ex, const double ey, const std::vector< double > &XYbounds, const std::vector< std::vector< common::math::LineSegment2d > > &obstacles_linesegments_vec, GridAStartResult *result)
 
bool GenerateDpMap (const double ex, const double ey, const std::vector< double > &XYbounds, const std::vector< std::vector< common::math::LineSegment2d > > &obstacles_linesegments_vec, const std::vector< std::vector< common::math::LineSegment2d > > &soft_boundary_linesegments_vec={{}})
 
double CheckDpMap (const double sx, const double sy)
 
 GridSearch (const WarmStartConfig &warm_start_conf)
 
double GetObstacleDistance (const double x, const double y)
 

详细描述

在文件 grid_search.h 第 132 行定义.

构造及析构函数说明

◆ GridSearch() [1/2]

apollo::planning::GridSearch::GridSearch ( const PlannerOpenSpaceConfig &  open_space_conf)
explicit

在文件 grid_search.cc 第 28 行定义.

28 {
29 xy_grid_resolution_ = open_space_conf.warm_start_config().grid_a_star_xy_resolution();
30 node_radius_ = open_space_conf.warm_start_config().node_radius();
31}

◆ ~GridSearch()

virtual apollo::planning::GridSearch::~GridSearch ( )
virtualdefault

◆ GridSearch() [2/2]

apollo::planning::GridSearch::GridSearch ( const WarmStartConfig &  warm_start_conf)
explicit

在文件 grid_search.cc 第 33 行定义.

33 {
34 xy_grid_resolution_ = warm_start_conf.grid_a_star_xy_resolution();
35 node_radius_ = warm_start_conf.node_radius();
36 esdf_range_ = warm_start_conf.esdf_range();
37 use_esdf_ = warm_start_conf.use_esdf();
38}

成员函数说明

◆ CheckDpMap()

double apollo::planning::GridSearch::CheckDpMap ( const double  sx,
const double  sy 
)

在文件 grid_search.cc 第 267 行定义.

267 {
268 std::string index = Node2d::CalcIndex(sx, sy, xy_grid_resolution_, XYbounds_);
269 if (dp_map_.find(index) != dp_map_.end()) {
270 return dp_map_[index]->GetCost() * xy_grid_resolution_;
271 } else {
272 return std::numeric_limits<double>::infinity();
273 }
274}
static std::string CalcIndex(const double x, const double y, const double xy_resolution, const std::vector< double > &XYbounds)
Definition grid_search.h:96

◆ GenerateAStarPath()

bool apollo::planning::GridSearch::GenerateAStarPath ( const double  sx,
const double  sy,
const double  ex,
const double  ey,
const std::vector< double > &  XYbounds,
const std::vector< std::vector< common::math::LineSegment2d > > &  obstacles_linesegments_vec,
GridAStartResult *  result 
)

在文件 grid_search.cc 第 155 行定义.

162 {
163 std::priority_queue<std::pair<std::string, double>, std::vector<std::pair<std::string, double>>, cmp> open_pq;
164 std::unordered_map<std::string, std::shared_ptr<Node2d>> open_set;
165 std::unordered_map<std::string, std::shared_ptr<Node2d>> close_set;
166 XYbounds_ = XYbounds;
167 std::shared_ptr<Node2d> start_node = std::make_shared<Node2d>(sx, sy, xy_grid_resolution_, XYbounds_);
168 std::shared_ptr<Node2d> end_node = std::make_shared<Node2d>(ex, ey, xy_grid_resolution_, XYbounds_);
169 std::shared_ptr<Node2d> final_node_ = nullptr;
170 obstacles_linesegments_vec_ = obstacles_linesegments_vec;
171 open_set.emplace(start_node->GetIndex(), start_node);
172 open_pq.emplace(start_node->GetIndex(), start_node->GetCost());
173
174 // Grid a star begins
175 size_t explored_node_num = 0;
176 while (!open_pq.empty()) {
177 std::string current_id = open_pq.top().first;
178 open_pq.pop();
179 std::shared_ptr<Node2d> current_node = open_set[current_id];
180 // Check destination
181 if (*(current_node) == *(end_node)) {
182 final_node_ = current_node;
183 break;
184 }
185 close_set.emplace(current_node->GetIndex(), current_node);
186 std::vector<std::shared_ptr<Node2d>> next_nodes = std::move(GenerateNextNodes(current_node));
187 for (auto& next_node : next_nodes) {
188 if (!CheckConstraints(next_node)) {
189 continue;
190 }
191 if (close_set.find(next_node->GetIndex()) != close_set.end()) {
192 continue;
193 }
194 if (open_set.find(next_node->GetIndex()) == open_set.end()) {
195 ++explored_node_num;
196 next_node->SetHeuristic(EuclidDistance(
197 next_node->GetGridX(), next_node->GetGridY(), end_node->GetGridX(), end_node->GetGridY()));
198 next_node->SetPreNode(current_node);
199 open_set.emplace(next_node->GetIndex(), next_node);
200 open_pq.emplace(next_node->GetIndex(), next_node->GetCost());
201 }
202 }
203 }
204
205 if (final_node_ == nullptr) {
206 AERROR << "Grid A searching return null ptr(open_set ran out)";
207 return false;
208 }
209 LoadGridAStarResult(result);
210 ADEBUG << "explored node num is " << explored_node_num;
211 return true;
212}
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44

◆ GenerateDpMap()

bool apollo::planning::GridSearch::GenerateDpMap ( const double  ex,
const double  ey,
const std::vector< double > &  XYbounds,
const std::vector< std::vector< common::math::LineSegment2d > > &  obstacles_linesegments_vec,
const std::vector< std::vector< common::math::LineSegment2d > > &  soft_boundary_linesegments_vec = {{}} 
)

在文件 grid_search.cc 第 214 行定义.

219 {
220 std::priority_queue<std::pair<std::string, double>, std::vector<std::pair<std::string, double>>, cmp> open_pq;
221 std::unordered_map<std::string, std::shared_ptr<Node2d>> open_set;
222 dp_map_ = decltype(dp_map_)();
223 XYbounds_ = XYbounds;
224 // XYbounds with xmin, xmax, ymin, ymax
225 max_grid_y_ = std::round((XYbounds_[3] - XYbounds_[2]) / xy_grid_resolution_);
226 max_grid_x_ = std::round((XYbounds_[1] - XYbounds_[0]) / xy_grid_resolution_);
227 std::shared_ptr<Node2d> end_node = std::make_shared<Node2d>(ex, ey, xy_grid_resolution_, XYbounds_);
228 obstacles_linesegments_vec_ = obstacles_linesegments_vec;
229 open_set.emplace(end_node->GetIndex(), end_node);
230 open_pq.emplace(end_node->GetIndex(), end_node->GetCost());
231
232 // Grid a star begins
233 size_t explored_node_num = 0;
234 while (!open_pq.empty()) {
235 const std::string current_id = open_pq.top().first;
236 open_pq.pop();
237 std::shared_ptr<Node2d> current_node = open_set[current_id];
238 dp_map_.emplace(current_node->GetIndex(), current_node);
239 std::vector<std::shared_ptr<Node2d>> next_nodes = std::move(GenerateNextNodes(current_node));
240 for (auto& next_node : next_nodes) {
241 if (!CheckConstraints(next_node)) {
242 continue;
243 }
244 if (dp_map_.find(next_node->GetIndex()) != dp_map_.end()) {
245 continue;
246 }
247 if (open_set.find(next_node->GetIndex()) == open_set.end()) {
248 ++explored_node_num;
249 next_node->SetPreNode(current_node);
250 open_set.emplace(next_node->GetIndex(), next_node);
251 open_pq.emplace(next_node->GetIndex(), next_node->GetCost());
252 } else {
253 if (open_set[next_node->GetIndex()]->GetCost() > next_node->GetCost()) {
254 open_set[next_node->GetIndex()]->SetCost(next_node->GetCost());
255 open_set[next_node->GetIndex()]->SetPreNode(current_node);
256 }
257 }
258 }
259 }
260 if (use_esdf_) {
261 AddSoftCost(soft_boundary_linesegments_vec);
262 }
263 ADEBUG << "explored node num is " << explored_node_num;
264 return true;
265}

◆ GetObstacleDistance()

double apollo::planning::GridSearch::GetObstacleDistance ( const double  x,
const double  y 
)

在文件 grid_search.cc 第 276 行定义.

276 {
277 std::string index = Node2d::CalcIndex(x, y, xy_grid_resolution_, XYbounds_);
278 if (dp_map_.find(index) != dp_map_.end()) {
279 return dp_map_[index]->GetDistanceToObstacle();
280 } else {
281 return 0.0;
282 }
283}

该类的文档由以下文件生成: