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 __ENVINTERVAL_H_
00030 #define __ENVINTERVAL_H_
00031
00032 #include <sbpl_dynamic_planner/DiscreteSpaceTimeIntervalInformation.h>
00033 #include <sbpl_dynamic_planner/sbpl_dynamicObstacles.h>
00034
00035
00036 #define ENVINTERVALLAT_DXYWIDTH 8
00037
00038 #define ENVINTERVALLAT_DEFAULTOBSTHRESH 254 //see explanation of the value below
00039 #define ENVINTERVALLAT_DEFAULTDYNOBSTHRESH 254 //see explanation of the value below
00040
00041
00042
00043
00044
00045
00046 #define ENVINTERVALLAT_THETADIRS 16
00047
00048
00049 #define ENVINTERVALLAT_DEFAULT_ACTIONWIDTH 5 //decrease, increase, same angle while moving plus decrease, increase angle while standing.
00050
00051 #define ENVINTERVALLAT_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 #define FAIL 0
00057 #define SUCCESS_WITH_TIME 1
00058 #define SUCCESS_NO_TIME 2
00059
00060 typedef struct
00061 {
00062 char starttheta;
00063 char dX;
00064 char dY;
00065 int dT;
00066 char endtheta;
00067 unsigned int cost;
00068
00069
00070 vector<SBPL_4Dcell_t> intersectingcellsV;
00071
00072
00073
00074 vector<SBPL_4Dpt_t> intermptV;
00075
00076
00077
00078 vector<SBPL_4Dcell_t> interm4DcellsV;
00079 } envIntervalLatAction_t;
00080
00081
00082 typedef struct
00083 {
00084 int stateID;
00085 int X;
00086 int Y;
00087 char Theta;
00088 int Interval;
00089 int T;
00090 int tempT;
00091 bool Optimal;
00092 bool closed;
00093 bool init;
00094 int iteration;
00095 } envIntervalLatHashEntry_t;
00096
00097
00098 typedef struct
00099 {
00100 int motprimID;
00101 unsigned char starttheta_c;
00102 int additionalactioncostmult;
00103 SBPL_4Dcell_t endcell;
00104
00105 vector<SBPL_4Dpt_t> intermptV;
00106 }SBPL_xythetainterval_mprimitive;
00107
00108
00109
00110 typedef struct
00111 {
00112
00113 int startstateid;
00114 int goalstateid;
00115
00116 bool bInitialized;
00117
00118
00119
00120
00121 }EnvIntervalLat_t;
00122
00123
00124 typedef struct envIntervalLat_config
00125 {
00126 int EnvWidth_c;
00127 int EnvHeight_c;
00128 int StartX_c;
00129 int StartY_c;
00130 int StartTheta;
00131 int StartTime;
00132 int EndX_c;
00133 int EndY_c;
00134 int EndTheta;
00135 unsigned char** Grid2D;
00136
00137
00138
00139 unsigned char obsthresh;
00140
00141
00142
00143
00144
00145 unsigned char cost_inscribed_thresh;
00146
00147
00148
00149
00150
00151 int cost_possibly_circumscribed_thresh;
00152
00153
00154 unsigned char dynamic_obstacle_collision_cost_thresh;
00155
00156 double nominalvel_mpersecs;
00157 double timetoturn45degsinplace_secs;
00158 double cellsize_m;
00159 double timeResolution;
00160
00161 int dXY[ENVINTERVALLAT_DXYWIDTH][2];
00162
00163 envIntervalLatAction_t** ActionsV;
00164 vector<envIntervalLatAction_t*>* PredActionsV;
00165
00166 int actionwidth;
00167 vector<SBPL_xythetainterval_mprimitive> mprimV;
00168
00169 vector<sbpl_2Dpt_t> FootprintPolygon;
00170 double robotRadius;
00171 double maxMovement;
00172 } envIntervalLatConfig_t;
00173
00174
00175
00176
00177 class SBPL2DGridSearch;
00178
00179 class EnvIntervalLattice : public DiscreteSpaceTimeIntervalInformation
00180 {
00181
00182 public:
00183
00187 EnvIntervalLattice();
00188
00197 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile, const char* sDynObsFile);
00198
00206 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile);
00207
00235 bool InitializeEnv(int width, int height,
00237 const unsigned char* mapdata,
00238 double startx, double starty, double starttheta, double startTime,
00239 double goalx, double goaly, double goaltheta,
00240 double goaltol_x, double goaltol_y, double goaltol_theta,
00241 const vector<sbpl_2Dpt_t> & perimeterptsV,
00242 double cellsize_m, double timeResolution, double temporal_padding_c,
00243 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00244 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile,
00245 vector<SBPL_DynamicObstacle_t> & dynObs);
00246
00251 int getStartID();
00252
00257 int getGoalID();
00258
00266 bool UpdateCost(int x, int y, unsigned char newcost);
00267
00274 bool IsObstacle(int x, int y);
00275
00283 bool IsValidConfiguration(int X, int Y, int Theta);
00284
00291 unsigned char GetMapCost(int x, int y);
00292
00299 bool IsWithinMapCell(int X, int Y);
00300
00301
00308 virtual bool SetEnvParameter(const char* parameter, int value);
00309
00315 virtual int GetEnvParameter(const char* parameter);
00316
00320 void GetEnvParms(int *size_x, int *size_y, double* startx, double* starty, double* starttheta, double* startTime, double* goalx, double* goaly, double* goaltheta,
00321 double* cellsize_m, double* timeResolution, double* temporal_padding_, double* nominalvel_mpersecs, double* timetoturn45degsinplace_secs, unsigned char* obsthresh, unsigned char* dyn_obs_thresh, vector<SBPL_xythetainterval_mprimitive>* motionprimitiveV);
00322
00326 ~EnvIntervalLattice();
00327
00328
00329 virtual int GetFromToHeuristic(int FromStateID, int ToStateID) = 0;
00330 virtual int GetGoalHeuristic(int stateID) = 0;
00331 virtual int GetStartHeuristic(int stateID) = 0;
00332
00333 const envIntervalLatConfig_t* GetEnvNavConfig();
00334 void PrintTimeStat(FILE* fOut);
00335 void PrintEnv_Config(FILE* fOut);
00336
00337 bool PoseContToDisc(double px, double py, double pth, double pt,
00338 int &ix, int &iy, int &ith, int &it) const;
00339 bool PoseDiscToCont(int ix, int iy, int ith, int it,
00340 double &px, double &py, double &pth, double &pt) const;
00341 virtual void PrintVars(){};
00342
00343 protected:
00344
00345 virtual int GetActionCost(int SourceX, int SourceY, int SourceTheta, envIntervalLatAction_t* action);
00346
00347 void InitializeTimelineMap();
00348 bool UpdateTimelineMap();
00349 void FillInBubble(int CenterX, int CenterY, int T, int rad);
00350 void FillInBubbleColumn(int x, int topY, int botY, int T);
00351 void FillInBubbleCell(int x, int y, int T);
00352
00353 void intervals2Timeline(int x, int y);
00354 int getInterval(int x, int y, int t);
00355 void getIntervals(vector<int>* intervals, vector<int>* times, envIntervalLatHashEntry_t* state, envIntervalLatAction_t* action);
00356 int getArrivalTimeToInterval(envIntervalLatHashEntry_t* state, envIntervalLatAction_t* action, int start_t, int end_t);
00357 virtual envIntervalLatHashEntry_t* getEntryFromID(int id) = 0;
00358 static bool pairCompare (pair<int,int> i, pair<int,int> j) { return (i.first<j.first); };
00359
00360
00361 envIntervalLatConfig_t envIntervalLatCfg;
00362 EnvIntervalLat_t envIntervalLat;
00363 vector<SBPL_4Dcell_t> affectedsuccstatesV;
00364 vector<SBPL_4Dcell_t> affectedpredstatesV;
00365 int iteration;
00366 vector<SBPL_DynamicObstacle_t> dynamicObstacles;
00367 vector< vector< vector<int> > > timelineMap;
00368 vector< vector< vector< pair<int,int> > > > intervalMap;
00369 int temporal_padding;
00370
00371
00372 bool bNeedtoRecomputeStartHeuristics;
00373 bool bNeedtoRecomputeGoalHeuristics;
00374 SBPL2DGridSearch* grid2Dsearchfromstart;
00375 SBPL2DGridSearch* grid2Dsearchfromgoal;
00376
00377
00378 void ReadDynamicObstacles(FILE* fDynObs);
00379
00380 virtual void ReadConfiguration(FILE* fCfg);
00381
00382 void InitializeEnvConfig(vector<SBPL_xythetainterval_mprimitive>* motionprimitiveV);
00383
00384
00385 bool CheckQuant(FILE* fOut);
00386
00387 void SetConfiguration(int width, int height,
00389 const unsigned char* mapdata,
00390 int startx, int starty, int starttheta, int startTime,
00391 int goalx, int goaly, int goaltheta,
00392 double cellsize_m, double timeResolution,
00393 double nominalvel_mpersecs, double timetoturn45degsinplace_secs, const vector<sbpl_2Dpt_t> & robot_perimeterV);
00394
00395 bool InitGeneral( vector<SBPL_xythetainterval_mprimitive>* motionprimitiveV);
00396 void PrecomputeActionswithBaseMotionPrimitive(vector<SBPL_xythetainterval_mprimitive>* motionprimitiveV);
00397 void PrecomputeActionswithCompleteMotionPrimitive(vector<SBPL_xythetainterval_mprimitive>* motionprimitiveV);
00398 void PrecomputeActions();
00399
00400 void CreateStartandGoalStates();
00401
00402 virtual void InitializeEnvironment() = 0;
00403
00404 void ComputeHeuristicValues();
00405
00406 bool IsValidCell(int X, int Y);
00407
00408 void CalculateFootprintForPose(SBPL_4Dpt_t pose, vector<SBPL_4Dcell_t>* footprint);
00409 void RemoveSourceFootprint(SBPL_4Dpt_t sourcepose, vector<SBPL_4Dcell_t>* footprint);
00410
00411 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<bool>* OptV, bool optSearch);
00412 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<bool>* OptV, bool optSearch, vector<envIntervalLatAction_t*>* actionV=NULL) = 0;
00413
00414 double EuclideanDistance_m(int X1, int Y1, int X2, int Y2);
00415
00416 void ComputeReplanningData();
00417 void ComputeReplanningDataforAction(envIntervalLatAction_t* action);
00418
00419 bool ReadMotionPrimitives(FILE* fMotPrims);
00420 bool ReadinMotionPrimitive(SBPL_xythetainterval_mprimitive* pMotPrim, FILE* fIn, bool &isWaitMotion);
00421 int ReadinCell(SBPL_4Dcell_t* cell, char* fIn);
00422 int ReadinPose(SBPL_4Dpt_t* pose, char* fIn);
00423
00424 void PrintHeuristicValues();
00425
00426
00427 bool InitializeEnv(const char* sEnvFile);
00428 bool InitializeMDPCfg(MDPConfig *MDPCfg);
00429 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state) = 0;
00430 virtual void SetAllPreds(CMDPSTATE* state);
00431 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV) = 0;
00432 bool InitializeEnv(int width, int height,
00433 const unsigned char* mapdata,
00434 double startx, double starty, double starttheta, double startTime,
00435 double goalx, double goaly, double goaltheta,
00436 double goaltol_x, double goaltol_y, double goaltol_theta,
00437 const vector<sbpl_2Dpt_t> & perimeterptsV,
00438 double cellsize_m, double timeResolution, double temporal_padding_c,
00439 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00440 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile);
00441 virtual void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV) = 0;
00442 virtual void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV) = 0;
00443
00444 };
00445
00446
00447 class EnvIntervalLat : public EnvIntervalLattice
00448 {
00449
00450 public:
00451 ~EnvIntervalLat();
00452
00461 int SetStart(double x, double y, double theta, double startTime);
00462
00470 int SetGoal(double x, double y, double theta);
00471
00478 bool setDynamicObstacles(vector<SBPL_DynamicObstacle_t> dynObs, bool reset_states = true);
00479
00480
00486 void ConvertStateIDPathintoXYThetaPath(vector<int>* stateIDPath, vector<SBPL_4Dpt_t>* xythetaPath);
00487
00491 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<bool>* OptV, bool optSearch, vector<envIntervalLatAction_t*>* actionV=NULL);
00492
00496 void Relax(int stateID);
00497
00501 void GetCoordFromState(int stateID, int& x, int& y, int& theta, int& t) const;
00502
00506 void GetCoordFromState(int stateID, int& x, int& y, int& theta, int& t, bool& opt) const;
00507
00511 int GetStateFromCoord(int x, int y, int theta, int t);
00512
00513 void PrintState(int stateID, bool bVerbose, FILE* fOut=NULL);
00514
00515 virtual int GetFromToHeuristic(int FromStateID, int ToStateID);
00516 virtual int GetGoalHeuristic(int stateID);
00517 virtual int GetStartHeuristic(int stateID);
00518
00519 virtual int SizeofCreatedEnv();
00520
00521 virtual void PrintVars(){};
00522
00523 void getExpansions(vector<SBPL_4Dpt_t>* p);
00524 void dumpStatesToFile();
00525 void dumpEnvironmentToFile();
00526 void dumpDynamicObstaclesToFile();
00527 protected:
00528 void ClearStates();
00529 envIntervalLatHashEntry_t* getEntryFromID(int id);
00530
00531
00532
00533 int HashTableSize;
00534 vector<envIntervalLatHashEntry_t*>* Coord2StateIDHashTable;
00535
00536 vector<envIntervalLatHashEntry_t*> StateID2CoordTable;
00537
00538 unsigned int GETHASHBIN(unsigned int X, unsigned int Y, unsigned int Theta, unsigned int interval, bool Opt);
00539
00540 envIntervalLatHashEntry_t* GetHashEntry(int X, int Y, int Theta, int interval, int T, bool Opt);
00541 envIntervalLatHashEntry_t* CreateNewHashEntry(int X, int Y, int Theta, int interval, int T, bool Opt);
00542
00543 virtual void InitializeEnvironment();
00544
00545 void PrintHashTableHist();
00546
00547
00548 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV);
00549 void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV);
00550 void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV);
00551 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state);
00552 };
00553
00554
00555 #endif
00556