00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef POLAR_SCAN_MATCHING_POLAR_MATCHER_H
00036 #define POLAR_SCAN_MATCHING_POLAR_MATCHER_H
00037
00038 #include <stdio.h>
00039 #include <iostream>
00040 #include <unistd.h>
00041 #include <math.h>
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include <vector>
00045
00046 #define PM_TYPE double // change it to double for higher accuracy and lower speed
00047
00048
00049 #define PM_RANGE 1 // range reading is longer than PM_MAX_RANGE
00050 #define PM_MOVING 2 // range reading corresponds to a moving point
00051 #define PM_MIXED 4 // range reading is a mixed pixel
00052 #define PM_OCCLUDED 8 // range reading is occluded
00053 #define PM_EMPTY 16 // at that bearing there is no measurment (between 2
00054
00055
00056 #define PM_ODO -1 //show results with odometry only in mapping_with_matching()
00057 #define PM_PSM 1 //polar scanmatching - matching bearing
00058 #define PM_PSM_C 2 //polar scanmatching - using cartesian equations
00059 #define PM_ICP 3 //scanmatchign with iterative closest point
00060 #define PM_IDC 4 //lu's iterative dual correspondence - not implemented,
00061
00062 #define PM_MBICP 5 //scanmatchign with metric based ICP
00063
00064 const double PM_D2R = M_PI/180.0;
00065 const double PM_R2D = 180.0/M_PI;
00066
00067
00068
00069
00070 struct PMScan
00071 {
00072 PMScan(int nPoints)
00073 {
00074 r.resize(nPoints);
00075 x.resize(nPoints);
00076 y.resize(nPoints);
00077 bad.resize(nPoints);
00078 seg.resize(nPoints);
00079 }
00080
00081 PM_TYPE rx;
00082 PM_TYPE ry;
00083 PM_TYPE th;
00084 std::vector<PM_TYPE> r;
00085 std::vector<PM_TYPE> x;
00086 std::vector<PM_TYPE> y;
00087 std::vector<int> bad;
00088
00089
00090 std::vector<int> seg;
00091 };
00092
00093 class PolarMatcher
00094 {
00095 private:
00096
00097
00098
00099
00100
00101
00102
00103
00104 PM_TYPE pm_error_index(PMScan *lsr,PMScan *lsa);
00105
00106
00107
00108
00109 void pm_cov_est(PM_TYPE err, double *c11,double *c12, double *c22, double *c33,
00110 bool corridor=false, PM_TYPE corr_angle=0);
00111
00112 void pm_scan_project(const PMScan *act, PM_TYPE *new_r, int *new_bad);
00113 PM_TYPE pm_orientation_search(const PMScan *ref, const PM_TYPE *new_r, const int *new_bad);
00114 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);
00115
00116 PM_TYPE point_line_distance ( PM_TYPE x1, PM_TYPE y1, PM_TYPE x2, PM_TYPE y2,
00117 PM_TYPE x3, PM_TYPE y3,PM_TYPE *x, PM_TYPE *y);
00118
00119 inline PM_TYPE norm_a ( PM_TYPE a )
00120 {
00121 int m;
00122 m= ( int ) ( a/ ( 2.0*M_PI ) );
00123 a=a- ( PM_TYPE ) m*M_PI;
00124 if ( a< ( -M_PI ) )
00125 a+=2.0*M_PI;
00126 if ( a>=M_PI )
00127 a-=2.0*M_PI;
00128 return ( a );
00129 }
00130
00131 public:
00132
00133 int PM_L_POINTS;
00134
00135 PM_TYPE PM_FI_MIN;
00136 PM_TYPE PM_FI_MAX;
00137 PM_TYPE PM_DFI;
00138
00139 std::vector<PM_TYPE> pm_fi;
00140 std::vector<PM_TYPE> pm_si;
00141 std::vector<PM_TYPE> pm_co;
00142
00143 double PM_FOV ;
00144 double PM_MAX_RANGE ;
00145 int PM_MIN_VALID_POINTS;
00146 int PM_SEARCH_WINDOW;
00147
00148 double PM_TIME_DELAY;
00149
00150 double PM_MAX_ERROR;
00151 double PM_STOP_COND;
00152 int PM_MAX_ITER;
00153 int PM_MAX_ITER_ICP;
00154 int PM_STOP_COND_ICP;
00155
00156 PolarMatcher();
00157
00158 void pm_init();
00159
00160
00161
00162
00163 void pm_median_filter(PMScan *ls);
00164
00165
00166 void pm_find_far_points(PMScan *ls);
00167
00168
00169 void pm_segment_scan(PMScan *ls);
00170
00171
00172
00173
00174 PM_TYPE pm_psm(PMScan *lsr,PMScan *lsa);
00175
00176
00177
00178
00179
00180 PM_TYPE pm_psm_c(PMScan *lsr,PMScan *lsa);
00181 };
00182
00183 #endif //POLAR_SCAN_MATCHING_POLAR_MATCH_H