ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Get path from ompl::geometric::PathPtr in OMPL

asked 2015-10-22 03:25:50 -0500

Vlad222 gravatar image

Hi all!

I work with OMPL without MoveIt and I have one simple question. I am not good in boost. I planned path for 6DOF industrial robot. How can I get points of path from ompl::geometric::PathPtr?

namespace ob = ompl::base;
namespace og = ompl::geometric;
namespace oc = ompl::control;  


bool isStateValid(const ob::State *state)
{
float a1 = state->as<ob::RealVectorStateSpace::StateType>()->values[0];
float a2 = state->as<ob::RealVectorStateSpace::StateType>()->values[1];
float a3 = state->as<ob::RealVectorStateSpace::StateType>()->values[2];
float a4 = state->as<ob::RealVectorStateSpace::StateType>()->values[3];
float a5 = state->as<ob::RealVectorStateSpace::StateType>()->values[4];
float a6 = state->as<ob::RealVectorStateSpace::StateType>()->values[5];

cout << "A1 " << a1 << endl;
cout << "A2 " << a2 << endl;
cout << "A3 " << a3 << endl;
cout << "A4 " << a4 << endl;
cout << "A5 " << a5 << endl;
cout << "A6 " << a6 << endl;

if ((abs(a1) > 0.91)||(abs(a2) > 0.91)||(abs(a3) > 0.91)||(abs(a4) > 0.91)||(abs(a5) > 0.91)||(abs(a6) > 0.91))
    return false;
if ((abs(a1) > 0.89)||(abs(a2) > 0.89)||(abs(a3) > 0.89)||(abs(a4) > 0.89)||(abs(a5) > 0.89)||(abs(a6) > 0.89))
    return true;
else
    return false;
}

bool plan_ompl(cut_data & work,rob_ang start_ang,rob_ang finish_ang,vector <rob_ang> & res)
{
// construct the state space we are planning in
ob::StateSpacePtr space(new ob::RealVectorStateSpace(6));

// set the bounds for the R^2 part of SE(2)
ob::RealVectorBounds bounds(6);
bounds.high.push_back(work.kuka.a1_max);
bounds.high.push_back(work.kuka.a2_max);
bounds.high.push_back(work.kuka.a3_max);
bounds.high.push_back(work.kuka.a4_max);
bounds.high.push_back(work.kuka.a5_max);
bounds.high.push_back(work.kuka.a6_max);

bounds.low.push_back(work.kuka.a1_min);
bounds.low.push_back(work.kuka.a2_min);
bounds.low.push_back(work.kuka.a3_min);
bounds.low.push_back(work.kuka.a4_min);
bounds.low.push_back(work.kuka.a5_min);
bounds.low.push_back(work.kuka.a6_min);

space->as<ob::RealVectorStateSpace>()->setBounds(bounds);

// construct an instance of  space information from this state space
ob::SpaceInformationPtr si(new ob::SpaceInformation(space));

// set state validity checking for this space
si->setStateValidityChecker(boost::bind(&isStateValid, _1));

// create a random start state
ob::ScopedState<> start(space);
start.random();
start[0] = start_ang.a1;
start[1] = start_ang.a2;
start[2] = start_ang.a3;
start[3] = start_ang.a4;
start[4] = start_ang.a5;
start[5] = start_ang.a6;

// create a random goal state
ob::ScopedState<> goal(space);
goal.random();
goal[0] = finish_ang.a1;
goal[1] = finish_ang.a2;
goal[2] = finish_ang.a3;
goal[3] = finish_ang.a4;
goal[4] = finish_ang.a5;
goal[5] = finish_ang.a6;

// create a problem instance
ob::ProblemDefinitionPtr pdef(new ob::ProblemDefinition(si));

// set the start and goal states
pdef->setStartAndGoalStates(start, goal);

// create a planner for the defined space
ob::PlannerPtr planner(new og::RRTConnect(si));

// set the problem we are trying to solve for the planner
planner->setProblemDefinition(pdef);

// perform setup steps for the planner
planner->setup();

// print the settings for this space
si->printSettings(std::cout);

// print the problem settings
pdef->print(std::cout);

// attempt to solve the problem within one second of planning time
ob::PlannerStatus solved = planner- ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-10-22 05:30:16 -0500

Vlad222 gravatar image

I understand how to do it!

       og::PathGeometric path( dynamic_cast< const og::PathGeometric& >( *pdef->getSolutionPath()));
       const std::vector< ob::State* > &states = path.getStates();
       ob::State *state;
       for( size_t i = 0 ; i < states.size( ) ; ++i )
       {
        state = states[ i ]->as< ob::State >( );

        rob_ang temp_rob_ang;
        temp_rob_ang.a1 = state->as<ob::RealVectorStateSpace::StateType>()->values[0];
        temp_rob_ang.a2 = state->as<ob::RealVectorStateSpace::StateType>()->values[1];
        temp_rob_ang.a3 = state->as<ob::RealVectorStateSpace::StateType>()->values[2];
        temp_rob_ang.a4 = state->as<ob::RealVectorStateSpace::StateType>()->values[3];
        temp_rob_ang.a5 = state->as<ob::RealVectorStateSpace::StateType>()->values[4];
        temp_rob_ang.a6 = state->as<ob::RealVectorStateSpace::StateType>()->values[5];
        res.push_back(temp_rob_ang);
        }
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-10-22 03:25:50 -0500

Seen: 740 times

Last updated: Oct 22 '15