grid_path.cpp
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  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Eitan Marder-Eppstein
36  * David V. Lu!!
37  *********************************************************************/
39 #include <algorithm>
40 #include <stdio.h>
41 namespace global_planner {
42 
43 bool GridPath::getPath(float* potential, double start_x, double start_y, double end_x, double end_y, std::vector<std::pair<float, float> >& path) {
44  std::pair<float, float> current;
45  current.first = end_x;
46  current.second = end_y;
47 
48  int start_index = getIndex(start_x, start_y);
49 
50  path.push_back(current);
51  int c = 0;
52  int ns = xs_ * ys_;
53 
54  while (getIndex(current.first, current.second) != start_index) {
55  float min_val = 1e10;
56  int min_x = 0, min_y = 0;
57  for (int xd = -1; xd <= 1; xd++) {
58  for (int yd = -1; yd <= 1; yd++) {
59  if (xd == 0 && yd == 0)
60  continue;
61  int x = current.first + xd, y = current.second + yd;
62  int index = getIndex(x, y);
63  if (potential[index] < min_val) {
64  min_val = potential[index];
65  min_x = x;
66  min_y = y;
67  }
68  }
69  }
70  if (min_x == 0 && min_y == 0)
71  return false;
72  current.first = min_x;
73  current.second = min_y;
74  path.push_back(current);
75 
76  if(c++>ns*4){
77  return false;
78  }
79 
80  }
81  return true;
82 }
83 
84 } //end namespace global_planner
85 
bool getPath(float *potential, double start_x, double start_y, double end_x, double end_y, std::vector< std::pair< float, float > > &path)
Definition: grid_path.cpp:43
TFSIMD_FORCE_INLINE const tfScalar & y() const
int getIndex(int x, int y)
Definition: traceback.h:54
TFSIMD_FORCE_INLINE const tfScalar & x() const


global_planner
Author(s): David Lu!!
autogenerated on Thu Jan 21 2021 04:06:07