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
00032 #include <iostream>
00033 #include <sbpl_arm_planner/robarm3d/environment_robarm3d.h>
00034 #include <ros/ros.h>
00035
00036 #define MAX_RUNTIME 200.0
00037 #define NUM_JOINTS 7
00038
00044 void PrintUsage(char *argv[])
00045 {
00046 printf("SBPL Arm Planner Test Program\n\n");
00047 printf("Usage: %s [arguments] <cfg file>\n\n", argv[0]);
00048
00049 printf("Arguments:\n");
00050 printf(" -A ARA* - Anytime Repairing A* (default)\n");
00051 printf(" -R R* - Random A*\n\n");
00052 }
00053
00054 int planRobarm(int argc, char *argv[])
00055 {
00056 int bRet = 0, env_arg = 4;
00057 int sol_cost;
00058 double allocated_time_secs = MAX_RUNTIME;
00059 MDPConfig MDPCfg;
00060 SBPLPlanner *planner;
00061 int planner_type = 0;
00062 std::string args(argv[1]);
00063 std::string arm_desc_filename("./config/pr2_right_arm.cfg"), params_filename("./config/params.cfg");
00064
00065 bool save_traj = false;
00066 char* name = NULL;
00067 char* path = NULL;
00068
00069
00070 if(argc > 2)
00071 {
00072 if(args.at(0) == '-')
00073 {
00074
00075 if(args.find_first_of('R') != std::string::npos)
00076 planner_type = 1;
00077
00078 else if(args.find_first_of('N') != std::string::npos)
00079 {
00080 save_traj = true;
00081 if(argc < 4)
00082 {
00083 printf("Argument '-N' must be accompanied by a path and a test name.\n");
00084 return 0;
00085 }
00086 path = argv[2];
00087 name = argv[3];
00088 }
00089
00090
00091 if(argc > 5)
00092 params_filename = std::string(argv[5]);
00093
00094
00095 if (argc > 6)
00096 arm_desc_filename = std::string(argv[6]);
00097 }
00098 }
00099 else
00100 env_arg = 1;
00101
00102
00103 sbpl_arm_planner::EnvironmentROBARM3D environment_robarm;
00104
00105 if(!environment_robarm.InitializeEnv(argv[env_arg], params_filename, arm_desc_filename))
00106 {
00107 printf("ERROR: InitializeEnv failed\n");
00108 return 0;
00109 }
00110
00111
00112 if(!environment_robarm.InitializeMDPCfg(&MDPCfg))
00113 {
00114 printf("ERROR: InitializeMDPCfg failed\n");
00115 exit(1);
00116 }
00117
00118
00119 clock_t starttime = clock();
00120
00121 vector<int> solution_stateIDs_V;
00122 bool bforwardsearch = true;
00123
00124 if(planner_type == 1)
00125 {
00126 environment_robarm.SetEnvParameter("useRSTAR", 1.0);
00127 planner = new RSTARPlanner(&environment_robarm, bforwardsearch);
00128 }
00129 else
00130 {
00131 environment_robarm.SetEnvParameter("useRSTAR",0);
00132 planner = new ARAPlanner(&environment_robarm, bforwardsearch);
00133 }
00134
00135 if(planner->set_start(MDPCfg.startstateid) == 0)
00136 {
00137 printf("ERROR: failed to set start state\n");
00138 exit(1);
00139 }
00140
00141 if(planner->set_goal(MDPCfg.goalstateid) == 0)
00142 {
00143 printf("ERROR: failed to set goal state\n");
00144 exit(1);
00145 }
00146
00147
00148 planner->set_initialsolution_eps(environment_robarm.getEpsilon());
00149
00150
00151 planner->set_search_mode(false);
00152
00153
00154 printf("start planning...\n");
00155 bRet = planner->replan(allocated_time_secs, &solution_stateIDs_V,&sol_cost);
00156 printf("completed in %.4f seconds.\n", double(clock()-starttime) / CLOCKS_PER_SEC);
00157
00158 environment_robarm.debugAdaptiveMotionPrims();
00159
00160
00161 FILE* afid = fopen("./config/pr2_right_arm.cfg","r");
00162 SBPLArmModel arm(afid);
00163 arm.initKDLChainFromParamServer();
00164
00165 std::vector<double> pose;
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 printf("\ndone\n");
00229
00230 return bRet;
00231 }
00232
00233 int main(int argc, char *argv[])
00234 {
00235 if(argc < 2)
00236 {
00237 PrintUsage(argv);
00238 exit(1);
00239 }
00240
00241 ros::init(argc, argv, "sbpl_arm_planner");
00242
00243 planRobarm(argc, argv);
00244
00245 return 0;
00246 }
00247