44 #ifndef FASTRACK_PLANNING_OMPL_KINEMATIC_PLANNER_H 45 #define FASTRACK_PLANNING_OMPL_KINEMATIC_PLANNER_H 49 #include <ompl/geometric/planners/bitstar/BITstar.h> 50 #include <ompl/geometric/planners/rrt/RRTConnect.h> 52 #include <ompl/base/SpaceInformation.h> 53 #include <ompl/base/TypedSpaceInformation.h> 54 #include <ompl/base/spaces/RealVectorStateSpace.h> 55 #include <ompl/geometric/SimpleSetup.h> 57 #include <ompl/geometric/planners/bitstar/BITstar.h> 58 #include <ompl/geometric/planners/rrt/RRTConnect.h> 63 namespace ob = ompl::base;
64 namespace og = ompl::geometric;
66 template <
typename P,
typename S,
typename E,
typename B,
typename SB>
72 ompl::msg::setLogLevel(ompl::msg::LogLevel::LOG_ERROR);
79 Trajectory<S>
Plan(
const S& start,
const S& goal,
80 double start_time = 0.0)
const;
89 template <
typename P,
typename S,
typename E,
typename B,
typename SB>
91 const ob::State* state)
const {
94 throw std::runtime_error(
"OmplKinematicPlanner: null OMPL state.");
97 const ob::RealVectorStateSpace::StateType* cast_state =
98 static_cast<const ob::RealVectorStateSpace::StateType*
>(state);
101 VectorXd config(S::ConfigurationDimension());
102 for (
size_t ii = 0; ii < S::ConfigurationDimension(); ii++)
103 config(ii) = cast_state->values[ii];
110 template <
typename P,
typename S,
typename E,
typename B,
typename SB>
112 const S& start,
const S& goal,
double start_time)
const {
114 const VectorXd start_config = start.Configuration();
115 const VectorXd goal_config = goal.Configuration();
118 if (!this->
env_.AreValid(start.OccupiedPositions(), this->
bound_)) {
119 ROS_WARN_THROTTLE(1.0,
"Start point was in collision or out of bounds.");
120 return Trajectory<S>();
123 if (!this->
env_.AreValid(goal.OccupiedPositions(), this->
bound_)) {
124 ROS_WARN_THROTTLE(1.0,
"Goal point was in collision or out of bounds.");
125 return Trajectory<S>();
130 std::make_shared<ob::RealVectorStateSpace>(S::ConfigurationDimension()));
133 const VectorXd lower = S::GetConfigurationLower();
134 const VectorXd upper = S::GetConfigurationUpper();
136 ob::RealVectorBounds ompl_bounds(S::ConfigurationDimension());
137 for (
size_t ii = 0; ii < S::ConfigurationDimension(); ii++) {
138 ompl_bounds.setLow(ii, lower(ii));
139 ompl_bounds.setHigh(ii, upper(ii));
142 ompl_space->setBounds(ompl_bounds);
145 og::SimpleSetup ompl_setup(ompl_space);
146 ompl_setup.setStateValidityChecker([&](
const ob::State* state) {
152 ob::ScopedState<ob::RealVectorStateSpace> ompl_start(ompl_space);
153 ob::ScopedState<ob::RealVectorStateSpace> ompl_goal(ompl_space);
154 for (
size_t ii = 0; ii < S::ConfigurationDimension(); ii++) {
155 ompl_start[ii] = start_config(ii);
156 ompl_goal[ii] = goal_config(ii);
159 ompl_setup.setStartAndGoalStates(ompl_start, ompl_goal);
162 ob::PlannerPtr ompl_planner(
new P(ompl_setup.getSpaceInformation()));
163 ompl_setup.setPlanner(ompl_planner);
166 const ob::PlannerStatus solved = ompl_setup.solve(this->
max_runtime_);
169 ROS_WARN(
"OMPL Planner could not compute a solution.");
170 return Trajectory<S>();
174 const og::PathGeometric& solution = ompl_setup.getSolutionPath();
178 std::vector<S> states;
179 std::vector<double> times;
181 double time = start_time;
182 for (
size_t ii = 0; ii < solution.getStateCount(); ii++) {
187 if (ii > 0) time += this->
dynamics_.BestPossibleTime(states.back(), state);
189 times.push_back(time);
190 states.push_back(state);
193 return Trajectory<S>(states, times);
S FromOmplState(const ob::State *state) const
Trajectory< S > Plan(const S &start, const S &goal, double start_time=0.0) const
Kinematics< S > dynamics_