44#include "boost/program_options.hpp"
45#include "../PlanarManipulator/PolyWorld.h"
46#include "../PlanarManipulator/PlanarManipulatorPolyWorld.h"
47#include "../PlanarManipulator/PlanarManipulator.h"
48#include "../PlanarManipulator/PlanarManipulatorStateSpace.h"
49#include "../PlanarManipulator/PlanarManipulatorStateValidityChecker.h"
50#include "../PlanarManipulator/PlanarManipulatorIKGoal.h"
51#include "MultiLevelPlanarManipulatorCommon.h"
53#include <ompl/geometric/planners/rrt/RRTConnect.h>
54#include <ompl/geometric/planners/rrt/RRT.h>
55#include <ompl/base/spaces/SE2StateSpace.h>
56#include <ompl/base/spaces/RealVectorStateSpace.h>
57#include <ompl/multilevel/planners/qrrt/QRRT.h>
58#include <ompl/multilevel/planners/qmp/QMP.h>
60#include <ompl/multilevel/datastructures/Projection.h>
61#include <ompl/multilevel/datastructures/projections/SE2_R2.h>
62#include <boost/math/constants/constants.hpp>
78 : Projection(bundle,
base), manip_(manip)
83 void project(
const State *xBundle, State *xBase)
const
85 std::vector<double> reals;
86 getBundle()->copyToReals(reals, xBundle);
88 Eigen::Affine2d eeFrame;
89 manip_->FK(reals, eeFrame);
91 double x = eeFrame.translation()(0);
92 double y = eeFrame.translation()(1);
93 double yaw = acos(eeFrame.matrix()(0, 0));
95 xBase->
as<SE2StateSpace::StateType>()->setXY(x, y);
96 xBase->
as<SE2StateSpace::StateType>()->setYaw(yaw);
98 getBundle()->printState(xBundle);
99 getBase()->printState(xBase);
102 void lift(
const State *xBase, State *xBundle)
const
104 std::vector<double> reals;
105 getBase()->copyToReals(reals, xBase);
108 Eigen::Affine2d eeFrame = Eigen::Affine2d::Identity();
109 eeFrame.translation()(0) = reals.at(0);
110 eeFrame.translation()(1) = reals.at(1);
111 eeFrame.rotate(reals.at(2));
113 std::vector<double> solution;
114 manip_->FABRIK(solution, eeFrame);
117 for (uint k = 0; k < solution.size(); k++)
119 angles[k] = solution.at(k);
124 PlanarManipulator *manip_;
129 Eigen::Affine2d baseFrame;
130 Eigen::Affine2d goalFrame;
133 PolyWorld world = createCorridorProblem(numLinks, baseFrame, goalFrame);
140 bounds.setLow(-boost::math::constants::pi<double>());
141 bounds.setHigh(boost::math::constants::pi<double>());
143 manipulator.setBounds(bounds.low, bounds.high);
146 si->setStateValidityChecker(std::make_shared<PlanarManipulatorCollisionChecker>(si, manipulator, &world));
147 si->setStateValidityCheckingResolution(0.001);
154 boundsWorkspace.setLow(-2);
155 boundsWorkspace.setHigh(+2);
159 siSE2->setStateValidityChecker(std::make_shared<SE2CollisionChecker>(siSE2, &world));
160 siSE2->setStateValidityCheckingResolution(0.001);
179 ompl::multilevel::ProjectionPtr projAB = std::make_shared<ProjectionJointSpaceToSE2>(space, spaceSE2, &manipulator);
189 std::vector<SpaceInformationPtr> siVec;
190 std::vector<ompl::multilevel::ProjectionPtr> projVec;
194 siVec.push_back(siSE2);
195 projVec.push_back(projAB);
198 auto planner = std::make_shared<ompl::multilevel::QRRT>(siVec, projVec);
206 for (
int i = 0; i < numLinks; ++i)
208 start_angles[i] = 1e-1 * (pow(-1, i)) + i * 1e-3;
218 std::vector<double> goalJoints;
219 manipulator.IK(goalJoints, goalFrame);
222 goal_angles[0] = 0.346324;
223 goal_angles[1] = 0.0828153;
224 goal_angles[2] = 2.96842;
225 goal_angles[3] = -2.17559;
226 goal_angles[4] = -0.718962;
227 goal_angles[5] = 0.16532;
228 goal_angles[6] = -0.228314;
229 goal_angles[7] = 0.172762;
232 pdef->addStartState(start);
233 pdef->setGoalState(goal, 1e-3);
235 si->freeState(start);
241 planner->setProblemDefinition(pdef);
249 PathPtr path = pdef->getSolutionPath();
254 WriteVisualization(manipulator, &world, pgeo);
A shared pointer wrapper for ompl::base::Path.
A shared pointer wrapper for ompl::base::ProblemDefinition.
The lower and upper bounds for an Rn space.
The definition of a state in Rn.
A state space representing SE(2).
A shared pointer wrapper for ompl::base::StateSpace.
ompl::base::State StateType
Define the type of state allocated by this space.
Definition of an abstract state.
const T * as() const
Cast this instance to a desired type.
Definition of a geometric path.
std::size_t getStateCount() const
Get the number of states (way-points) that make up this path.
void interpolate(unsigned int count)
Insert a number of states in a path so that the path is made up of exactly count states....
#define OMPL_INFORM(fmt,...)
Log a formatted information string.
This namespace contains sampling based planning routines shared by both planning under geometric cons...
This namespace contains code that is specific to planning under geometric constraints.
This namespace contains datastructures and planners to exploit multilevel abstractions,...
@ PROJECTION_TASK_SPACE
X \rightarrow T (A mapping from state space X to a task space T).
Main namespace. Contains everything in this library.
A class to store the exit status of Planner::solve().
@ EXACT_SOLUTION
The planner found an exact solution.
@ APPROXIMATE_SOLUTION
The planner found an approximate solution.