stomp_valgrind.cpp
Go to the documentation of this file.
00001 
00026 #include <kdl_parser/kdl_parser.hpp>
00027 #include <ros/ros.h>
00028 #include <ros/package.h>
00029 #include <ros/console.h>
00030 #include <string.h>
00031 #include <moveit/robot_model_loader/robot_model_loader.h>
00032 #include <moveit/robot_model/joint_model_group.h>
00033 #include <moveit/robot_state/conversions.h>
00034 #include <moveit/kinematic_constraints/kinematic_constraint.h>
00035 #include <moveit/kinematic_constraints/utils.h>
00036 #include <moveit/collision_plugin_loader/collision_plugin_loader.h>
00037 #include <stomp_moveit/stomp_planner.h>
00038 #include <fstream>
00039 
00040 using namespace ros;
00041 using namespace stomp_moveit;
00042 using namespace Eigen;
00043 using namespace moveit::core;
00044 using namespace std;
00045 
00046 int main (int argc, char *argv[])
00047 {
00048   ros::init(argc,argv,"stomp_valgrid");
00049   ros::NodeHandle pnh;
00050 
00051 
00052   if (ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug))
00053      ros::console::notifyLoggerLevelsChanged();
00054 
00055   sleep(3);
00056   map<string, XmlRpc::XmlRpcValue> config;
00057   robot_model_loader::RobotModelLoaderPtr loader;
00058   robot_model::RobotModelPtr robot_model;
00059   string urdf_file_path, srdf_file_path;
00060 
00061   urdf_file_path = package::getPath("stomp_test_support") + "/urdf/test_kr210l150_500K.urdf";
00062   srdf_file_path = package::getPath("stomp_test_kr210_moveit_config") + "/config/test_kr210.srdf";
00063 
00064   ifstream ifs1 (urdf_file_path.c_str());
00065   string urdf_string((istreambuf_iterator<char>(ifs1)), (istreambuf_iterator<char>()));
00066 
00067   ifstream ifs2 (srdf_file_path.c_str());
00068   string srdf_string((istreambuf_iterator<char>(ifs2)), (istreambuf_iterator<char>()));
00069 
00070   robot_model_loader::RobotModelLoader::Options opts(urdf_string, srdf_string);
00071   loader.reset(new robot_model_loader::RobotModelLoader(opts));
00072   robot_model = loader->getModel();
00073 
00074   if (!robot_model)
00075   {
00076     ROS_ERROR_STREAM("Unable to load robot model from urdf and srdf.");
00077     return false;
00078   }
00079 
00080   StompPlanner::getConfigData(pnh, config);
00081   planning_scene::PlanningScenePtr planning_scene(new planning_scene::PlanningScene(robot_model));
00082   planning_interface::MotionPlanRequest req;
00083   planning_interface::MotionPlanResponse res;
00084   string group_name = "manipulator_rail";
00085   StompPlanner stomp(group_name, config[group_name], robot_model);
00086 
00087   //Now assign collision detection plugin
00088   collision_detection::CollisionPluginLoader cd_loader;
00089   std::string class_name = "IndustrialFCL";
00090   cd_loader.activate(class_name, planning_scene, true);
00091 
00092   req.allowed_planning_time = 10;
00093   req.num_planning_attempts = 1;
00094   req.group_name = group_name;
00095 
00096   robot_state::RobotState start = planning_scene->getCurrentState();
00097   map<string, double> jstart;
00098   jstart.insert(make_pair("joint_1", 1.4149));
00099   jstart.insert(make_pair("joint_2", 0.5530));
00100   jstart.insert(make_pair("joint_3", 0.1098));
00101   jstart.insert(make_pair("joint_4", -1.0295));
00102   jstart.insert(make_pair("joint_5", 0.0000));
00103   jstart.insert(make_pair("joint_6", 0.0000));
00104   jstart.insert(make_pair("rail_to_base", 1.3933));
00105 
00106   start.setVariablePositions(jstart);
00107   robotStateToRobotStateMsg(start, req.start_state);
00108   req.start_state.is_diff = true;
00109 
00110   robot_state::RobotState goal = planning_scene->getCurrentState();
00111   map<string, double> jgoal;
00112   jgoal.insert(make_pair("joint_1", 1.3060));
00113   jgoal.insert(make_pair("joint_2", -0.2627));
00114   jgoal.insert(make_pair("joint_3", 0.2985));
00115   jgoal.insert(make_pair("joint_4", -0.8236));
00116   jgoal.insert(make_pair("joint_5", 0.0000));
00117   jgoal.insert(make_pair("joint_6", 0.0000));
00118   jgoal.insert(make_pair("rail_to_base", -1.2584));
00119 
00120   goal.setVariablePositions(jgoal);
00121 
00122   vector<double> dist(7);
00123   dist[0] = 0.05;
00124   dist[1] = 0.05;
00125   dist[2] = 0.05;
00126   dist[3] = 0.05;
00127   dist[4] = 0.05;
00128   dist[5] = 0.05;
00129   dist[6] = 0.05;
00130 
00131   ros::Time t1, t2;
00132   t1 = ros::Time::now();
00133   const robot_state::JointModelGroup *jmg = goal.getJointModelGroup(group_name);
00134   int test_runs = 100;
00135   for (int i = 0; i < test_runs; i++)
00136   {
00137     if (jmg)
00138     {
00139       robot_state::RobotState new_goal = goal;
00140       new_goal.setToRandomPositionsNearBy(jmg, goal, dist);
00141       req.goal_constraints.resize(1);
00142       req.goal_constraints[0] = kinematic_constraints::constructGoalConstraints(new_goal, jmg);
00143     }
00144 
00145     stomp.clear();
00146     stomp.setPlanningScene(planning_scene);
00147     stomp.setMotionPlanRequest(req);
00148 
00149     if (!stomp.solve(res))
00150       ROS_ERROR_STREAM("STOMP Solver failed:" << res.error_code_);
00151 
00152   }
00153   t2 = ros::Time::now();
00154 
00155   ROS_ERROR("Average time spent calculating trajectory: %4.10f seconds", (t2-t1).toSec()/test_runs);
00156   return 0;
00157 }


industrial_moveit_benchmarking
Author(s): Levi Armstrong
autogenerated on Sat Jun 8 2019 19:24:11