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 #include <iostream>
00030 using namespace std;
00031
00032 #include <sbpl/headers.h>
00033 #include <sbpl_dynamic_planner/envInterval.h>
00034 #include <sbpl_dynamic_planner/envDBubble.h>
00035 #include <sbpl_dynamic_planner/envTime.h>
00036 #include <sbpl_dynamic_planner/weightedAStar.h>
00037 #include <sbpl_dynamic_planner/intervalPlanner.h>
00038
00039
00040 void PrintUsage(char *argv[])
00041 {
00042 printf("USAGE: %s <cfg file>\n", argv[0]);
00043 }
00044
00045
00046 int planxythetalat(int argc, char *argv[])
00047 {
00048
00049 int bRet = 0;
00050 double allocated_time_secs = 0.3;
00051 bool bsearchuntilfirstsolution = true;
00052
00053
00054 vector<sbpl_2Dpt_t> perimeterptsV;
00055 sbpl_2Dpt_t pt_m;
00056 double halfwidth = 0.01;
00057 double halflength = 0.01;
00058 pt_m.x = -halflength;
00059 pt_m.y = -halfwidth;
00060 perimeterptsV.push_back(pt_m);
00061 pt_m.x = halflength;
00062 pt_m.y = -halfwidth;
00063 perimeterptsV.push_back(pt_m);
00064 pt_m.x = halflength;
00065 pt_m.y = halfwidth;
00066 perimeterptsV.push_back(pt_m);
00067 pt_m.x = -halflength;
00068 pt_m.y = halfwidth;
00069 perimeterptsV.push_back(pt_m);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 EnvironmentNAVXYTHETALAT environment_navxythetalat;
00080
00081 if(argc >= 3)
00082 {
00083 if(!environment_navxythetalat.InitializeEnv(argv[1], perimeterptsV, argv[2]))
00084 {
00085 printf("ERROR: InitializeEnv failed\n");
00086 exit(1);
00087 }
00088 }
00089 else
00090 {
00091 if(!environment_navxythetalat.InitializeEnv(argv[1], perimeterptsV, NULL))
00092 {
00093 printf("ERROR: InitializeEnv failed\n");
00094 exit(1);
00095 }
00096 }
00097
00098
00099 vector<int> solution_stateIDs_V;
00100 bool bforwardsearch = true;
00101 ARAPlanner planner(&environment_navxythetalat, bforwardsearch);
00102 planner.set_initialsolution_eps(1.0);
00103
00104
00105 planner.set_search_mode(bsearchuntilfirstsolution);
00106
00107 if(planner.set_start(environment_navxythetalat.SetStart(0.0,0.0,0.6)) == 0)
00108
00109 {
00110 printf("ERROR: failed to set start state\n");
00111 exit(1);
00112 }
00113 if(planner.set_goal(environment_navxythetalat.SetGoal(0.36,0.36,0.6)) == 0)
00114
00115 {
00116 printf("ERROR: failed to set start state\n");
00117 exit(1);
00118 }
00119
00120
00121 printf("start planning...\n");
00122 bRet = planner.replan(allocated_time_secs, &solution_stateIDs_V);
00123 printf("done planning\n");
00124 std::cout << "size of solution=" << solution_stateIDs_V.size() << std::endl;
00125
00126 environment_navxythetalat.PrintTimeStat(stdout);
00127
00128
00129 FILE* fSol = fopen("sol.txt", "w");
00130 vector<EnvNAVXYTHETALAT3Dpt_t> xythetaPath;
00131 environment_navxythetalat.ConvertStateIDPathintoXYThetaPath(&solution_stateIDs_V, &xythetaPath);
00132 printf("solution size=%d\n", (int)xythetaPath.size());
00133 for(unsigned int i = 0; i < xythetaPath.size(); i++) {
00134 fprintf(fSol, "%.3f %.3f %.3f\n", xythetaPath.at(i).x, xythetaPath.at(i).y, xythetaPath.at(i).theta);
00135 }
00136 fclose(fSol);
00137
00138 environment_navxythetalat.PrintTimeStat(stdout);
00139
00140
00141 if(bRet)
00142 {
00143
00144 printf("Solution is found\n");
00145 }
00146 else
00147 printf("Solution does not exist\n");
00148
00149 fflush(NULL);
00150
00151
00152 return bRet;
00153 }
00154
00155
00156 int planxythetatimelat(int argc, char *argv[])
00157 {
00158
00159 int bRet = 0;
00160 double allocated_time_secs = 0.3;
00161 bool bsearchuntilfirstsolution = true;
00162
00163
00164 vector<sbpl_2Dpt_t> perimeterptsV;
00165 sbpl_2Dpt_t pt_m;
00166 double halfwidth = 0.01;
00167 double halflength = 0.01;
00168 pt_m.x = -halflength;
00169 pt_m.y = -halfwidth;
00170 perimeterptsV.push_back(pt_m);
00171 pt_m.x = halflength;
00172 pt_m.y = -halfwidth;
00173 perimeterptsV.push_back(pt_m);
00174 pt_m.x = halflength;
00175 pt_m.y = halfwidth;
00176 perimeterptsV.push_back(pt_m);
00177 pt_m.x = -halflength;
00178 pt_m.y = halfwidth;
00179 perimeterptsV.push_back(pt_m);
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 EnvironmentNAVXYTHETATIMELAT environment_navxythetatimelat;
00190
00191 if(argc >= 4){
00192 if(!environment_navxythetatimelat.InitializeEnv(argv[2], perimeterptsV, argv[4], argv[5])){
00193 printf("ERROR: InitializeEnv failed\n");
00194 exit(1);
00195 }
00196 }
00197 else{
00198 printf("Please provide three arguments: environmentFile motionPrimitiveFile dynamicObstacleFile\n");
00199 exit(1);
00200 }
00201
00202
00203 vector<int> solution_stateIDs_V;
00204 bool bforwardsearch = true;
00205 WeightedAStar planner(&environment_navxythetatimelat, bforwardsearch);
00206
00207 planner.set_initialsolution_eps(1.0);
00208
00209
00210 planner.set_search_mode(bsearchuntilfirstsolution);
00211
00212
00213
00214 if(planner.set_start(environment_navxythetatimelat.getStartID()) == 0)
00215 {
00216 printf("ERROR: failed to set start state\n");
00217 exit(1);
00218 }
00219
00220
00221
00222 if(planner.set_goal(environment_navxythetatimelat.getGoalID()) == 0)
00223 {
00224 printf("ERROR: failed to set start state\n");
00225 exit(1);
00226 }
00227
00228
00229 printf("start planning...\n");
00230 bRet = planner.replan(allocated_time_secs, &solution_stateIDs_V);
00231 printf("done planning\n");
00232 std::cout << "size of solution=" << solution_stateIDs_V.size() << std::endl;
00233
00234 environment_navxythetatimelat.PrintTimeStat(stdout);
00235
00236 FILE* fSol = fopen("sol.txt", "w");
00237 vector<SBPL_4Dpt_t> xythetatimePath;
00238 environment_navxythetatimelat.ConvertStateIDPathintoXYThetaPath(&solution_stateIDs_V, &xythetatimePath);
00239 printf("solution size=%d\n", (int)xythetatimePath.size());
00240 for(unsigned int i = 0; i < xythetatimePath.size(); i++) {
00241 fprintf(fSol, "%.3f %.3f %.3f %.3f\n", xythetatimePath.at(i).x, xythetatimePath.at(i).y, xythetatimePath.at(i).theta, xythetatimePath.at(i).t);
00242 }
00243 fclose(fSol);
00244
00245 environment_navxythetatimelat.PrintTimeStat(stdout);
00246
00247
00248 if(bRet)
00249 {
00250
00251 printf("Solution is found\n");
00252 }
00253 else
00254 printf("Solution does not exist\n");
00255
00256 fflush(NULL);
00257
00258
00259 return bRet;
00260 }
00261
00262 int planxythetatimebubblelat(int argc, char *argv[])
00263 {
00264
00265 int bRet = 0;
00266 double allocated_time_secs = 1200.0;
00267 bool bsearchuntilfirstsolution = true;
00268
00269
00270 vector<sbpl_2Dpt_t> perimeterptsV;
00271 sbpl_2Dpt_t pt_m;
00272 double halfwidth = 0.01;
00273 double halflength = 0.01;
00274 pt_m.x = -halflength;
00275 pt_m.y = -halfwidth;
00276 perimeterptsV.push_back(pt_m);
00277 pt_m.x = halflength;
00278 pt_m.y = -halfwidth;
00279 perimeterptsV.push_back(pt_m);
00280 pt_m.x = halflength;
00281 pt_m.y = halfwidth;
00282 perimeterptsV.push_back(pt_m);
00283 pt_m.x = -halflength;
00284 pt_m.y = halfwidth;
00285 perimeterptsV.push_back(pt_m);
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 EnvDBubbleLat environment_navxythetatimebubblelat;
00296
00297
00298
00299
00300
00301
00302
00303 if(argc >= 4){
00304 if(!environment_navxythetatimebubblelat.InitializeEnv(argv[1], perimeterptsV, argv[2], argv[3])){
00305 printf("ERROR: InitializeEnv failed\n");
00306 exit(1);
00307 }
00308 }
00309 else{
00310 printf("Please provide three arguments: environmentFile motionPrimitiveFile dynamicObstacleFile\n");
00311 exit(1);
00312 }
00313
00314
00315 vector<int> solution_stateIDs_V;
00316 bool bforwardsearch = true;
00317 WeightedAStar planner(&environment_navxythetatimebubblelat, bforwardsearch);
00318
00319 planner.set_initialsolution_eps(1.0);
00320
00321
00322 planner.set_search_mode(bsearchuntilfirstsolution);
00323
00324
00325
00326 if(planner.set_start(environment_navxythetatimebubblelat.getStartID()) == 0)
00327 {
00328 printf("ERROR: failed to set start state\n");
00329 exit(1);
00330 }
00331
00332
00333
00334 if(planner.set_goal(environment_navxythetatimebubblelat.getGoalID()) == 0)
00335 {
00336 printf("ERROR: failed to set start state\n");
00337 exit(1);
00338 }
00339
00340
00341 printf("start planning...\n");
00342 bRet = planner.replan(allocated_time_secs, &solution_stateIDs_V);
00343 printf("done planning\n");
00344 std::cout << "size of solution=" << solution_stateIDs_V.size() << std::endl;
00345
00346 environment_navxythetatimebubblelat.PrintTimeStat(stdout);
00347
00348 FILE* fSol = fopen("sol.txt", "w");
00349 vector<SBPL_4Dpt_t> xythetatimePath;
00350 environment_navxythetatimebubblelat.ConvertStateIDPathintoXYThetaPath(&solution_stateIDs_V, &xythetatimePath);
00351 printf("solution size=%d\n", (int)xythetatimePath.size());
00352 for(unsigned int i = 0; i < xythetatimePath.size(); i++) {
00353 fprintf(fSol, "%.3f %.3f %.3f %.3f\n", xythetatimePath.at(i).x, xythetatimePath.at(i).y, xythetatimePath.at(i).theta, xythetatimePath.at(i).t);
00354 }
00355 fclose(fSol);
00356
00357 environment_navxythetatimebubblelat.PrintTimeStat(stdout);
00358
00359
00360 if(bRet)
00361 {
00362
00363 printf("Solution is found\n");
00364 }
00365 else
00366 printf("Solution does not exist\n");
00367
00368 fflush(NULL);
00369
00370
00371
00372 return bRet;
00373 }
00374
00375
00376 int planIntervallat(int argc, char *argv[], double eps)
00377 {
00378
00379 int bRet = 0;
00380 double allocated_time_secs = 1200.0;
00381 bool bsearchuntilfirstsolution = true;
00382
00383
00384 vector<sbpl_2Dpt_t> perimeterptsV;
00385 sbpl_2Dpt_t pt_m;
00386 double halfwidth = 0.01;
00387 double halflength = 0.01;
00388 pt_m.x = -halflength;
00389 pt_m.y = -halfwidth;
00390 perimeterptsV.push_back(pt_m);
00391 pt_m.x = halflength;
00392 pt_m.y = -halfwidth;
00393 perimeterptsV.push_back(pt_m);
00394 pt_m.x = halflength;
00395 pt_m.y = halfwidth;
00396 perimeterptsV.push_back(pt_m);
00397 pt_m.x = -halflength;
00398 pt_m.y = halfwidth;
00399 perimeterptsV.push_back(pt_m);
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 EnvIntervalLat environment_navIntervallat;
00410
00411
00412
00413
00414
00415
00416
00417 if(argc >= 4){
00418 if(!environment_navIntervallat.InitializeEnv(argv[1], perimeterptsV, argv[2], argv[3])){
00419 printf("ERROR: InitializeEnv failed\n");
00420 exit(1);
00421 }
00422 }
00423 else{
00424 printf("Please provide three arguments: environmentFile motionPrimitiveFile dynamicObstacleFile\n");
00425 exit(1);
00426 }
00427
00428
00429 vector<int> solution_stateIDs_V;
00430 bool bforwardsearch = true;
00431 IntervalPlanner planner(&environment_navIntervallat);
00432
00433 planner.set_initialsolution_eps(eps);
00434
00435
00436 planner.set_search_mode(bsearchuntilfirstsolution);
00437
00438
00439
00440 if(planner.set_start(environment_navIntervallat.getStartID()) == 0)
00441 {
00442 printf("ERROR: failed to set start state\n");
00443 exit(1);
00444 }
00445
00446
00447
00448 if(planner.set_goal(environment_navIntervallat.getGoalID()) == 0)
00449 {
00450 printf("ERROR: failed to set start state\n");
00451 exit(1);
00452 }
00453
00454
00455 printf("start planning...\n");
00456 bRet = planner.replan(allocated_time_secs, &solution_stateIDs_V);
00457 printf("done planning\n");
00458 std::cout << "size of solution=" << solution_stateIDs_V.size() << std::endl;
00459
00460 environment_navIntervallat.PrintTimeStat(stdout);
00461
00462 FILE* fSol = fopen("sol.txt", "w");
00463 vector<SBPL_4Dpt_t> xythetatimePath;
00464 environment_navIntervallat.ConvertStateIDPathintoXYThetaPath(&solution_stateIDs_V, &xythetatimePath);
00465 printf("solution size=%d\n", (int)xythetatimePath.size());
00466 for(unsigned int i = 0; i < xythetatimePath.size(); i++) {
00467 fprintf(fSol, "%.3f %.3f %.3f %.3f\n", xythetatimePath.at(i).x, xythetatimePath.at(i).y, xythetatimePath.at(i).theta, xythetatimePath.at(i).t);
00468 }
00469 fclose(fSol);
00470
00471 environment_navIntervallat.PrintTimeStat(stdout);
00472
00473
00474 if(bRet)
00475 {
00476
00477 printf("Solution is found\n");
00478 }
00479 else
00480 printf("Solution does not exist\n");
00481
00482 fflush(NULL);
00483
00484 environment_navIntervallat.dumpStatesToFile();
00485
00486 return bRet;
00487 }
00488
00489
00490 int main(int argc, char *argv[])
00491 {
00492
00493 if(argc < 2){
00494 PrintUsage(argv);
00495 exit(1);
00496 }
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 planIntervallat(argc, argv,1.0);
00510
00511 return 0;
00512 }
00513
00514
00515
00516
00517