polar_match.h
Go to the documentation of this file.
1 /***************************************************************************
2  polar_match.h - matching laser scans in polar coord system
3  designed for use with SICK LMS in cm res./361 meas. mode
4  only 181 readings (1 deg res) are used (less accuracy but higher
5  speed)
6  -------------------
7  begin : Tue Nov 9 2004
8  version : 0.2
9  copyright : (C) 2005 by Albert Diosi and Lindsay Kleeman
10  email : albert.diosi@gmail.com
11  comments : range units are cm; angle units are deg
12  the laser is on the robots y axis
13  - in scan projections, occluded ref scanpoints aren't removed!
14  changed:
15  14/03/2005 removing of unnecessary code
16  ***************************************************************************/
17  /****************************************************************************
18  This file is part of polar_matching.
19 
20  polar_matching is free software; you can redistribute it and/or modify
21  it under the terms of the GNU General Public License as published by
22  the Free Software Foundation; either version 2 of the License, or
23  (at your option) any later version.
24 
25  polar_matching is distributed in the hope that it will be useful,
26  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  GNU General Public License for more details.
29 
30  You should have received a copy of the GNU General Public License
31  along with polar_matching; if not, write to the Free Software
32  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 ****************************************************************************/
34 
35 #ifndef POLAR_SCAN_MATCHING_POLAR_MATCHER_H
36 #define POLAR_SCAN_MATCHING_POLAR_MATCHER_H
37 
38 #include <stdio.h>
39 #include <iostream>
40 #include <unistd.h>
41 #include <math.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <vector>
45 
46 #define PM_TYPE double // change it to double for higher accuracy and lower speed
47 
48 // range reading errors
49 #define PM_RANGE 1 // range reading is longer than PM_MAX_RANGE
50 #define PM_MOVING 2 // range reading corresponds to a moving point
51 #define PM_MIXED 4 // range reading is a mixed pixel
52 #define PM_OCCLUDED 8 // range reading is occluded
53 #define PM_EMPTY 16 // at that bearing there is no measurment (between 2
54  // segments there is no interpolation!)
55 
56 #define PM_ODO -1 //show results with odometry only in mapping_with_matching()
57 #define PM_PSM 1 //polar scanmatching - matching bearing
58 #define PM_PSM_C 2 //polar scanmatching - using cartesian equations
59 #define PM_ICP 3 //scanmatchign with iterative closest point
60 #define PM_IDC 4 //lu's iterative dual correspondence - not implemented,
61  //Guttman's external code is used for comparisson
62 #define PM_MBICP 5 //scanmatchign with metric based ICP
63 
64 const double PM_D2R = M_PI/180.0; // degrees to rad
65 const double PM_R2D = 180.0/M_PI; // rad to degrees
66 
67 //const int PM_L_POINTS = 681;
68 
69 //might want to consider doubles for rx,ry -> in a large environment?
70 struct PMScan
71 {
72  PMScan(int nPoints)
73  {
74  r.resize(nPoints);
75  x.resize(nPoints);
76  y.resize(nPoints);
77  bad.resize(nPoints);
78  seg.resize(nPoints);
79  }
80 
81  PM_TYPE rx; //robot odometry pos
82  PM_TYPE ry; //robot odometry pos
83  PM_TYPE th; //robot orientation
84  std::vector<PM_TYPE> r;//[cm] - 0 or negative ranges denote invalid readings.
85  std::vector<PM_TYPE> x;//[cm]
86  std::vector<PM_TYPE> y;//[cm]
87  std::vector<int> bad;// 0 if OK
88  //sources of invalidity - too big range;
89  //moving object; occluded;mixed pixel
90  std::vector<int> seg;//nuber describing into which segment the point belongs to
91 };
92 
94 {
95  private:
96 
97  //calculates an error index expressing the quality of the match
98  //of the actual scan to the reference scan
99  //has to be called after scan matching so the actual scan in expressed
100  //in the reference scan coordinate system
101  //return the average minimum Euclidean distance; MAXIMUM RANGE points
102  //are not considered; number of non maximum range points have to be
103  //smaller than a threshold
104  PM_TYPE pm_error_index(PMScan *lsr,PMScan *lsa);
105 
106  //estimates the covariance matrix(c11,c12,c22,c33) (x,y,th) of
107  //a scan match based on an error index (err-depends on how good the
108  //match is), and the angle of the corridor if it is a corridor
109  void pm_cov_est(PM_TYPE err, double *c11,double *c12, double *c22, double *c33,
110  bool corridor=false, PM_TYPE corr_angle=0);
111 
112  void pm_scan_project(const PMScan *act, PM_TYPE *new_r, int *new_bad);
113  PM_TYPE pm_orientation_search(const PMScan *ref, const PM_TYPE *new_r, const int *new_bad);
114  PM_TYPE pm_translation_estimation(const PMScan *ref, const PM_TYPE *new_r, const int *new_bad, PM_TYPE C, PM_TYPE *dx, PM_TYPE *dy);
115 
116  PM_TYPE point_line_distance ( PM_TYPE x1, PM_TYPE y1, PM_TYPE x2, PM_TYPE y2,
117  PM_TYPE x3, PM_TYPE y3,PM_TYPE *x, PM_TYPE *y);
118 
119  inline PM_TYPE norm_a ( PM_TYPE a )
120  {
121  int m;
122  m= ( int ) ( a/ ( 2.0*M_PI ) );
123  a=a- ( PM_TYPE ) m*M_PI;
124  if ( a< ( -M_PI ) )
125  a+=2.0*M_PI;
126  if ( a>=M_PI )
127  a-=2.0*M_PI;
128  return ( a );
129  }
130 
131  public:
132 
134 
135  PM_TYPE PM_FI_MIN;// = M_PI/2.0 - PM_FOV*PM_D2R/2.0;//[rad] bearing from which laser scans start
136  PM_TYPE PM_FI_MAX;// = M_PI/2.0 + PM_FOV*PM_D2R/2.0;//[rad] bearing at which laser scans end
137  PM_TYPE PM_DFI; // = PM_FOV*PM_D2R/ ( PM_L_POINTS + 1.0 );//[rad] angular resolution of laser scans
138 
139  std::vector<PM_TYPE> pm_fi;//contains precomputed angles
140  std::vector<PM_TYPE> pm_si;//contains sinus of angles
141  std::vector<PM_TYPE> pm_co;//contains cos of angles
142 
143  double PM_FOV ;
144  double PM_MAX_RANGE ;
147 
148  double PM_TIME_DELAY;
149 
150  double PM_MAX_ERROR; //[cm] max distance between associated points used in pose est.
151  double PM_STOP_COND;
155 
156  PolarMatcher();
157 
158  void pm_init();
159 
160  //filters the ranges with a median filter. x,y points are not upadted
161  //ls - laser scan; the job of the median filter is to remove chair and table
162  //legs wich would be moving anyway;
163  void pm_median_filter(PMScan *ls);
164 
165  // marks point further than a given distance PM_MAX_RANGE as PM_RANGE
166  void pm_find_far_points(PMScan *ls);
167 
168  //segments scanpoints into groups based on range discontinuities
169  void pm_segment_scan(PMScan *ls);
170 
171  // minimizes least square error through changing lsa->rx, lsa->ry,lsa->th
172  // this looks for angle too, like pm_linearized_match_proper,execept it
173  // fits a parabola to the error when searching for the angle and interpolates.
174  PM_TYPE pm_psm(PMScan *lsr,PMScan *lsa);
175 
176  // does scan matching using the equations for translation and orietation
177  //estimation as in Lu & milios, however our matching bearing association rule
178  //is used together with our association filter.
179  //this is PSM-C in the tech report
180  PM_TYPE pm_psm_c(PMScan *lsr,PMScan *lsa);
181 };
182 
183 #endif //POLAR_SCAN_MATCHING_POLAR_MATCH_H
int PM_MAX_ITER
stopping condition; the pose change has to be smaller than ...
Definition: polar_match.h:152
double PM_FOV
Definition: polar_match.h:143
std::vector< int > bad
Definition: polar_match.h:87
std::vector< PM_TYPE > pm_fi
Definition: polar_match.h:139
PM_TYPE PM_DFI
Definition: polar_match.h:137
double PM_STOP_COND
Definition: polar_match.h:151
const double PM_R2D
Definition: polar_match.h:65
int PM_STOP_COND_ICP
maximum number of iterations for ICP,MBICP
Definition: polar_match.h:154
std::vector< int > seg
Definition: polar_match.h:90
PM_TYPE ry
Definition: polar_match.h:82
std::vector< PM_TYPE > x
Definition: polar_match.h:85
const double PM_D2R
Definition: polar_match.h:64
int PM_SEARCH_WINDOW
minimum number of valid points for scanmatching
Definition: polar_match.h:146
std::vector< PM_TYPE > r
Definition: polar_match.h:84
std::vector< PM_TYPE > y
Definition: polar_match.h:86
double PM_TIME_DELAY
half window size which is searched for correct orientation
Definition: polar_match.h:148
PM_TYPE norm_a(PM_TYPE a)
Definition: polar_match.h:119
double PM_MAX_ERROR
Definition: polar_match.h:150
std::vector< PM_TYPE > pm_si
Definition: polar_match.h:140
PM_TYPE rx
Definition: polar_match.h:81
PM_TYPE th
Definition: polar_match.h:83
int PM_MAX_ITER_ICP
maximum number of iterations for PSM.PSM_C
Definition: polar_match.h:153
double PM_MAX_RANGE
field of view of the laser range finder in degrees
Definition: polar_match.h:144
#define PM_TYPE
Definition: polar_match.h:46
int PM_MIN_VALID_POINTS
[cm] max valid laser range (set this to about 400 for the Hokuyo URG)
Definition: polar_match.h:145
std::vector< PM_TYPE > pm_co
Definition: polar_match.h:141
PMScan(int nPoints)
Definition: polar_match.h:72
PM_TYPE PM_FI_MAX
Definition: polar_match.h:136
PM_TYPE PM_FI_MIN
Definition: polar_match.h:135


polar_scan_matcher
Author(s): Ivan Dryanovski
autogenerated on Mon Jun 10 2019 15:08:51