point_grid_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2008, 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 the Willow Garage 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 *********************************************************************/
37 
39 #include <ros/console.h>
40 #ifdef HAVE_SYS_TIME_H
41 #include <sys/time.h>
42 #endif
43 
44 #include <math.h>
45 #include <cstdio>
47 
48 using namespace std;
49 using namespace costmap_2d;
50 
51 void printPoint(const geometry_msgs::Point& pt){
52  printf("(%.2f, %.2f, %.2f)", pt.x, pt.y, pt.z);
53 }
54 
56  printf("%%!PS\n");
57  printf("%%%%Creator: Eitan Marder-Eppstein (Willow Garage)\n");
58  printf("%%%%EndComments\n");
59 }
60 
62  printf("showpage\n%%%%EOF\n");
63 }
64 
65 void printPolygonPS(const std::vector<geometry_msgs::Point32>& poly, double line_width){
66  if(poly.size() < 2)
67  return;
68 
69  printf("%.2f setlinewidth\n", line_width);
70  printf("newpath\n");
71  printf("%.4f\t%.4f\tmoveto\n", poly[0].x * 10, poly[0].y * 10);
72  for(unsigned int i = 1; i < poly.size(); ++i)
73  printf("%.4f\t%.4f\tlineto\n", poly[i].x * 10, poly[i].y * 10);
74  printf("%.4f\t%.4f\tlineto\n", poly[0].x * 10, poly[0].y * 10);
75  printf("closepath stroke\n");
76 
77 }
78 
79 using namespace base_local_planner;
80 
81 int main(int argc, char** argv){
82  geometry_msgs::Point origin;
83  origin.x = 0.0;
84  origin.y = 0.0;
85  PointGrid pg(50.0, 50.0, 0.2, origin, 2.0, 3.0, 0.0);
86  /*
87  double x = 10.0;
88  double y = 10.0;
89  for(int i = 0; i < 100; ++i){
90  for(int j = 0; j < 100; ++j){
91  pcl::PointXYZ pt;
92  pt.x = x;
93  pt.y = y;
94  pt.z = 1.0;
95  pg.insert(pt);
96  x += .03;
97  }
98  y += .03;
99  x = 10.0;
100  }
101  */
102  std::vector<geometry_msgs::Point> footprint, footprint2, footprint3;
103  geometry_msgs::Point pt;
104 
105  pt.x = 1.0;
106  pt.y = 1.0;
107  footprint.push_back(pt);
108 
109  pt.x = 1.0;
110  pt.y = 1.65;
111  footprint.push_back(pt);
112 
113  pt.x = 1.325;
114  pt.y = 1.75;
115  footprint.push_back(pt);
116 
117  pt.x = 1.65;
118  pt.y = 1.65;
119  footprint.push_back(pt);
120 
121  pt.x = 1.65;
122  pt.y = 1.0;
123  footprint.push_back(pt);
124 
125  pt.x = 1.325;
126  pt.y = 1.00;
127  footprint2.push_back(pt);
128 
129  pt.x = 1.325;
130  pt.y = 1.75;
131  footprint2.push_back(pt);
132 
133  pt.x = 1.65;
134  pt.y = 1.75;
135  footprint2.push_back(pt);
136 
137  pt.x = 1.65;
138  pt.y = 1.00;
139  footprint2.push_back(pt);
140 
141  pt.x = 0.99;
142  pt.y = 0.99;
143  footprint3.push_back(pt);
144 
145  pt.x = 0.99;
146  pt.y = 1.66;
147  footprint3.push_back(pt);
148 
149  pt.x = 1.3255;
150  pt.y = 1.85;
151  footprint3.push_back(pt);
152 
153  pt.x = 1.66;
154  pt.y = 1.66;
155  footprint3.push_back(pt);
156 
157  pt.x = 1.66;
158  pt.y = 0.99;
159  footprint3.push_back(pt);
160 
161  pt.x = 1.325;
162  pt.y = 1.325;
163 
164  geometry_msgs::Point32 point;
165  point.x = 1.2;
166  point.y = 1.2;
167  point.z = 1.0;
168 
169 #ifdef HAVE_SYS_TIME_H
170  struct timeval start, end;
171  double start_t, end_t, t_diff;
172 #endif
173 
174  printPSHeader();
175 
176 #ifdef HAVE_SYS_TIME_H
177  gettimeofday(&start, NULL);
178 #endif
179 
180  for(unsigned int i = 0; i < 2000; ++i){
181  pg.insert(point);
182  }
183 
184 #ifdef HAVE_SYS_TIME_H
185  gettimeofday(&end, NULL);
186  start_t = start.tv_sec + double(start.tv_usec) / 1e6;
187  end_t = end.tv_sec + double(end.tv_usec) / 1e6;
188  t_diff = end_t - start_t;
189  printf("%%Insertion Time: %.9f \n", t_diff);
190 #endif
191 
192  vector<Observation> obs;
193  vector<PlanarLaserScan> scan;
194 
195 #ifdef HAVE_SYS_TIME_H
196  gettimeofday(&start, NULL);
197 #endif
198  pg.updateWorld(footprint, obs, scan);
199 
200  double legal = pg.footprintCost(pt, footprint, 0.0, .95);
201  pg.updateWorld(footprint, obs, scan);
202  double legal2 = pg.footprintCost(pt, footprint, 0.0, .95);
203 
204 #ifdef HAVE_SYS_TIME_H
205  gettimeofday(&end, NULL);
206  start_t = start.tv_sec + double(start.tv_usec) / 1e6;
207  end_t = end.tv_sec + double(end.tv_usec) / 1e6;
208  t_diff = end_t - start_t;
209 
210  printf("%%Footprint calc: %.9f \n", t_diff);
211 #endif
212 
213  if(legal >= 0.0)
214  printf("%%Legal footprint %.4f, %.4f\n", legal, legal2);
215  else
216  printf("%%Illegal footprint\n");
217 
218  printPSFooter();
219 
220  return 0;
221 }
void updateWorld(const std::vector< geometry_msgs::Point > &footprint, const std::vector< costmap_2d::Observation > &observations, const std::vector< PlanarLaserScan > &laser_scans)
Inserts observations from sensors into the point grid.
Definition: point_grid.cpp:335
A class that implements the WorldModel interface to provide free-space collision checks for the traje...
Definition: point_grid.h:57
void printPolygonPS(const std::vector< geometry_msgs::Point32 > &poly, double line_width)
int main(int argc, char **argv)
void printPoint(const geometry_msgs::Point &pt)
void insert(const geometry_msgs::Point32 &pt)
Insert a point into the point grid.
Definition: point_grid.cpp:211
void printPSFooter()
void printPSHeader()
virtual double footprintCost(const geometry_msgs::Point &position, const std::vector< geometry_msgs::Point > &footprint, double inscribed_radius, double circumscribed_radius)
Checks if any points in the grid lie inside a convex footprint.
Definition: point_grid.cpp:61


base_local_planner
Author(s): Eitan Marder-Eppstein, Eric Perko, contradict@gmail.com
autogenerated on Wed Jun 22 2022 02:07:08