Go to the documentation of this file.00001 #include "wam_cartesian_planning_alg.h"
00002 namespace ob = ompl::base;
00003 namespace og = ompl::geometric;
00004 WamCartesianPlanningAlgorithm::WamCartesianPlanningAlgorithm(void)
00005 {
00006
00007 space.reset(new ob::SE3StateSpace());
00008
00009 ob::RealVectorBounds bounds(3);
00010 bounds.setLow(-2);
00011 bounds.setHigh(2);
00012 space->as<ob::SE3StateSpace>()->setBounds(bounds);
00013 }
00014
00015 WamCartesianPlanningAlgorithm::~WamCartesianPlanningAlgorithm(void)
00016 {
00017 }
00018
00019 void WamCartesianPlanningAlgorithm::config_update(Config& new_cfg, uint32_t level)
00020 {
00021 this->lock();
00022
00023
00024 this->config_=new_cfg;
00025
00026 this->unlock();
00027 }
00028
00029 bool WamCartesianPlanningAlgorithm::isStateValid(const ob::State *state)
00030 {
00031
00032 const ob::SE3StateSpace::StateType *se3state = state->as<ob::SE3StateSpace::StateType>();
00033
00034
00035 const ob::RealVectorStateSpace::StateType *pos = se3state->as<ob::RealVectorStateSpace::StateType>(0);
00036
00037
00038 const ob::SO3StateSpace::StateType *rot = se3state->as<ob::SO3StateSpace::StateType>(1);
00039
00040
00041
00042
00043
00044 return (void*)rot != (void*)pos;
00045 }
00046
00047 void WamCartesianPlanningAlgorithm::planWithSimpleSetup(ob::ScopedState<ompl::base::SE3StateSpace>& start,ob::ScopedState<ompl::base::SE3StateSpace>& goal, const int& st,std::vector<geometry_msgs::PoseStamped>& vector)
00048 {
00049
00050 og::SimpleSetup ss(space);
00051
00052 ss.setStateValidityChecker(boost::bind(&isStateValid, _1));
00053
00054 std::vector<geometry_msgs::PoseStamped> poses;
00055
00056 ss.setStartAndGoalStates(start, goal);
00057
00058 ss.setup();
00059 ss.print();
00060
00061 bool solved = ss.solve(1.0);
00062 if (solved)
00063 {
00064 std::cout << "Found solution:" << std::endl;
00065
00066 ss.simplifySolution();
00067 og::PathGeometric path=ss.getSolutionPath();
00068 path.interpolate(st);
00069 omplToRos(path,poses);
00070
00071
00072
00073
00074
00075 }
00076
00077 else std::cout << "No solution found" << std::endl;
00078 }
00079
00080 void WamCartesianPlanningAlgorithm::omplToRos(og::PathGeometric& path, std::vector<geometry_msgs::PoseStamped>& vect)
00081 {
00082 geometry_msgs::PoseStamped msg;
00083 for(size_t i=0; i <path.getStates().size(); ++i)
00084 {
00085 msg.pose.position.x=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->getX();
00086 msg.pose.position.y=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->getY();
00087 msg.pose.position.z=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->getZ();
00088 msg.pose.orientation.x=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().x;
00089 msg.pose.orientation.y=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().y;
00090 msg.pose.orientation.z=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().z;
00091 msg.pose.orientation.w=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().w;
00092 vect.push_back(msg);
00093 }
00094 }
00095 void WamCartesianPlanningAlgorithm::writeFile(og::PathGeometric& path,std::string& pathDir)
00096 {
00097 std::ofstream traj;
00098 traj.open(pathDir.c_str(), std::ofstream::out);
00099 float tx,ty,tz,qx,qy,qz,qw;
00100 for(size_t i=0; i <path.getStates().size(); ++i)
00101 {
00102 tx=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->getX();
00103 ty=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->getY();
00104 tz=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->getZ();
00105 qx=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().x;
00106 qy=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().y;
00107 qz=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().z;
00108 qw=path.getStates()[i]->as<ob::SE3StateSpace::StateType>()->rotation().w;
00109
00110 traj<<tx<<" "<<ty<<" "<<tz<<" "<<qx<<" "<<qy<<" "<<qz<<" "<<qw<<"\n";
00111 std::cout<<tx<<" "<<ty<<" "<<tz<<" "<<qx<<" "<<qy<<" "<<qz<<" "<<qw<<std::endl;
00112 }
00113 traj.close();
00114 }