00001 #ifndef LOCALIZER_H
00002 #define LOCALIZER_H
00003
00004
00005
00006 #include <types.h>
00007 #include <utility/fixedpoint.h>
00008 #include <pose_chain.h>
00009 #include <point.h>
00010 #include <ir_base.h>
00011 #include <range_sensor_ids.h>
00012
00013 #define MAXIMUM_LOCALIZER_WALLS 5
00014
00015
00043
00044 #define MINIMUM_HYPOTHESIS_THRESHOLD 1
00045
00046 #define BASE_FLOAT_TYPE FIXED_POINT
00047
00048 #define RADIAN_TYPE BASE_FLOAT_TYPE
00049 #define DEGREE_TYPE BASE_FLOAT_TYPE
00050 #define DISTANCE_TYPE BASE_FLOAT_TYPE
00051
00052
00053
00054 #define fpSSS(_S1,_S2,_S3) (fpdiv(( fpmul(_S1,_S1) + fpmul(_S2,_S2) - fpmul(_S3,_S3)),(fpmul(FIXED_TWO,fpmul(_S1,_S2))) ))
00055 #define fpSAS(_S1,_A,_S2) (fpmul(_S1,_S1) + fpmul(_S2,_S2) - fpmul( fpmul(FIXED_TWO,fpmul(_S1,_S2)), fpcos(_A) ))
00056
00057 #define dpSSS(_S1,_S2,_S3) ( (_S1*_S1 + _S2*_S2 - _S3*_S3)/(2.0*_S1*_S2) )
00058
00059 #define dpSAS(_S1,_A,_S2) (_S1*_S1 + _S2*_S2 - 2.0*_S1*_S2*cos(_A) )
00060
00061 FIXED_POINT FPangle(point, point);
00062 FIXED_POINT FPdistance(point,point);
00063 FIXED_POINT FPslope(point, point);
00064 int FPintersection(point& I, const point& p0, FIXED_POINT M0, const point& p1,const point& p2);
00065 FIXED_POINT FPrise(point, point);
00066 FIXED_POINT FPrun(point, point);
00067
00068 #ifdef DOS
00069
00070 double DPslope(DPpoint, DPpoint);
00071 double DPangle(DPpoint a, DPpoint b);
00072 double DPdistance(DPpoint p1,DPpoint p2);
00073 int DPintersection(DPpoint& I, const DPpoint& p0, double M0, const DPpoint& p1,const DPpoint& p2);
00074
00075 double DPangle(point, point);
00076 double DPdistance(point,point);
00077 double DPslope(point, point);
00078 double DPrise(point, point);
00079 double DPrun(point, point);
00080 #endif
00081
00082
00083
00084
00085
00086
00087
00089
00095 class Linear_Obstacle_T
00096 {
00097 public:
00098 Linear_Obstacle_T(void);
00099 point p1;
00100 point p2;
00101 };
00103 class Linear_Obstacle
00104 {
00105 public:
00106 Linear_Obstacle(void);
00107 Linear_Obstacle_T o[MAXIMUM_LOCALIZER_WALLS];
00109
00110 int top;
00111 };
00112
00114
00124 struct Localizer
00125 {
00126 public:
00127 Localizer(void);
00129 void wall_extract(void);
00131 void WSwrite(void);
00133
00139 void localizer_event(RANGE_SENSOR rid, IR_base* const ir);
00140 #ifdef DOS
00141 void generate_statistics(void);
00142 #endif
00143 protected:
00145 bool point_within_map(const Linear_Obstacle_T& lo, int x, int y);
00147 bool good_intersection(point p0, const Linear_Obstacle_T&);
00149
00152 void find_bounds(point p1, point p2, point& Pmin, point& Pmax);
00153 #ifdef DOS
00154
00155 bool DPSensorEvent(double& Newsigma, const DPpoint& PIsigma, const Linear_Obstacle_T& lo,double Th, double& Siota, bool simple);
00156 bool DPSetup(const DPpoint& p0, const Linear_Obstacle_T& lo, double& d0, double& RL, double M0, double M1);
00157 #else
00158 bool FPSensorEvent(FIXED_POINT&, const point& p0, const Linear_Obstacle_T& lo, FIXED_POINT Th, FIXED_POINT rs, bool simple);
00159 void FPSetup(const point& p0, const Linear_Obstacle_T& lo, FIXED_POINT& , FIXED_POINT& RL, FIXED_POINT M0, FIXED_POINT M1);
00160
00161 #endif
00162
00163
00168 void generic_localizer_event(sensor_base* ir, short ir_value, bool simple);
00169
00170 bool valid_wall(DIRECTORY_OPCODE, Linear_Obstacle_T& LO);
00171 enum WALL_SLANT_TYPE { UNDETERMINED_SLANT, SLANT_E, SLANT_NE, SLANT_N, SLANT_NW, SLANT_W, MAX_SLANT };
00172 enum WALL_INSPECTION_TYPE { UNINSPECTED, INSPECTED, ENDPOINT, PART_OF_LINE};
00174 pose_chain _sensors;
00175
00176 Linear_Obstacle walls;
00178
00183 short sign;
00184 private:
00185 #ifdef DOS
00186 bool find_wall(const Linear_Obstacle_T& LO, DPpoint PIsigma, double Siota, double sigma);
00187 #else
00188 bool find_wall(const Linear_Obstacle_T& LO, point PIsigma, FIXED_POINT Siota, FIXED_POINT sigma);
00189 #endif
00190 bool _non_intersecting;
00191 void it(uint8* wg, Linear_Obstacle_T& lo,short x,short y);
00192 bool obstacle_extraction1(uint8* wg, Linear_Obstacle_T& lo, uint8& slant, short cx,short cy,short& nx, short& ny);
00194 point PSO;
00195 #ifdef DOS
00196
00197 double Post_Processing(sensor_base* ir, const Linear_Obstacle_T& lo, double&, int Siota);
00198 DPpoint PIsigma;
00199 DPpoint Pi;
00200 DPpoint Pr;
00201 DPpoint PIiota;
00202 double sigma;
00203 double Ssigma;
00204 #else
00205 FIXED_POINT FPPost_Processing(sensor_base* ir, const Linear_Obstacle_T& lo, FIXED_POINT&, int Siota);
00206 point PIsigma;
00207 point Pi;
00208 point Pr;
00209 point PIiota;
00210 FIXED_POINT Ssigma;
00211 FIXED_POINT sigma;
00212 #endif
00213 point Pmin, Pmax;
00214 RANGE_SENSOR _current_ir;
00215 #ifdef DOS
00216 short disp_list[1000];
00217 float orient_list[1000];
00218 int _episode_number;
00219 #endif
00220 };
00221
00222 #endif