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 __ENVIRONMENT_NAVXYTHETATIMELAT_H_
00030 #define __ENVIRONMENT_NAVXYTHETATIMELAT_H_
00031
00032 #include <sbpl_dynamic_planner/DiscreteSpaceTimeInformation.h>
00033 #include <sbpl_dynamic_planner/sbpl_dynamicObstacles.h>
00034
00035
00036 #define NAVXYTHETATIMELAT_DXYWIDTH 8
00037
00038 #define ENVNAVXYTHETATIMELAT_DEFAULTOBSTHRESH 254 //see explanation of the value below
00039 #define ENVNAVXYTHETATIMELAT_DEFAULTDYNOBSTHRESH 254 //see explanation of the value below
00040
00041
00042
00043
00044
00045
00046 #define NAVXYTHETATIMELAT_THETADIRS 16
00047
00048
00049 #define NAVXYTHETATIMELAT_DEFAULT_ACTIONWIDTH 5 //decrease, increase, same angle while moving plus decrease, increase angle while standing.
00050
00051 #define NAVXYTHETATIMELAT_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
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 } EnvNAVXYTHETATIMELATAction_t;
00081
00082
00083 typedef struct
00084 {
00085 int stateID;
00086 int X;
00087 int Y;
00088 char Theta;
00089 int T;
00090 int iteration;
00091 } EnvNAVXYTHETATIMELATHashEntry_t;
00092
00093
00094 typedef struct
00095 {
00096 int motprimID;
00097 unsigned char starttheta_c;
00098 int additionalactioncostmult;
00099 SBPL_4Dcell_t endcell;
00100
00101 vector<SBPL_4Dpt_t> intermptV;
00102 }SBPL_xythetatime_mprimitive;
00103
00104
00105
00106 typedef struct
00107 {
00108
00109 int startstateid;
00110 int goalstateid;
00111
00112 bool bInitialized;
00113
00114
00115
00116
00117 }EnvironmentNAVXYTHETATIMELAT_t;
00118
00119
00120 typedef struct ENV_NAVXYTHETATIMELAT_CONFIG
00121 {
00122 int EnvWidth_c;
00123 int EnvHeight_c;
00124 int StartX_c;
00125 int StartY_c;
00126 int StartTheta;
00127 int StartTime;
00128 int EndX_c;
00129 int EndY_c;
00130 int EndTheta;
00131 unsigned char** Grid2D;
00132
00133
00134
00135 unsigned char obsthresh;
00136
00137
00138
00139
00140
00141 unsigned char cost_inscribed_thresh;
00142
00143
00144
00145
00146
00147 int cost_possibly_circumscribed_thresh;
00148
00149
00150 unsigned char dynamic_obstacle_collision_cost_thresh;
00151
00152 double nominalvel_mpersecs;
00153 double timetoturn45degsinplace_secs;
00154 double cellsize_m;
00155 double timeResolution;
00156
00157 int dXY[NAVXYTHETATIMELAT_DXYWIDTH][2];
00158
00159 EnvNAVXYTHETATIMELATAction_t** ActionsV;
00160 vector<EnvNAVXYTHETATIMELATAction_t*>* PredActionsV;
00161
00162 int actionwidth;
00163 vector<SBPL_xythetatime_mprimitive> mprimV;
00164
00165 vector<sbpl_2Dpt_t> FootprintPolygon;
00166 double robotRadius;
00167 } EnvNAVXYTHETATIMELATConfig_t;
00168
00169
00170
00171 class SBPL2DGridSearch;
00172
00173 class EnvironmentNAVXYTHETATIMELATTICE : public DiscreteSpaceTimeInformation
00174 {
00175
00176 public:
00177
00178 EnvironmentNAVXYTHETATIMELATTICE();
00179
00180 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile, const char* sDynObsFile);
00181 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const char* sMotPrimFile);
00182 bool InitializeEnv(const char* sEnvFile);
00183 virtual bool SetEnvParameter(const char* parameter, int value);
00184 virtual int GetEnvParameter(const char* parameter);
00185 bool InitializeMDPCfg(MDPConfig *MDPCfg);
00186 virtual int GetFromToHeuristic(int FromStateID, int ToStateID) = 0;
00187 virtual int GetGoalHeuristic(int stateID) = 0;
00188 virtual int GetStartHeuristic(int stateID) = 0;
00189 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state) = 0;
00190 virtual void SetAllPreds(CMDPSTATE* state);
00191 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV);
00192
00193 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV) = 0;
00194
00195
00196 void PrintEnv_Config(FILE* fOut);
00197
00198 bool InitializeEnv(int width, int height,
00200 const unsigned char* mapdata,
00201 double startx, double starty, double starttheta, double startTime,
00202 double goalx, double goaly, double goaltheta,
00203 double goaltol_x, double goaltol_y, double goaltol_theta,
00204 const vector<sbpl_2Dpt_t> & perimeterptsV,
00205 double cellsize_m, double timeResolution,
00206 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00207 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile,
00208 vector<SBPL_DynamicObstacle_t> & dynObs);
00209 bool InitializeEnv(int width, int height,
00211 const unsigned char* mapdata,
00212 double startx, double starty, double starttheta, double startTime,
00213 double goalx, double goaly, double goaltheta,
00214 double goaltol_x, double goaltol_y, double goaltol_theta,
00215 const vector<sbpl_2Dpt_t> & perimeterptsV,
00216 double cellsize_m, double timeResolution,
00217 double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00218 unsigned char obsthresh, unsigned char dynobsthresh, const char* sMotPrimFile);
00219 bool UpdateCost(int x, int y, unsigned char newcost);
00220 virtual void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV) = 0;
00221 virtual void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV) = 0;
00222
00223
00224 bool IsObstacle(int x, int y);
00225 bool IsValidConfiguration(int X, int Y, int Theta);
00226
00227 int getStartID();
00228 int getGoalID();
00229
00230 void GetEnvParms(int *size_x, int *size_y, double* startx, double* starty, double* starttheta, double* startTime, double* goalx, double* goaly, double* goaltheta,
00231 double* cellsize_m, double* timeResolution, double* nominalvel_mpersecs, double* timetoturn45degsinplace_secs, unsigned char* obsthresh, unsigned char* dyn_obs_thresh, vector<SBPL_xythetatime_mprimitive>* motionprimitiveV);
00232
00233 const EnvNAVXYTHETATIMELATConfig_t* GetEnvNavConfig();
00234
00235
00236 ~EnvironmentNAVXYTHETATIMELATTICE();
00237
00238 void PrintTimeStat(FILE* fOut);
00239
00240 unsigned char GetMapCost(int x, int y);
00241
00242
00243 bool IsWithinMapCell(int X, int Y);
00244
00257
00258
00259 bool PoseContToDisc(double px, double py, double pth, double pt,
00260 int &ix, int &iy, int &ith, int &it) const;
00261
00271
00272
00273 bool PoseDiscToCont(int ix, int iy, int ith, int it,
00274 double &px, double &py, double &pth, double &pt) const;
00275
00276 virtual void PrintVars(){};
00277
00278 protected:
00279
00280 virtual int GetActionCost(int SourceX, int SourceY, int SourceTheta, int SourceTime, EnvNAVXYTHETATIMELATAction_t* action);
00281 void InitializeTimelineMap();
00282 bool UpdateTimelineMap();
00283 void FillInBubble(int CenterX, int CenterY, int T, int rad);
00284 void FillInBubbleColumn(int x, int topY, int botY, int T);
00285 void FillInBubbleCell(int x, int y, int T);
00286
00287 void intervals2Timeline(int x, int y);
00288 int getInterval(int x, int y, int t);
00289 virtual EnvNAVXYTHETATIMELATHashEntry_t* getEntryFromID(int id) = 0;
00290 static bool pairCompare (pair<int,int> i, pair<int,int> j) { return (i.first<j.first); };
00291
00292 unsigned char getDynamicObstacleCost(SBPL_4Dcell_t cell);
00293 double dynObsPtSqrDist(SBPL_4Dcell_t cell, SBPL_Traj_Pt_t p);
00294
00295
00296
00297 EnvNAVXYTHETATIMELATConfig_t EnvNAVXYTHETATIMELATCfg;
00298 EnvironmentNAVXYTHETATIMELAT_t EnvNAVXYTHETATIMELAT;
00299 vector<SBPL_4Dcell_t> affectedsuccstatesV;
00300 vector<SBPL_4Dcell_t> affectedpredstatesV;
00301 int iteration;
00302 vector<SBPL_DynamicObstacle_t> dynamicObstacles;
00303 vector< vector< vector<int> > > timelineMap;
00304 vector< vector< vector< pair<int,int> > > > intervalMap;
00305 int temporal_padding;
00306
00307
00308 bool bNeedtoRecomputeStartHeuristics;
00309 bool bNeedtoRecomputeGoalHeuristics;
00310 SBPL2DGridSearch* grid2Dsearchfromstart;
00311 SBPL2DGridSearch* grid2Dsearchfromgoal;
00312
00313
00314 void ReadDynamicObstacles(FILE* fDynObs);
00315
00316 virtual void ReadConfiguration(FILE* fCfg);
00317
00318 void InitializeEnvConfig(vector<SBPL_xythetatime_mprimitive>* motionprimitiveV);
00319
00320
00321 bool CheckQuant(FILE* fOut);
00322
00323 void SetConfiguration(int width, int height,
00325 const unsigned char* mapdata,
00326 int startx, int starty, int starttheta, int startTime,
00327 int goalx, int goaly, int goaltheta,
00328 double cellsize_m, double timeResolution,
00329 double nominalvel_mpersecs, double timetoturn45degsinplace_secs, const vector<sbpl_2Dpt_t> & robot_perimeterV);
00330
00331 bool InitGeneral( vector<SBPL_xythetatime_mprimitive>* motionprimitiveV);
00332 void PrecomputeActionswithBaseMotionPrimitive(vector<SBPL_xythetatime_mprimitive>* motionprimitiveV);
00333 void PrecomputeActionswithCompleteMotionPrimitive(vector<SBPL_xythetatime_mprimitive>* motionprimitiveV);
00334 void PrecomputeActions();
00335
00336 void CreateStartandGoalStates();
00337
00338 virtual void InitializeEnvironment() = 0;
00339
00340 void ComputeHeuristicValues();
00341
00342 bool IsValidCell(int X, int Y);
00343
00344 void CalculateFootprintForPose(SBPL_4Dpt_t pose, vector<SBPL_4Dcell_t>* footprint);
00345 void RemoveSourceFootprint(SBPL_4Dpt_t sourcepose, vector<SBPL_4Dcell_t>* footprint);
00346
00347 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<EnvNAVXYTHETATIMELATAction_t*>* actionindV=NULL) = 0;
00348
00349 double EuclideanDistance_m(int X1, int Y1, int X2, int Y2);
00350
00351 void ComputeReplanningData();
00352 void ComputeReplanningDataforAction(EnvNAVXYTHETATIMELATAction_t* action);
00353
00354 bool ReadMotionPrimitives(FILE* fMotPrims);
00355 bool ReadinMotionPrimitive(SBPL_xythetatime_mprimitive* pMotPrim, FILE* fIn);
00356 int ReadinCell(SBPL_4Dcell_t* cell, char* fIn);
00357 int ReadinPose(SBPL_4Dpt_t* pose, char* fIn);
00358
00359 void PrintHeuristicValues();
00360
00361 };
00362
00363
00364 class EnvironmentNAVXYTHETATIMELAT : public EnvironmentNAVXYTHETATIMELATTICE
00365 {
00366
00367 public:
00368 ~EnvironmentNAVXYTHETATIMELAT();
00369
00370
00371 int SetStart(double x, double y, double theta, double startTime);
00372 int SetGoal(double x, double y, double theta);
00373 void SetGoalTolerance(double tol_x, double tol_y, double tol_theta) { }
00374 bool setDynamicObstacles(vector<SBPL_DynamicObstacle_t> dynObs, bool reset_states = true);
00375 EnvNAVXYTHETATIMELATHashEntry_t* getEntryFromID(int id);
00376
00377
00378 void GetCoordFromState(int stateID, int& x, int& y, int& theta, int& t) const;
00379
00380 int GetStateFromCoord(int x, int y, int theta, int t);
00381
00382 void ConvertStateIDPathintoXYThetaPath(vector<int>* stateIDPath, vector<SBPL_4Dpt_t>* xythetaPath);
00383 bool AreEquivalent(int StateID1, int StateID2){return StateID1 == StateID2;}
00384 void PrintState(int stateID, bool bVerbose, FILE* fOut=NULL);
00385
00386 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV);
00387 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<EnvNAVXYTHETATIMELATAction_t*>* actionindV=NULL);
00388
00389 void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV);
00390 void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV);
00391
00392 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state);
00393
00394 virtual int GetFromToHeuristic(int FromStateID, int ToStateID);
00395 virtual int GetGoalHeuristic(int stateID);
00396 virtual int GetStartHeuristic(int stateID);
00397
00398 virtual int SizeofCreatedEnv();
00399
00400 virtual void PrintVars(){};
00401
00402 void dumpStatesToFile();
00403 protected:
00404
00405
00406 int HashTableSize;
00407 vector<EnvNAVXYTHETATIMELATHashEntry_t*>* Coord2StateIDHashTable;
00408
00409 vector<EnvNAVXYTHETATIMELATHashEntry_t*> StateID2CoordTable;
00410
00411 unsigned int GETHASHBIN(unsigned int X, unsigned int Y, unsigned int Theta, unsigned int T);
00412
00413 EnvNAVXYTHETATIMELATHashEntry_t* GetHashEntry(int X, int Y, int Theta, int T);
00414 EnvNAVXYTHETATIMELATHashEntry_t* CreateNewHashEntry(int X, int Y, int Theta, int T);
00415
00416 virtual void InitializeEnvironment();
00417
00418 void PrintHashTableHist();
00419
00420 };
00421
00422
00423 #endif
00424