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 #ifndef __ENVDBUBBLE_H_
00030 #define __ENVDBUBBLE_H_
00031
00032 #include <sbpl_dynamic_planner/DiscreteSpaceTimeInformation.h>
00033 #include <sbpl_dynamic_planner/sbpl_dynamicObstacles.h>
00034
00035
00036 #define ENVDBUBBLELAT_DXYWIDTH 8
00037
00038 #define ENVDBUBBLELAT_DEFAULTOBSTHRESH 254 //see explanation of the value below
00039 #define ENVDBUBBLELAT_DEFAULTDYNOBSTHRESH 254 //see explanation of the value below
00040
00041
00042
00043
00044
00045
00046 #define ENVDBUBBLELAT_THETADIRS 16
00047
00048
00049 #define ENVDBUBBLELAT_DEFAULT_ACTIONWIDTH 5 //decrease, increase, same angle while moving plus decrease, increase angle while standing.
00050
00051 #define ENVDBUBBLELAT_COSTMULT_MTOMM 1000
00052
00053 #define CONTTIME2DISC(X, CELLSIZE) (((X)>=0)?((int)((X)/(CELLSIZE)+0.5)):((int)((X)/(CELLSIZE))-1))
00054 #define DISCTIME2CONT(X, CELLSIZE) ((X)*(CELLSIZE))
00055
00056
00057 #define FAIL 0
00058 #define SUCCESS_WITH_TIME 1
00059 #define SUCCESS_NO_TIME 2
00060
00061 typedef struct
00062 {
00063 char starttheta;
00064 char dX;
00065 char dY;
00066 int dT;
00067 char endtheta;
00068 unsigned int cost;
00069
00070
00071 vector<SBPL_4Dcell_t> intersectingcellsV;
00072
00073
00074
00075 vector<SBPL_4Dpt_t> intermptV;
00076
00077
00078
00079 vector<SBPL_4Dcell_t> interm4DcellsV;
00080 } envDBubbleLatAction_t;
00081
00082
00083 typedef struct
00084 {
00085 int stateID;
00086 int X;
00087 int Y;
00088 char Theta;
00089 int T;
00090 bool inBubble;
00091 int iteration;
00092 } envDBubbleLatHashEntry_t;
00093
00094
00095 typedef struct
00096 {
00097 int motprimID;
00098 unsigned char starttheta_c;
00099 int additionalactioncostmult;
00100 SBPL_4Dcell_t endcell;
00101
00102 vector<SBPL_4Dpt_t> intermptV;
00103 }SBPL_xythetatimebubble_mprimitive;
00104
00105
00106
00107 typedef struct
00108 {
00109
00110 int startstateid;
00111 int goalstateid;
00112
00113 bool bInitialized;
00114
00115
00116
00117
00118 }EnvDBubbleLat_t;
00119
00120
00121 typedef struct envBubbleLat_config
00122 {
00123 int EnvWidth_c;
00124 int EnvHeight_c;
00125 int StartX_c;
00126 int StartY_c;
00127 int StartTheta;
00128 int StartTime;
00129 int EndX_c;
00130 int EndY_c;
00131 int EndTheta;
00132 unsigned char** Grid2D;
00133
00134
00135
00136 unsigned char obsthresh;
00137
00138
00139
00140
00141
00142 unsigned char cost_inscribed_thresh;
00143
00144
00145
00146
00147
00148 int cost_possibly_circumscribed_thresh;
00149
00150
00151 unsigned char dynamic_obstacle_collision_cost_thresh;
00152
00153 double nominalvel_mpersecs;
00154 double timetoturn45degsinplace_secs;
00155 double cellsize_m;
00156 double timeResolution;
00157
00158 int dXY[ENVDBUBBLELAT_DXYWIDTH][2];
00159
00160 envDBubbleLatAction_t** ActionsV;
00161 vector<envDBubbleLatAction_t*>* PredActionsV;
00162
00163 int actionwidth;
00164 vector<SBPL_xythetatimebubble_mprimitive> mprimV;
00165
00166 vector<sbpl_2Dpt_t> FootprintPolygon;
00167 double robotRadius;
00168 double maxMovement;
00169 } envDBubbleLatConfig_t;
00170
00171
00172 typedef struct{
00173 SBPL_DynamicObstacle_t* obs;
00174
00175 int startt;
00176 int endt;
00177 int collision_startt;
00178 int collision_endt;
00179 vector<int> ID;
00180 } envDBubbleLat_BubbleCellObs_t;
00181
00182 typedef struct{
00183 vector<envDBubbleLat_BubbleCellObs_t> dynObs;
00184 int firstObsT;
00185 int lastObsT;
00186 } envDBubbleLat_BubbleCell_t;
00187
00188
00189
00190 class SBPL2DGridSearch;
00191
00192 class EnvDBubbleLattice : public DiscreteSpaceTimeInformation
00193 {
00194
00195 public:
00196
00197 EnvDBubbleLattice();
00198
00199 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile, const char* sDynObsFile);
00200 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile);
00201 bool InitializeEnv(const char* sEnvFile);
00202 virtual bool SetEnvParameter(const char* parameter, int value);
00203 virtual int GetEnvParameter(const char* parameter);
00204 bool InitializeMDPCfg(MDPConfig *MDPCfg);
00205 virtual int GetFromToHeuristic(int FromStateID, int ToStateID) = 0;
00206 virtual int GetGoalHeuristic(int stateID) = 0;
00207 virtual int GetStartHeuristic(int stateID) = 0;
00208 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state) = 0;
00209 virtual void SetAllPreds(CMDPSTATE* state);
00210 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV);
00211 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<int>* stateBubbles, vector<int>* bubbleCollisions);
00212
00213 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV) = 0;
00214
00215
00216 void PrintEnv_Config(FILE* fOut);
00217
00218 bool InitializeEnv(int width, int height,
00220 const unsigned char* mapdata,
00221 double startx, double starty, double starttheta, double startTime,
00222 double goalx, double goaly, double goaltheta,
00223 double goaltol_x, double goaltol_y, double goaltol_theta,
00224 const vector<sbpl_2Dpt_t> & perimeterptsV,
00225 double cellsize_m, double timeResolution,
00226 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00227 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile,
00228 vector<SBPL_DynamicObstacle_t> & dynObs);
00229 bool InitializeEnv(int width, int height,
00231 const unsigned char* mapdata,
00232 double startx, double starty, double starttheta, double startTime,
00233 double goalx, double goaly, double goaltheta,
00234 double goaltol_x, double goaltol_y, double goaltol_theta,
00235 const vector<sbpl_2Dpt_t> & perimeterptsV,
00236 double cellsize_m, double timeResolution,
00237 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00238 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile);
00239 bool UpdateCost(int x, int y, unsigned char newcost);
00240 virtual void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV) = 0;
00241 virtual void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV) = 0;
00242
00243
00244 bool IsObstacle(int x, int y);
00245 bool IsValidConfiguration(int X, int Y, int Theta);
00246
00247 int getStartID();
00248 int getGoalID();
00249
00250 void GetEnvParms(int *size_x, int *size_y, double* startx, double* starty, double* starttheta, double* startTime, double* goalx, double* goaly, double* goaltheta,
00251 double* cellsize_m, double* timeResolution, double* nominalvel_mpersecs, double* timetoturn45degsinplace_secs, unsigned char* obsthresh, unsigned char* dyn_obs_thresh, vector<SBPL_xythetatimebubble_mprimitive>* motionprimitiveV);
00252
00253 const envDBubbleLatConfig_t* GetEnvNavConfig();
00254
00255
00256 ~EnvDBubbleLattice();
00257
00258 void PrintTimeStat(FILE* fOut);
00259
00260 unsigned char GetMapCost(int x, int y);
00261
00262
00263 bool IsWithinMapCell(int X, int Y);
00264
00277
00278
00279 bool PoseContToDisc(double px, double py, double pth, double pt,
00280 int &ix, int &iy, int &ith, int &it) const;
00281
00291
00292
00293 bool PoseDiscToCont(int ix, int iy, int ith, int it,
00294 double &px, double &py, double &pth, double &pt) const;
00295
00296 virtual void PrintVars(){};
00297
00298 protected:
00299
00300 virtual int GetActionCost(int SourceX, int SourceY, int SourceTheta, int SourceTime, envDBubbleLatAction_t* action, vector<int>* bubbleCollisions=NULL);
00301 unsigned char getDynamicObstacleCost(SBPL_4Dcell_t cell, vector<int>* bubbleCollisions);
00302 double dynObsPtSqrDist(SBPL_4Dcell_t cell, SBPL_Traj_Pt_t p);
00303
00304 bool isInBubble(int x, int y, int t);
00305 void InitializeBubbleMap();
00306 void UpdateBubbleMap();
00307 void FillInBubble(int CenterX, int CenterY, int T, SBPL_DynamicObstacle_t* obs, int rad, int ID, bool isInnerBubble);
00308 void FillInBubbleColumn(int x, int topY, int botY, int T, SBPL_DynamicObstacle_t* obs, int ID, bool isInnerBubble);
00309 void FillInBubbleCell(int x, int y, int T, SBPL_DynamicObstacle_t* obs, int ID, bool isInnerBubble);
00310 int getNumBubbles();
00311
00312
00313 envDBubbleLatConfig_t envDBubbleLatCfg;
00314 EnvDBubbleLat_t envDBubbleLat;
00315 vector<SBPL_4Dcell_t> affectedsuccstatesV;
00316 vector<SBPL_4Dcell_t> affectedpredstatesV;
00317 int iteration;
00318 vector<SBPL_DynamicObstacle_t> dynamicObstacles;
00319 vector< vector<envDBubbleLat_BubbleCell_t> > bubblemap;
00320 vector<bool> bubble4Dactive;
00321 int temporal_padding;
00322
00323
00324 bool bNeedtoRecomputeStartHeuristics;
00325 bool bNeedtoRecomputeGoalHeuristics;
00326 SBPL2DGridSearch* grid2Dsearchfromstart;
00327 SBPL2DGridSearch* grid2Dsearchfromgoal;
00328
00329
00330 void ReadDynamicObstacles(FILE* fDynObs);
00331
00332 virtual void ReadConfiguration(FILE* fCfg);
00333
00334 void InitializeEnvConfig(vector<SBPL_xythetatimebubble_mprimitive>* motionprimitiveV);
00335
00336
00337 bool CheckQuant(FILE* fOut);
00338
00339 void SetConfiguration(int width, int height,
00341 const unsigned char* mapdata,
00342 int startx, int starty, int starttheta, int startTime,
00343 int goalx, int goaly, int goaltheta,
00344 double cellsize_m, double timeResolution,
00345 double nominalvel_mpersecs, double timetoturn45degsinplace_secs, const vector<sbpl_2Dpt_t> & robot_perimeterV);
00346
00347 bool InitGeneral( vector<SBPL_xythetatimebubble_mprimitive>* motionprimitiveV);
00348 void PrecomputeActionswithBaseMotionPrimitive(vector<SBPL_xythetatimebubble_mprimitive>* motionprimitiveV);
00349 void PrecomputeActionswithCompleteMotionPrimitive(vector<SBPL_xythetatimebubble_mprimitive>* motionprimitiveV);
00350 void PrecomputeActions();
00351
00352 void CreateStartandGoalStates();
00353
00354 virtual void InitializeEnvironment() = 0;
00355
00356 void ComputeHeuristicValues();
00357
00358 bool IsValidCell(int X, int Y);
00359
00360 void CalculateFootprintForPose(SBPL_4Dpt_t pose, vector<SBPL_4Dcell_t>* footprint);
00361 void RemoveSourceFootprint(SBPL_4Dpt_t sourcepose, vector<SBPL_4Dcell_t>* footprint);
00362
00363
00364 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<int>* stateBubbles, vector<int>* bubbleCollisions, vector<envDBubbleLatAction_t*>* actionV=NULL) = 0;
00365
00366 double EuclideanDistance_m(int X1, int Y1, int X2, int Y2);
00367
00368 void ComputeReplanningData();
00369 void ComputeReplanningDataforAction(envDBubbleLatAction_t* action);
00370
00371 bool ReadMotionPrimitives(FILE* fMotPrims);
00372 bool ReadinMotionPrimitive(SBPL_xythetatimebubble_mprimitive* pMotPrim, FILE* fIn, bool &isWaitMotion);
00373 int ReadinCell(SBPL_4Dcell_t* cell, char* fIn);
00374 int ReadinPose(SBPL_4Dpt_t* pose, char* fIn);
00375
00376 void PrintHeuristicValues();
00377
00378 };
00379
00380
00381 class EnvDBubbleLat : public EnvDBubbleLattice
00382 {
00383
00384 public:
00385 ~EnvDBubbleLat();
00386
00387
00388 int SetStart(double x, double y, double theta, double startTime);
00389 int SetGoal(double x, double y, double theta);
00390 void SetGoalTolerance(double tol_x, double tol_y, double tol_theta) { }
00391 bool setDynamicObstacles(vector<SBPL_DynamicObstacle_t> dynObs, bool reset_states = true);
00392
00393
00394 void GetCoordFromState(int stateID, int& x, int& y, int& theta, int& t) const;
00395
00396 int GetStateFromCoord(int x, int y, int theta, int t);
00397
00398
00399 void ConvertStateIDPathintoXYThetaPath(vector<int>* stateIDPath, vector<SBPL_4Dpt_t>* xythetaPath);
00400 void PrintState(int stateID, bool bVerbose, FILE* fOut=NULL);
00401
00402 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV);
00403 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<int>* stateBubbles, vector<int>* bubbleCollisions, vector<envDBubbleLatAction_t*>* actionV=NULL);
00404 virtual void Relax(int sourceID, int targetID);
00405
00406 void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV);
00407 void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV);
00408
00409 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state);
00410
00411 virtual int GetFromToHeuristic(int FromStateID, int ToStateID);
00412 virtual int GetGoalHeuristic(int stateID);
00413 virtual int GetStartHeuristic(int stateID);
00414
00415 virtual int SizeofCreatedEnv();
00416
00417 virtual void PrintVars(){};
00418
00419 void dumpStatesToFile();
00420 protected:
00421
00422
00423 int HashTableSize;
00424 vector<envDBubbleLatHashEntry_t*>* Coord2StateIDHashTable;
00425
00426 vector<envDBubbleLatHashEntry_t*> StateID2CoordTable;
00427
00428 unsigned int GETHASHBIN(unsigned int X, unsigned int Y, unsigned int Theta, unsigned int T);
00429
00430 envDBubbleLatHashEntry_t* GetHashEntry(int X, int Y, int Theta, int T, bool inBubble);
00431 envDBubbleLatHashEntry_t* CreateNewHashEntry(int X, int Y, int Theta, int T, bool inBubble);
00432
00433 virtual void InitializeEnvironment();
00434
00435 void PrintHashTableHist();
00436
00437 };
00438
00439
00440 #endif
00441