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
00031 #include <iostream>
00032 #include <sbpl_arm_planner/robarm3d/environment_robarm3d.h>
00033 #include <ros/ros.h>
00034
00035 #define VERBOSE 1
00036 #define MAX_RUNTIME 10.0
00037
00043 void PrintUsage(char *argv[])
00044 {
00045 printf("SBPL Arm Planner Test Program\n\n");
00046 printf("Usage: %s [arguments] <cfg file>\n\n", argv[0]);
00047
00048 printf("Arguments:\n");
00049 printf(" -A ARA* - Anytime Repairing A* (default)\n");
00050 printf(" -R R* - Random A*\n\n");
00051 }
00052
00053 int planRobarm(int argc, char *argv[])
00054 {
00055 int bRet = 0, env_arg = 2;
00056 double allocated_time_secs = MAX_RUNTIME;
00057 MDPConfig MDPCfg;
00058 SBPLPlanner *planner;
00059 int planner_type = 0;
00060 std::string args(argv[1]);
00061
00062
00063 if(argc > 2)
00064 {
00065 if(args.at(0) == '-')
00066
00067 if(args.find_first_of('R') != std::string::npos)
00068 planner_type = 1;
00069 }
00070 else
00071 env_arg = 1;
00072
00073 clock_t totaltime = clock();
00074
00075
00076 sbpl_arm_planner::EnvironmentROBARM3D environment_robarm;
00077
00078 if(!environment_robarm.InitializeEnv(argv[env_arg]))
00079 {
00080 printf("ERROR: InitializeEnv failed\n");
00081 return 0;
00082 }
00083
00084
00085 if(!environment_robarm.InitializeMDPCfg(&MDPCfg))
00086 {
00087 printf("ERROR: InitializeMDPCfg failed\n");
00088 return 0;
00089 }
00090
00091
00092 clock_t starttime = clock();
00093
00094 vector<int> solution_stateIDs_V;
00095 bool bforwardsearch = true;
00096
00097 if(planner_type == 1)
00098 {
00099 environment_robarm.SetEnvParameter("useRSTAR", 1.0);
00100 planner = new RSTARPlanner(&environment_robarm, bforwardsearch);
00101 }
00102 else
00103 {
00104 environment_robarm.SetEnvParameter("useRSTAR",0);
00105 planner = new ARAPlanner(&environment_robarm, bforwardsearch);
00106 }
00107
00108 if(planner->set_start(MDPCfg.startstateid) == 0)
00109 {
00110 printf("ERROR: failed to set start state\n");
00111 return 0;
00112 }
00113
00114 if(planner->set_goal(MDPCfg.goalstateid) == 0)
00115 {
00116 printf("ERROR: failed to set goal state\n");
00117 return 0;
00118 }
00119
00120
00121 planner->set_initialsolution_eps(environment_robarm.getEpsilon());
00122
00123
00124 planner->set_search_mode(false);
00125
00126 int sol_cost;
00127 printf("start planning...\n");
00128 bRet = planner->replan(allocated_time_secs, &solution_stateIDs_V,&sol_cost);
00129
00130 printf("completed in %.4f seconds.\n", double(clock()-starttime) / CLOCKS_PER_SEC);
00131
00132
00133
00134 printf("done planning\n");
00135 std::cout << "size of solution=" << solution_stateIDs_V.size() << std::endl;
00136 std::cout << "cost of solution=" << sol_cost << std::endl;
00137
00138 printf("\ntotal planning time is %.4f seconds.\n", double(clock()-totaltime) / CLOCKS_PER_SEC);
00139
00140
00141 string outputfile = "sol";
00142 outputfile.append(".txt");
00143
00144 FILE* fSol = fopen(outputfile.c_str(), "w");
00145 for(unsigned int i = 0; i < solution_stateIDs_V.size(); i++)
00146 environment_robarm.PrintState(solution_stateIDs_V[i], true, fSol);
00147
00148 fclose(fSol);
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 return bRet;
00165 }
00166
00167 int main(int argc, char *argv[])
00168 {
00169 if(argc < 2)
00170 {
00171 PrintUsage(argv);
00172 return 0;
00173 }
00174
00175 ros::init(argc, argv, "actual_arm_planner");
00176
00177 if(!planRobarm(argc, argv))
00178 {
00179 printf("Planning failed\n");
00180 return 0;
00181 }
00182
00183
00184 return 1;
00185 }
00186