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
00030
00034
00035
00036 #ifndef __GRID_H_
00037 #define __GRID_H_
00038
00039 #ifdef MIP_HOST_APPLE
00040 #include <applePatch.h>)
00041 #endif
00042
00043
00044 #include <stdio.h>
00045 #include <fcntl.h>
00046 #include <unistd.h>
00047 #include <string.h>
00048 #include <stdlib.h>
00049 #include <signal.h>
00050 #include <assert.h>
00051
00052 #include <iostream>
00053 #include <utility>
00054
00055 #include <fstream>
00056 #include <iostream>
00057
00058 #include <vector>
00059 #include <Spaces.h>
00060 #include <assert.h>
00061 #include <math.h>
00062 #include <Scan.h>
00063 #include <algorithm>
00064
00065 #include <Types.h>
00066 #include <LogTrace.h>
00067
00068 using namespace std;
00069
00071
00072
00073 enum CellPerceptionType{
00074 OBSTACLE_CELL,
00075 FRONTIER_CELL,
00076 LRR_CELL,
00077 LSR_CELL,
00078 UNKNOWN_CELL,
00079 CELL_PERC_TYPE_NUM
00080 };
00081
00082 static const char* CellPerceptionTypeName[CELL_PERC_TYPE_NUM] ={
00083 "Obstacle Cell",
00084 "Frontier Cell",
00085 "LRR Cell",
00086 "LSR Cell",
00087 "Unknown Cell"
00088 };
00089
00090
00091 namespace MipBaselib {
00092
00097 class ExplorationParams{
00098 private:
00099 Decimal _range;
00100 Decimal _coneAmplitude;
00101 Decimal _scanAngle;
00102 int _samples;
00103 const char* _logPath;
00104
00105 public:
00106 ofstream _logFile;
00107
00109 ExplorationParams();
00110
00112 ExplorationParams(Decimal range,Decimal scanAngle, int samples, Decimal coneAmplitude);
00113
00115 ~ExplorationParams();
00116
00118 ExplorationParams(const ExplorationParams& p);
00119
00121 ExplorationParams operator=(const ExplorationParams& p);
00122
00123
00124
00126 Decimal range();
00127
00129 Decimal coneAmplitude();
00130
00132 Decimal scanAngle();
00133
00135 int samples();
00136
00138 string print();
00139
00141 void log();
00142
00143
00144
00146 void setRange(Decimal value);
00147
00149 void setConeAmplitude(Decimal value);
00150
00152 void setScanAngle(Decimal value);
00153
00155 void setSamples(int value);
00156
00158 void setLogPath(const char* value);
00159 };
00160
00167 class Cell{
00168 private:
00169 Position _point;
00170 Position _reading;
00171 DubInt _indexes;
00172 int _vectorIndex;
00173
00174 Decimal _side;
00175 Decimal _distVP;
00176 int _distLSRBound;
00177
00178 unsigned int _cone;
00179 unsigned int _frame;
00180
00181 vector<Cell*> _neighbours;
00182
00183 bool _isLRR;
00184 bool _isFrontier;
00185 bool _isLSR;
00186 bool _isPrevExpl;
00187 bool _isObstacle;
00188 bool _isBoundary;
00189 bool _isLRRBoundary;
00190 bool _isUnknown;
00191 bool _isLabelA;
00192 bool _isLabelB;
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 bool _integrity();
00207
00208 public:
00209 vector<int> perceptionCounter;
00210
00212 Cell();
00213
00215 Cell(Decimal);
00216
00218 ~Cell();
00219
00221 Cell(const Cell& c);
00222
00224 Cell& operator=(const Cell& c);
00225
00226
00227
00229 void setPoint(Position value);
00230
00232 void setReading(Position value);
00233
00235 void setIndexes(DubInt value);
00236
00238 void setVectorIndex(int value);
00239
00241 void setSide(Decimal value);
00242
00244 void setNeighbours(vector<Cell*> value);
00245
00247 void neighPushBack(Cell* value);
00248
00250 void setIsLRR();
00251
00253 void setIsFrontier();
00254
00256 void setIsLSR();
00257
00259 void setIsPrevExpl();
00260
00262 void setIsObstacle();
00263
00265 void setIsUnknown();
00266
00268 void setIsBoundary();
00269
00271 void setIsLRRBoundary();
00272
00274 void setIsLabelA();
00275
00277 void setIsLabelB();
00278
00280 void setCone (unsigned int value);
00281
00283 void setFrame (unsigned int value);
00284
00286 void setDistVP(Decimal value);
00287
00289 void setDistLSRBound(int value);
00290
00292 void unsetIsLRR();
00293
00295 void unsetIsFrontier();
00296
00298 void unsetIsLSR();
00299
00301 void unsetIsPrevExpl();
00302
00304 void unsetIsObstacle();
00305
00307 void unsetIsUnknown();
00308
00310 void unsetIsBoundary();
00311
00313 void unsetIsLRRBoundary();
00314
00316 void unsetIsLabelA();
00317
00319 void unsetIsLabelB();
00320
00322 void unsetAllFlags();
00323
00325 void copyAllFlags(Cell cell);
00326
00327
00328
00330 Position point();
00331
00333 Position reading();
00334
00336 DubInt indexes();
00337
00339 int vectorIndex();
00340
00342 Decimal side();
00343
00345 vector<Cell*> neighbours();
00346
00348 bool isLRR();
00349
00351 bool isFrontier();
00352
00354 bool isLSR();
00355
00357 bool isPrevExpl();
00358
00360 bool isObstacle();
00361
00363 bool isUnknown();
00364
00366 bool isBoundary();
00367
00369 bool isLRRBoundary();
00370
00372 bool isLabelA();
00373
00375 bool isLabelB();
00376
00378 bool integrity();
00379
00381 unsigned int cone();
00382
00384 unsigned int frame();
00385
00387 Decimal distVP();
00388
00390 int distLSRBound();
00391
00395 void merge(Cell& otherCell);
00396
00398 string printFlags();
00399 };
00400
00401
00402 typedef vector<DubInt> LSR;
00403 typedef vector<DubInt> LSRBound;
00404
00405 typedef vector<DubInt> LRR;
00406 typedef vector<DubInt> LRRBound;
00407
00408
00414 class FrontierArc{
00415 private:
00416 bool _isRangeEdge;
00417 vector<DubInt> _vec;
00418
00419 public:
00421 FrontierArc();
00422
00424 FrontierArc(const FrontierArc& arc);
00425
00427 FrontierArc operator=(const FrontierArc& arc);
00428
00430 DubInt operator[](size_t index) const;
00431
00433 vector<DubInt>::iterator begin();
00434
00436 vector<DubInt>::iterator end();
00437
00439 void push_back(DubInt cell);
00440
00442 void pop_back();
00443
00445 void insert(vector<DubInt>::iterator pos, DubInt value);
00446
00448 void insert(vector<DubInt>::iterator pos, vector<DubInt>::iterator begin, vector<DubInt>::iterator end );
00449
00451 vector<DubInt>::iterator erase (vector<DubInt>::iterator position );
00452
00454 vector<DubInt> vec();
00455
00457 int size();
00458
00460 void setIsRangeEdge();
00461
00463 void unsetIsRangeEdge();
00464
00466 bool isRangeEdge();
00467
00469 string print();
00470 };
00471
00472
00473
00477 class Frontier:public vector<FrontierArc>,MIPObject{
00478 private:
00479 public:
00481 Frontier():vector< FrontierArc >(){}
00482
00485 Frontier(vector< vector<Position> > frontier);
00486
00488 ~Frontier();
00489
00492 string getObjectName() const {
00493 return "Frontier";
00494 }
00495
00498 void toVectVectPosition(vector< vector< Position > > & vectPos);
00499
00502 vector < vector < Position > > toVectVectPosition();
00503 };
00504
00505
00511 class Grid {
00512 private:
00513
00515 bool _isContiguos(DubInt cell1, DubInt cell2);
00516 public:
00517 ExplorationParams _params;
00518 Scan _currScan;
00519 Decimal _resolution;
00520 Decimal _width;
00521 Decimal _height;
00522 Decimal _distForInvalid;
00523 unsigned int _columns;
00524 unsigned int _rows;
00525 Pose _center;
00526 Cell* _centralCell;
00527 Position _LLC;
00528 Position _RLC;
00529 Position _LUC;
00530 Position _RUC;
00531
00532 vector<Cell> _board;
00533
00534 LSR _lsr;
00535 LSRBound _lsrBound;
00536 LRR _lrr;
00537 LRRBound _lrrBound;
00538 Frontier _frontier;
00539 LSRBound _originalFront;
00540 LSRBound _tempBound;
00541
00543 Grid();
00544
00546 Grid(ExplorationParams params, Scan currScan, Pose center);
00547
00549 Grid(ExplorationParams params, Scan currScan, Pose center, Decimal width, Decimal height, Decimal distForInvalid = 0.3);
00550
00552 Grid(const Grid& g);
00553
00555 Grid operator=(const Grid& g);
00556
00558 ~Grid();
00559
00560
00562 vector<Cell*> findFrameCells(int frame);
00563
00565 vector<Cell*> bresenham(Cell* startCell, Cell* stopCell);
00566
00568 void defineLSR();
00569
00571 void defineLSRBoundary( int iMinArcSize = 3, int iMinRadialSize = 1, bool bIncludeObstacleEndPoints = false );
00572
00574 void defineFrontier();
00575
00577 void defineLRR();
00578
00582 unsigned int compCol(Decimal wid, Decimal res);
00583
00587 unsigned int compRow(Decimal hei, Decimal res);
00588
00590 void defineBoard( int iMinArcSize = 3, int iMinRadialSize = 1, bool bIncludeObstacleEndPoints = false );
00591
00593 void updateLSR();
00594
00596 void updateFrontier();
00597
00599 bool initializeScan(ExplorationParams params, Scan &currScan);
00600
00601
00602
00604 void setParams(ExplorationParams value);
00605
00608 void setResolution(Decimal value);
00609
00612 void setWidth(Decimal value);
00613
00616 void setHeight(Decimal value);
00617
00620 void setColumns(int value);
00621
00624 void setRows(int value);
00625
00628 void setCenter(Pose value);
00629
00632 void setCentralCell(Cell* value);
00633
00636 void setLLC(Position value);
00637
00640 void setRLC(Position value);
00641
00644 void setLUC(Position value);
00645
00648 void setRUC(Position value);
00649
00650
00651
00653 Frontier frontier();
00654
00656 LSRBound lsrBound();
00657
00659 LSR lsr();
00660
00662 LRR lrr();
00663
00670 void getExpectedScan(Scan& expScan, Pose pose, Decimal range, unsigned int samples, Angle angWidth);
00671
00673 ExplorationParams params();
00674
00676 Decimal resolution();
00677
00679 Decimal width();
00680
00682 Decimal height();
00683
00685 int columns();
00686
00688 int rows();
00689
00691 Pose center();
00692
00694 Cell* centralCell();
00695
00697 Position LLC();
00698
00700 Position RLC();
00701
00703 Position LUC();
00704
00706 Position RUC();
00707
00709 Cell* getCell(int index);
00710
00712 Cell* getCell (int i, int j);
00713
00715 Cell* getCell (DubInt indexes);
00716
00718 Cell* getCell(Position pos);
00719
00721 Cell* getCellOnGlobal (DubInt indexes,int minI,int minJ);
00722
00724 Cell* getCellOnGlobal (Position pos,int minI,int minJ, Position globalCenter);
00725
00727 string print(Cell cell);
00728
00730 void log(Cell cell);
00731
00733 string print();
00734
00736 void log();
00737
00739 Position alligne(Position pos);
00740
00742 void addScan(Scan& scan, Pose scanPose);
00743 };
00744
00745
00750 class ProbCell : public Cell {
00751
00752 private:
00753
00754 Decimal _logProbOfObstacle;
00755
00756 public:
00757
00758 ProbCell();
00759 ProbCell(Decimal newProbOfObstacle);
00760 ~ProbCell();
00761
00762 void setProbOfObstacle( Decimal newProbOfObstacle );
00763
00764 Decimal getProbOfObstacle( );
00765
00766 void setLogProbOfObstacle( Decimal newLogProbOfObstacle );
00767
00768 Decimal getLogProbOfObstacle( );
00769
00770 void changeLogProbOfObstacle( Decimal deltaLogProbOfObstacle );
00771 };
00772
00773
00778 class ProbGrid : public Grid {
00779
00780 private:
00781 static const Decimal LOG_OCCUPIED;
00782 static const Decimal LOG_FREE;
00783
00784 public:
00785
00786 vector<ProbCell> _probBoard;
00787
00788 ProbGrid();
00789
00791 ProbGrid(ExplorationParams params, Scan currScan, Pose center, Decimal width, Decimal height, Decimal distForInvalid = 0.3);
00792
00793 ~ProbGrid();
00794
00796 void addScan(Scan& scan, Pose &scanPose);
00797
00799 Pose pickBestScanPose( );
00800
00802 bool isGridSettled( );
00803
00805 void defineProbBoard( );
00806
00807 ProbCell* getProbCell(Position pos);
00808
00809 vector<ProbCell*> bresenham(ProbCell* startCell, ProbCell* stopCell);
00810 };
00811
00812
00813
00814 };
00815
00816 #endif
00817
00818
00819