44 #ifndef FASTRACK_PLANNING_PLANAR_DUBINS_PLANNER_H 45 #define FASTRACK_PLANNING_PLANAR_DUBINS_PLANNER_H 52 #include <fastrack_srvs/PlanarDubinsPlannerDynamics.h> 54 #include <ompl/base/SpaceInformation.h> 55 #include <ompl/base/spaces/DubinsStateSpace.h> 56 #include <ompl/base/spaces/SE2StateSpace.h> 57 #include <ompl/geometric/SimpleSetup.h> 63 using dynamics::PlanarDubinsDynamics3D;
64 using environment::BallsInBoxOccupancyMap;
65 using state::PlanarDubins3D;
67 namespace ob = ompl::base;
68 namespace og = ompl::geometric;
70 template <
typename E,
typename B,
typename SB>
73 fastrack_srvs::PlanarDubinsPlannerDynamics, B,
79 fastrack_srvs::PlanarDubinsPlannerDynamics, B,
82 ompl::msg::setLogLevel(ompl::msg::LogLevel::LOG_ERROR);
88 Trajectory<PlanarDubins3D>
SubPlan(
const PlanarDubins3D& start,
89 const PlanarDubins3D& goal,
90 double start_time = 0.0)
const;
93 PlanarDubins3D
FromOmplState(
const ob::State* ompl_state)
const;
94 static ob::ScopedState<ob::SE2StateSpace>
ToOmplState(
95 const PlanarDubins3D& state,
96 const std::shared_ptr<ob::SE2StateSpace>& space);
104 template <
typename E,
typename B,
typename SB>
106 const PlanarDubins3D& start,
const PlanarDubins3D& goal,
107 double start_time)
const {
110 std::make_shared<ob::DubinsStateSpace>(this->
dynamics_.TurningRadius());
113 const auto& ompl_start =
ToOmplState(start, space);
117 constexpr
size_t kNumRealVectorBoundDimensions = 2;
118 ob::RealVectorBounds bounds(kNumRealVectorBoundDimensions);
120 bounds.setLow(0, PlanarDubins3D::GetLower().X());
121 bounds.setLow(1, PlanarDubins3D::GetLower().Y());
122 bounds.setHigh(0, PlanarDubins3D::GetUpper().X());
123 bounds.setHigh(1, PlanarDubins3D::GetUpper().Y());
124 space->setBounds(bounds);
127 og::SimpleSetup ompl_setup(space);
128 ompl_setup.setStateValidityChecker([&](
const ob::State* state) {
133 ompl_setup.setStartAndGoalStates(ompl_start, ompl_goal);
134 ompl_setup.getSpaceInformation()->setStateValidityCheckingResolution(0.005);
140 constexpr
double kMaxRuntimeFraction = 0.1;
141 if (!ompl_setup.solve(kMaxRuntimeFraction * this->max_runtime_)) {
142 ROS_WARN_THROTTLE(1.0,
"%s: Could not compute a valid solution.",
143 this->
name_.c_str());
144 return Trajectory<PlanarDubins3D>();
149 auto path = ompl_setup.getSolutionPath();
152 std::vector<PlanarDubins3D> states;
153 std::vector<double> times;
155 double time = start_time;
156 for (
size_t ii = 0; ii < path.getStateCount(); ii++) {
160 time += (state.Position() - states.back().Position()).norm() /
163 states.emplace_back(state);
164 times.emplace_back(time);
167 return Trajectory<PlanarDubins3D>(states, times);
171 template <
typename E,
typename B,
typename SB>
173 const ob::State* ompl_state)
const {
176 throw std::runtime_error(
"PlanarDubinsPlanner: null OMPL state.");
179 const ob::SE2StateSpace::StateType* cast_state =
180 static_cast<const ob::SE2StateSpace::StateType*
>(ompl_state);
183 return PlanarDubins3D(cast_state->getX(), cast_state->getY(),
184 cast_state->getYaw(), this->
dynamics_.V());
187 template <
typename E,
typename B,
typename SB>
189 const PlanarDubins3D& state,
190 const std::shared_ptr<ob::SE2StateSpace>& space) {
191 ob::ScopedState<ob::SE2StateSpace> ompl_state(space);
194 ompl_state[0] = state.X();
195 ompl_state[1] = state.Y();
196 ompl_state[2] = state.Theta();
PlanarDubinsDynamics3D dynamics_
static ob::ScopedState< ob::SE2StateSpace > ToOmplState(const PlanarDubins3D &state, const std::shared_ptr< ob::SE2StateSpace > &space)
PlanarDubins3D FromOmplState(const ob::State *ompl_state) const
Trajectory< PlanarDubins3D > SubPlan(const PlanarDubins3D &start, const PlanarDubins3D &goal, double start_time=0.0) const