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 __ENVSIPP_H_
00030 #define __ENVSIPP_H_
00031
00032 #include <sbpl_dynamic_planner/DiscreteSpaceTimeInformation.h>
00033 #include <sbpl_dynamic_planner/sbpl_dynamicObstacles.h>
00034
00035
00036 #define ENVSIPPLAT_DXYWIDTH 8
00037
00038 #define ENVSIPPLAT_DEFAULTOBSTHRESH 254 //see explanation of the value below
00039 #define ENVSIPPLAT_DEFAULTDYNOBSTHRESH 254 //see explanation of the value below
00040
00041
00042
00043
00044
00045
00046 #define ENVSIPPLAT_THETADIRS 16
00047
00048
00049 #define ENVSIPPLAT_DEFAULT_ACTIONWIDTH 5 //decrease, increase, same angle while moving plus decrease, increase angle while standing.
00050
00051 #define ENVSIPPLAT_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 } envSIPPLatAction_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 bool closed;
00091 int iteration;
00092 } envSIPPLatHashEntry_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_xythetasipp_mprimitive;
00104
00105
00106
00107 typedef struct
00108 {
00109
00110 int startstateid;
00111 int goalstateid;
00112
00113 bool bInitialized;
00114
00115
00116
00117
00118 }EnvSIPPLat_t;
00119
00120
00121 typedef struct envSIPPLat_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[ENVSIPPLAT_DXYWIDTH][2];
00159
00160 envSIPPLatAction_t** ActionsV;
00161 vector<envSIPPLatAction_t*>* PredActionsV;
00162
00163 int actionwidth;
00164 vector<SBPL_xythetasipp_mprimitive> mprimV;
00165
00166 vector<sbpl_2Dpt_t> FootprintPolygon;
00167 double robotRadius;
00168 double maxMovement;
00169 } envSIPPLatConfig_t;
00170
00171
00172
00173
00174 class SBPL2DGridSearch;
00175
00176 class EnvSIPPLattice : public DiscreteSpaceTimeInformation
00177 {
00178
00179 public:
00180
00181 EnvSIPPLattice();
00182
00183 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile, const char* sDynObsFile);
00184 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile);
00185 bool InitializeEnv(const char* sEnvFile);
00186 virtual bool SetEnvParameter(const char* parameter, int value);
00187 virtual int GetEnvParameter(const char* parameter);
00188 bool InitializeMDPCfg(MDPConfig *MDPCfg);
00189 virtual int GetFromToHeuristic(int FromStateID, int ToStateID) = 0;
00190 virtual int GetGoalHeuristic(int stateID) = 0;
00191 virtual int GetStartHeuristic(int stateID) = 0;
00192 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state) = 0;
00193 virtual void SetAllPreds(CMDPSTATE* state);
00194 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV);
00195
00196 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV) = 0;
00197
00198
00199 void PrintEnv_Config(FILE* fOut);
00200
00201 bool InitializeEnv(int width, int height,
00203 const unsigned char* mapdata,
00204 double startx, double starty, double starttheta, double startTime,
00205 double goalx, double goaly, double goaltheta,
00206 double goaltol_x, double goaltol_y, double goaltol_theta,
00207 const vector<sbpl_2Dpt_t> & perimeterptsV,
00208 double cellsize_m, double timeResolution,
00209 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00210 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile,
00211 vector<SBPL_DynamicObstacle_t> & dynObs);
00212 bool InitializeEnv(int width, int height,
00214 const unsigned char* mapdata,
00215 double startx, double starty, double starttheta, double startTime,
00216 double goalx, double goaly, double goaltheta,
00217 double goaltol_x, double goaltol_y, double goaltol_theta,
00218 const vector<sbpl_2Dpt_t> & perimeterptsV,
00219 double cellsize_m, double timeResolution,
00220 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00221 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile);
00222 bool UpdateCost(int x, int y, unsigned char newcost);
00223 virtual void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV) = 0;
00224 virtual void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV) = 0;
00225
00226
00227 bool IsObstacle(int x, int y);
00228 bool IsValidConfiguration(int X, int Y, int Theta);
00229
00230 int getStartID();
00231 int getGoalID();
00232
00233 void GetEnvParms(int *size_x, int *size_y, double* startx, double* starty, double* starttheta, double* startTime, double* goalx, double* goaly, double* goaltheta,
00234 double* cellsize_m, double* timeResolution, double* nominalvel_mpersecs, double* timetoturn45degsinplace_secs, unsigned char* obsthresh, unsigned char* dyn_obs_thresh, vector<SBPL_xythetasipp_mprimitive>* motionprimitiveV);
00235
00236 const envSIPPLatConfig_t* GetEnvNavConfig();
00237
00238
00239 ~EnvSIPPLattice();
00240
00241 void PrintTimeStat(FILE* fOut);
00242
00243 unsigned char GetMapCost(int x, int y);
00244
00245
00246 bool IsWithinMapCell(int X, int Y);
00247
00260
00261
00262 bool PoseContToDisc(double px, double py, double pth, double pt,
00263 int &ix, int &iy, int &ith, int &it) const;
00264
00274
00275
00276 bool PoseDiscToCont(int ix, int iy, int ith, int it,
00277 double &px, double &py, double &pth, double &pt) const;
00278
00279 virtual void PrintVars(){};
00280
00281 protected:
00282
00283 virtual int GetActionCost(int SourceX, int SourceY, int SourceTheta, envSIPPLatAction_t* action);
00284
00285 void InitializeTimelineMap();
00286 bool UpdateTimelineMap();
00287 void FillInBubble(int CenterX, int CenterY, int T, int rad);
00288 void FillInBubbleColumn(int x, int topY, int botY, int T);
00289 void FillInBubbleCell(int x, int y, int T);
00290
00291 void intervals2Timeline(int x, int y);
00292 int getInterval(int x, int y, int t);
00293 void getIntervals(vector<int>* intervals, vector<int>* times, envSIPPLatHashEntry_t* state, envSIPPLatAction_t* action);
00294 int getArrivalTimeToInterval(envSIPPLatHashEntry_t* state, envSIPPLatAction_t* action, int start_t, int end_t);
00295 virtual envSIPPLatHashEntry_t* getEntryFromID(int id) = 0;
00296 static bool pairCompare (pair<int,int> i, pair<int,int> j) { return (i.first<j.first); };
00297
00298
00299 envSIPPLatConfig_t envSIPPLatCfg;
00300 EnvSIPPLat_t envSIPPLat;
00301 vector<SBPL_4Dcell_t> affectedsuccstatesV;
00302 vector<SBPL_4Dcell_t> affectedpredstatesV;
00303 int iteration;
00304 vector<SBPL_DynamicObstacle_t> dynamicObstacles;
00305 vector< vector< vector<int> > > timelineMap;
00306 vector< vector< vector< pair<int,int> > > > intervalMap;
00307 int temporal_padding;
00308
00309
00310 bool bNeedtoRecomputeStartHeuristics;
00311 bool bNeedtoRecomputeGoalHeuristics;
00312 SBPL2DGridSearch* grid2Dsearchfromstart;
00313 SBPL2DGridSearch* grid2Dsearchfromgoal;
00314
00315
00316 void ReadDynamicObstacles(FILE* fDynObs);
00317
00318 virtual void ReadConfiguration(FILE* fCfg);
00319
00320 void InitializeEnvConfig(vector<SBPL_xythetasipp_mprimitive>* motionprimitiveV);
00321
00322
00323 bool CheckQuant(FILE* fOut);
00324
00325 void SetConfiguration(int width, int height,
00327 const unsigned char* mapdata,
00328 int startx, int starty, int starttheta, int startTime,
00329 int goalx, int goaly, int goaltheta,
00330 double cellsize_m, double timeResolution,
00331 double nominalvel_mpersecs, double timetoturn45degsinplace_secs, const vector<sbpl_2Dpt_t> & robot_perimeterV);
00332
00333 bool InitGeneral( vector<SBPL_xythetasipp_mprimitive>* motionprimitiveV);
00334 void PrecomputeActionswithBaseMotionPrimitive(vector<SBPL_xythetasipp_mprimitive>* motionprimitiveV);
00335 void PrecomputeActionswithCompleteMotionPrimitive(vector<SBPL_xythetasipp_mprimitive>* motionprimitiveV);
00336 void PrecomputeActions();
00337
00338 void CreateStartandGoalStates();
00339
00340 virtual void InitializeEnvironment() = 0;
00341
00342 void ComputeHeuristicValues();
00343
00344 bool IsValidCell(int X, int Y);
00345
00346 void CalculateFootprintForPose(SBPL_4Dpt_t pose, vector<SBPL_4Dcell_t>* footprint);
00347 void RemoveSourceFootprint(SBPL_4Dpt_t sourcepose, vector<SBPL_4Dcell_t>* footprint);
00348
00349
00350 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<envSIPPLatAction_t*>* actionV=NULL) = 0;
00351
00352 double EuclideanDistance_m(int X1, int Y1, int X2, int Y2);
00353
00354 void ComputeReplanningData();
00355 void ComputeReplanningDataforAction(envSIPPLatAction_t* action);
00356
00357 bool ReadMotionPrimitives(FILE* fMotPrims);
00358 bool ReadinMotionPrimitive(SBPL_xythetasipp_mprimitive* pMotPrim, FILE* fIn, bool &isWaitMotion);
00359 int ReadinCell(SBPL_4Dcell_t* cell, char* fIn);
00360 int ReadinPose(SBPL_4Dpt_t* pose, char* fIn);
00361
00362 void PrintHeuristicValues();
00363
00364 };
00365
00366
00367 class EnvSIPPLat : public EnvSIPPLattice
00368 {
00369
00370 public:
00371 ~EnvSIPPLat();
00372
00373
00374 int SetStart(double x, double y, double theta, double startTime);
00375 int SetGoal(double x, double y, double theta);
00376 void SetGoalTolerance(double tol_x, double tol_y, double tol_theta) { }
00377 bool setDynamicObstacles(vector<SBPL_DynamicObstacle_t> dynObs, bool reset_states = true);
00378 void ClearStates();
00379 envSIPPLatHashEntry_t* getEntryFromID(int id);
00380
00381
00382 void GetCoordFromState(int stateID, int& x, int& y, int& theta, int& t) const;
00383
00384 int GetStateFromCoord(int x, int y, int theta, int t);
00385
00386
00387 void ConvertStateIDPathintoXYThetaPath(vector<int>* stateIDPath, vector<SBPL_4Dpt_t>* xythetaPath);
00388 void PrintState(int stateID, bool bVerbose, FILE* fOut=NULL);
00389
00390 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV);
00391 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<envSIPPLatAction_t*>* actionV=NULL);
00392
00393 void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV);
00394 void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV);
00395
00396 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state);
00397
00398 virtual int GetFromToHeuristic(int FromStateID, int ToStateID);
00399 virtual int GetGoalHeuristic(int stateID);
00400 virtual int GetStartHeuristic(int stateID);
00401
00402 virtual int SizeofCreatedEnv();
00403
00404 virtual void PrintVars(){};
00405
00406
00407 void getExpansions(vector<SBPL_4Dpt_t>* p);
00408 void dumpStatesToFile();
00409 void dumpEnvironmentToFile();
00410 void dumpDynamicObstaclesToFile();
00411 protected:
00412
00413
00414 int HashTableSize;
00415 vector<envSIPPLatHashEntry_t*>* Coord2StateIDHashTable;
00416
00417 vector<envSIPPLatHashEntry_t*> StateID2CoordTable;
00418
00419 unsigned int GETHASHBIN(unsigned int X, unsigned int Y, unsigned int Theta, unsigned int interval);
00420
00421 envSIPPLatHashEntry_t* GetHashEntry(int X, int Y, int Theta, int interval, int T);
00422 envSIPPLatHashEntry_t* CreateNewHashEntry(int X, int Y, int Theta, int interval, int T);
00423
00424 virtual void InitializeEnvironment();
00425
00426 void PrintHashTableHist();
00427
00428 };
00429
00430
00431 #endif
00432