example_utils.h
00001 #ifndef EXAMPLE_UTILS_H
00002 #define EXAMPLE_UTILS_H
00003 #include "constrained_ik/basic_kin.h"
00004 #include "constrained_ik/constrained_ik.h"
00005 #include "constrained_ik/constrained_ik_utils.h"
00006 #include <moveit/robot_model_loader/robot_model_loader.h>
00007 #include <moveit/collision_plugin_loader/collision_plugin_loader.h>
00008 #include <ros/package.h>
00009 #include <fstream>
00010 
00015 static planning_scene::PlanningScenePtr getExampleRobotData(robot_model_loader::RobotModelLoaderPtr &loader)
00016 {
00017   ros::NodeHandle nh;
00018   std::string urdf_file_path, srdf_file_path;
00019 
00020   urdf_file_path = ros::package::getPath("constrained_ik") + "/test/resources/ur10.urdf";
00021   srdf_file_path = ros::package::getPath("constrained_ik") + "/test/resources/ur10.srdf";
00022 
00023   std::ifstream ifs1 (urdf_file_path.c_str());
00024   std::string urdf_string((std::istreambuf_iterator<char>(ifs1)), (std::istreambuf_iterator<char>()));
00025 
00026   std::ifstream ifs2 (srdf_file_path.c_str());
00027   std::string srdf_string((std::istreambuf_iterator<char>(ifs2)), (std::istreambuf_iterator<char>()));
00028 
00029   robot_model_loader::RobotModelLoader::Options opts(urdf_string, srdf_string);
00030   loader.reset(new robot_model_loader::RobotModelLoader(opts));
00031 
00032   // Create planning scene and assign collision detection plugin
00033   collision_detection::CollisionPluginLoader cd_loader;
00034   planning_scene::PlanningScenePtr planning_scene(new planning_scene::PlanningScene(loader->getModel()));
00035 
00036   std::string class_name = "IndustrialFCL";
00037   cd_loader.setupScene(nh, planning_scene);
00038   cd_loader.activate(class_name, planning_scene, true);
00039   return planning_scene;
00040 }
00041 
00050 static bool evaluteExampleIK(constrained_ik::basic_kin::BasicKin &kin, constrained_ik::Constrained_IK &ik, planning_scene::PlanningScenePtr planning_scene = planning_scene::PlanningScenePtr())
00051 {
00052   ros::NodeHandle nh;
00053   Eigen::Affine3d goalPose, finalPose;
00054   Eigen::VectorXd joints(6);
00055 
00056   // get data from ros param server
00057   std::vector<double> goal_vector, seed_vector;
00058   nh.getParam("/constrained_ik/example/goal", goal_vector);
00059   nh.getParam("/constrained_ik/example/seed", seed_vector);
00060   Eigen::VectorXd goal = Eigen::VectorXd::Map(goal_vector.data(), goal_vector.size());
00061   Eigen::VectorXd seed = Eigen::VectorXd::Map(seed_vector.data(), seed_vector.size());
00062 
00063   constrained_ik::ConstrainedIKConfiguration config;
00064   config = ik.getSolverConfiguration();
00065   config.solver_min_iterations = 5;
00066   ik.setSolverConfiguration(config);
00067 
00068   kin.calcFwdKin(goal, goalPose);
00069 
00070   // Now use the ik solver to see if it can find a joint solution for
00071   // homePose give seed.
00072   if (ik.calcInvKin(goalPose, seed, planning_scene, joints))
00073   {
00074     Eigen::IOFormat vector_fmt(4, 0, ", ", "\n", "[", "]");
00075     ROS_INFO("IK Solution Found");
00076     ROS_INFO_STREAM("Desired Joint State: " << goal.transpose().format(vector_fmt));
00077     ROS_INFO_STREAM("Seed Joint State:    " << seed.transpose().format(vector_fmt));
00078     ROS_INFO_STREAM("Final Joint State:   " << joints.transpose().format(vector_fmt));
00079 
00080     Eigen::IOFormat matrix_fmt(4, 0, ", ", "\n", "                                [", "]");
00081     kin.calcFwdKin(joints, finalPose);
00082     ROS_INFO_STREAM("IK Desired Pose:\n" << goalPose.matrix().format(matrix_fmt));
00083     ROS_INFO_STREAM("IK Final Pose:\n" << finalPose.matrix().format(matrix_fmt));
00084     return true;
00085   }
00086 
00087   ROS_INFO("Unable to find IK Solution");
00088   return false;
00089 }
00090 
00091 #endif // EXAMPLE_UTILS_H


constrained_ik
Author(s): Chris Lewis , Jeremy Zoss , Dan Solomon
autogenerated on Sat Jun 8 2019 19:23:45