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_NAVXYTHETACARTLAT_H_
00030 #define __ENVIRONMENT_NAVXYTHETACARTLAT_H_
00031
00032
00033
00034 #define NAVXYTHETACARTLAT_DXYWIDTH 8
00035
00036 #define ENVNAVXYTHETACARTLAT_DEFAULTOBSTHRESH 254 //see explanation of the value below
00037
00038 #define SBPL_XYTHETACARTLAT_MAXSTATESFORLOOKUP 100000000 //maximum number of states for storing them into lookup (as opposed to hash)
00039
00040
00041
00042
00043
00044 #define NAVXYTHETACARTLAT_THETADIRS 16
00045
00046
00047 #define CART_THETADIRS 5 //Should be symmetric
00048 #define MAX_CART_ANGLE M_PI/4.0
00049
00050
00051 #define NAVXYTHETACARTLAT_DEFAULT_ACTIONWIDTH 5 //decrease, increase, same angle while moving plus decrease, increase angle while standing.
00052
00053 #define NAVXYTHETACARTLAT_COSTMULT_MTOMM 1000
00054
00055 typedef struct{
00056 double x;
00057 double y;
00058 } EnvNAVXYTHETACARTLAT2Dpt_t;
00059
00060 typedef struct{
00061 double x;
00062 double y;
00063 double theta;
00064 double cartangle;
00065 } EnvNAVXYTHETACARTLAT3Dpt_t;
00066
00067
00068 typedef struct EnvNAVXYTHETACARTLAT3DCELL{
00069 int x;
00070 int y;
00071 int theta;
00072 int iteration;
00073 int cartangle;
00074 public:
00075 bool operator == (EnvNAVXYTHETACARTLAT3DCELL cell) {return (x==cell.x && y==cell.y && theta==cell.theta && cartangle == cell.cartangle);}
00076 } EnvNAVXYTHETACARTLAT3Dcell_t;
00077
00078
00079 typedef struct
00080 {
00081 char starttheta;
00082 char dX;
00083 char dY;
00084 char endtheta;
00085 char startcartangle;
00086 char endcartangle;
00087 unsigned int cost;
00088 vector<sbpl_2Dcell_t> intersectingcellsV;
00089
00090 vector<EnvNAVXYTHETACARTLAT3Dpt_t> intermptV;
00091
00092 vector<EnvNAVXYTHETACARTLAT3Dcell_t> interm3DcellsV;
00093 } EnvNAVXYTHETACARTLATAction_t;
00094
00095
00096 typedef struct
00097 {
00098 int stateID;
00099 int X;
00100 int Y;
00101 char Theta;
00102 char CartAngle;
00103 int iteration;
00104 } EnvNAVXYTHETACARTLATHashEntry_t;
00105
00106
00107 typedef struct
00108 {
00109 int motprimID;
00110 unsigned char starttheta_c;
00111 int additionalactioncostmult;
00112 EnvNAVXYTHETACARTLAT3Dcell_t endcell;
00113
00114 vector<EnvNAVXYTHETACARTLAT3Dpt_t> intermptV;
00115 }SBPL_xythetacart_mprimitive;
00116
00117
00118
00119 typedef struct
00120 {
00121
00122 int startstateid;
00123 int goalstateid;
00124
00125 bool bInitialized;
00126
00127
00128
00129
00130 }EnvironmentNAVXYTHETACARTLAT_t;
00131
00132
00133 typedef struct ENV_NAVXYTHETACARTLAT_CONFIG
00134 {
00135 int EnvWidth_c;
00136 int EnvHeight_c;
00137 int StartX_c;
00138 int StartY_c;
00139 int StartTheta;
00140 int StartCartAngle;
00141 int EndX_c;
00142 int EndY_c;
00143 int EndTheta;
00144 int EndCartAngle;
00145 unsigned char** Grid2D;
00146
00147
00148
00149 unsigned char obsthresh;
00150
00151
00152
00153
00154
00155 unsigned char cost_inscribed_thresh;
00156
00157
00158
00159
00160
00161 int cost_possibly_circumscribed_thresh;
00162
00163 double nominalvel_mpersecs;
00164 double timetoturn45degsinplace_secs;
00165 double cellsize_m;
00166
00167 int dXY[NAVXYTHETACARTLAT_DXYWIDTH][2];
00168
00169 EnvNAVXYTHETACARTLATAction_t** ActionsV;
00170 vector<EnvNAVXYTHETACARTLATAction_t*>* PredActionsV;
00171
00172 int actionwidth;
00173 vector<SBPL_xythetacart_mprimitive> mprimV;
00174
00175 vector<sbpl_2Dpt_t> FootprintPolygon;
00176 vector<sbpl_2Dpt_t> CartPolygon;
00177 sbpl_2Dpt_t CartOffset;
00178 sbpl_2Dpt_t CartCenterOffset;
00179 } EnvNAVXYTHETACARTLATConfig_t;
00180
00181
00182
00183 class SBPL2DGridSearch;
00184
00189 class EnvironmentNAVXYTHETACARTLATTICE : public DiscreteSpaceInformation
00190 {
00191
00192 public:
00193
00194 EnvironmentNAVXYTHETACARTLATTICE();
00195
00203
00204 bool InitializeEnv(const char* sEnvFile, const vector<sbpl_2Dpt_t>& perimeterptsV, const vector<sbpl_2Dpt_t>& cartperimeterptsV, sbpl_2Dpt_t &cart_offset, const char* sMotPrimFile);
00208 bool InitializeEnv(const char* sEnvFile);
00212 virtual bool SetEnvParameter(const char* parameter, int value);
00216 virtual int GetEnvParameter(const char* parameter);
00220 bool InitializeMDPCfg(MDPConfig *MDPCfg);
00224 virtual int GetFromToHeuristic(int FromStateID, int ToStateID) = 0;
00228 virtual int GetGoalHeuristic(int stateID) = 0;
00232 virtual int GetStartHeuristic(int stateID) = 0;
00236 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state) = 0;
00240 virtual void SetAllPreds(CMDPSTATE* state);
00244 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV);
00248 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV) = 0;
00249
00253 virtual void EnsureHeuristicsUpdated(bool bGoalHeuristics);
00254
00258 void PrintEnv_Config(FILE* fOut);
00259
00277 bool InitializeEnv(int width, int height,
00279 const unsigned char* mapdata,
00280 double startx, double starty, double starttheta, double startcartangle,
00281 double goalx, double goaly, double goaltheta, double goalcartangle,
00282 double goaltol_x, double goaltol_y, double goaltol_theta, double goaltol_cartangle,
00283 const vector<sbpl_2Dpt_t> & perimeterptsV,
00284 const sbpl_2Dpt_t & cart_offset,
00285 const vector<sbpl_2Dpt_t> & cartptsV,
00286 double cellsize_m, double nominalvel_mpersecs, double timetoturn45degsinplace_secs,
00287 unsigned char obsthresh, const char* sMotPrimFile);
00291 bool UpdateCost(int x, int y, unsigned char newcost);
00297 virtual void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV) = 0;
00301 virtual void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV) = 0;
00302
00306 bool IsObstacle(int x, int y);
00311 bool IsValidConfiguration(int X, int Y, int Theta, int CartAngle);
00312
00316
00317 void GetEnvParms(int *size_x, int *size_y,
00318 double* startx, double* starty, double*starttheta, double*startcartangle,
00319 double* goalx, double* goaly, double* goaltheta, double*goalcartangle,
00320 double* cellsize_m, double* nominalvel_mpersecs,
00321 double* timetoturn45degsinplace_secs, unsigned char* obsthresh,
00322 vector<SBPL_xythetacart_mprimitive>* mprimitiveV);
00323
00327 const EnvNAVXYTHETACARTLATConfig_t* GetEnvNavConfig();
00328
00329
00330 virtual ~EnvironmentNAVXYTHETACARTLATTICE();
00334 void PrintTimeStat(FILE* fOut);
00338 unsigned char GetMapCost(int x, int y);
00339
00343 bool IsWithinMapCell(int X, int Y);
00344
00345
00348 virtual void PrintVars(){};
00349
00350 bool initialized_;
00351
00352 protected:
00353
00354 virtual int GetActionCost(int SourceX, int SourceY, int SourceTheta, int SourceCartAngle, EnvNAVXYTHETACARTLATAction_t* action);
00355
00356
00357
00358 EnvNAVXYTHETACARTLATConfig_t EnvNAVXYTHETACARTLATCfg;
00359 EnvironmentNAVXYTHETACARTLAT_t EnvNAVXYTHETACARTLAT;
00360 vector<EnvNAVXYTHETACARTLAT3Dcell_t> affectedsuccstatesV;
00361 vector<EnvNAVXYTHETACARTLAT3Dcell_t> affectedpredstatesV;
00362 int iteration;
00363
00364
00365 bool bNeedtoRecomputeStartHeuristics;
00366 bool bNeedtoRecomputeGoalHeuristics;
00367 SBPL2DGridSearch* grid2Dsearchfromstart;
00368 SBPL2DGridSearch* grid2Dsearchfromgoal;
00369
00370 virtual void ReadConfiguration(FILE* fCfg);
00371
00372 void InitializeEnvConfig(vector<SBPL_xythetacart_mprimitive>* motionprimitiveV);
00373
00374
00375 bool CheckQuant(FILE* fOut);
00376
00377 void SetConfiguration(int width, int height,
00379 const unsigned char* mapdata,
00380 int startx, int starty, int starttheta, int startcartangle,
00381 int goalx, int goaly, int goaltheta, int goalcartangle,
00382 double cellsize_m, double nominalvel_mpersecs,
00383 double timetoturn45degsinplace_secs,
00384 const vector<sbpl_2Dpt_t> & robot_perimeterV,
00385 const vector<sbpl_2Dpt_t> & cart_perimeterV,
00386 const sbpl_2Dpt_t &cart_offset);
00387
00388 bool InitGeneral( vector<SBPL_xythetacart_mprimitive>* motionprimitiveV);
00389 void PrecomputeActionswithBaseMotionPrimitive(vector<SBPL_xythetacart_mprimitive>* motionprimitiveV);
00390 void PrecomputeActionswithCompleteMotionPrimitive(vector<SBPL_xythetacart_mprimitive>* motionprimitiveV);
00391 void PrecomputeActions();
00392
00393 void CreateStartandGoalStates();
00394
00395 virtual void InitializeEnvironment() = 0;
00396
00397 void ComputeHeuristicValues();
00398
00399 bool IsValidCell(int X, int Y);
00400
00401 void CalculateFootprintForPose(EnvNAVXYTHETACARTLAT3Dpt_t pose, vector<sbpl_2Dcell_t>* footprint);
00402 void RemoveSourceFootprint(EnvNAVXYTHETACARTLAT3Dpt_t sourcepose, vector<sbpl_2Dcell_t>* footprint);
00403
00404 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<EnvNAVXYTHETACARTLATAction_t*>* actionindV=NULL) = 0;
00405
00406 double EuclideanDistance_m(int X1, int Y1, int X2, int Y2);
00407
00408 void ComputeReplanningData();
00409 void ComputeReplanningDataforAction(EnvNAVXYTHETACARTLATAction_t* action);
00410
00411 bool ReadMotionPrimitives(FILE* fMotPrims);
00412 bool ReadinMotionPrimitive(SBPL_xythetacart_mprimitive* pMotPrim, FILE* fIn);
00413 bool ReadinCell(EnvNAVXYTHETACARTLAT3Dcell_t* cell, FILE* fIn);
00414 bool ReadinPose(EnvNAVXYTHETACARTLAT3Dpt_t* pose, FILE* fIn);
00415
00416 void PrintHeuristicValues();
00417 void PrintFootprint();
00418 EnvNAVXYTHETACARTLAT3Dpt_t getCartCenter(EnvNAVXYTHETACARTLAT3Dpt_t pose, sbpl_2Dpt_t cart_center_offset);
00419
00420 };
00421
00422
00423 class EnvironmentNAVXYTHETACARTLAT : public EnvironmentNAVXYTHETACARTLATTICE
00424 {
00425
00426 public:
00427 EnvironmentNAVXYTHETACARTLAT()
00428 {
00429 HashTableSize = 0;
00430 Coord2StateIDHashTable = NULL;
00431 Coord2StateIDHashTable_lookup = NULL;
00432 };
00433
00434 ~EnvironmentNAVXYTHETACARTLAT();
00435
00438 int SetStart(double x, double y, double theta, double cartangle);
00441 int SetGoal(double x, double y, double theta, double cartangle);
00444 void SetGoalTolerance(double tol_x, double tol_y, double tol_theta, double tol_cartangle) { }
00447 void GetCoordFromState(int stateID, int& x, int& y, int& theta, int& cartangle) const;
00450 int GetStateFromCoord(int x, int y, int theta, int cartangle);
00451
00455 bool ConvertStateIDPathintoXYThetaPath(vector<int>* stateIDPath, vector<EnvNAVXYTHETACARTLAT3Dpt_t>* xythetaPath);
00458 void PrintState(int stateID, bool bVerbose, FILE* fOut=NULL);
00461 virtual void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV);
00465 virtual void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV, vector<EnvNAVXYTHETACARTLATAction_t*>* actionindV=NULL);
00466
00471 void GetPredsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *preds_of_changededgesIDV);
00474 void GetSuccsofChangedEdges(vector<nav2dcell_t> const * changedcellsV, vector<int> *succs_of_changededgesIDV);
00475
00478 virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state);
00479
00482 virtual int GetFromToHeuristic(int FromStateID, int ToStateID);
00485 virtual int GetGoalHeuristic(int stateID);
00488 virtual int GetStartHeuristic(int stateID);
00489
00492 virtual int SizeofCreatedEnv();
00495 virtual void PrintVars(){};
00496
00497 protected:
00498
00499
00500 int HashTableSize;
00501 vector<EnvNAVXYTHETACARTLATHashEntry_t*>* Coord2StateIDHashTable;
00502
00503 vector<EnvNAVXYTHETACARTLATHashEntry_t*> StateID2CoordTable;
00504
00505 EnvNAVXYTHETACARTLATHashEntry_t** Coord2StateIDHashTable_lookup;
00506
00507 unsigned int GETHASHBIN(unsigned int X, unsigned int Y, unsigned int Theta, unsigned int CartAngle);
00508
00509 EnvNAVXYTHETACARTLATHashEntry_t* GetHashEntry_hash(int X, int Y, int Theta, int CartAngle);
00510 EnvNAVXYTHETACARTLATHashEntry_t* CreateNewHashEntry_hash(int X, int Y, int Theta, int CartAngle);
00511 EnvNAVXYTHETACARTLATHashEntry_t* GetHashEntry_lookup(int X, int Y, int Theta, int CartAngle);
00512 EnvNAVXYTHETACARTLATHashEntry_t* CreateNewHashEntry_lookup(int X, int Y, int Theta, int CartAngle);
00513
00514
00515 EnvNAVXYTHETACARTLATHashEntry_t* (EnvironmentNAVXYTHETACARTLAT::*GetHashEntry)(int X, int Y, int Theta, int CartAngle);
00516 EnvNAVXYTHETACARTLATHashEntry_t* (EnvironmentNAVXYTHETACARTLAT::*CreateNewHashEntry)(int X, int Y, int Theta, int CartAngle);
00517
00518
00519 virtual void InitializeEnvironment();
00520
00521 void PrintHashTableHist(FILE* fOut);
00522
00523
00524 };
00525
00526
00527 #endif
00528