Bench-MR
A Motion Planning Benchmark for Wheeled Mobile Robots
kinematic_car.hpp
Go to the documentation of this file.
1#ifndef _KINEMATIC_CAR_
2#define _KINEMATIC_CAR_
3
4#include <ompl/base/spaces/SE2StateSpace.h>
5#include <ompl/control/ODESolver.h>
6#include <ompl/control/SpaceInformation.h>
7#include <ompl/control/spaces/RealVectorControlSpace.h>
8
9namespace oc = ompl::control;
10namespace ob = ompl::base;
11
12namespace KinematicCar {
13// as in
14// https://ompl.kavrakilab.org/RigidBodyPlanningWithODESolverAndControls_8cpp_source.html
15inline void kinematicCarODE(const oc::ODESolver::StateType& q,
16 const oc::Control* control,
17 oc::ODESolver::StateType& qdot) {
19 double* u = control->as<oc::RealVectorControlSpace::ControlType>()->values;
20 double heading = q[2];
21 qdot.resize(q.size(), 0);
22
23 // Dynamics
24 qdot[0] = u[0] * cos(heading);
25 qdot[1] = u[0] * sin(heading);
26 qdot[2] = u[0] * tan(u[1]) / global::settings.forwardpropagation.car_length;
28}
29
30// as in
31// https://ompl.kavrakilab.org/RigidBodyPlanningWithODESolverAndControls_8cpp_source.html
32inline void kinematicCarPostIntegration(const ob::State* /*state*/,
33 const oc::Control* /*control*/,
34 const double /*duration*/, ob::State* result) {
35 // Normalize orientation between 0 and 2*pi
36 ob::SO2StateSpace SO2;
37 SO2.enforceBounds(result->as<ob::SE2StateSpace::StateType>()
38 ->as<ob::SO2StateSpace::StateType>(1));
39}
40
41inline void propagate(const oc::SpaceInformation* si, const ob::State* state,
42 const oc::Control* control, const double duration,
43 ob::State* result) {
45 static double timeStep = global::settings.forwardpropagation.dt;
46 int nsteps = ceil(duration / timeStep);
47 double dt = duration / nsteps;
48 const double* u =
49 control->as<oc::RealVectorControlSpace::ControlType>()->values;
50
51 ob::SE2StateSpace::StateType& se2 =
52 *result->as<ob::SE2StateSpace::StateType>();
53
54 si->getStateSpace()->copyState(result, state);
55
56 for (int i = 0; i < nsteps; i++) {
57 se2.setX(se2.getX() + dt * u[0] * cos(se2.getYaw()));
58 se2.setY(se2.getY() + dt * u[0] * sin(se2.getYaw()));
59 se2.setYaw(se2.getYaw() +
60 dt * u[0] * tan(dt * u[1]) /
62
63 if (!si->satisfiesBounds(result)) {
65 return;
66 }
67 }
68
69 ob::SO2StateSpace SO2;
70 SO2.enforceBounds(se2.as<ob::SO2StateSpace::StateType>(1));
72}
73
74} // namespace KinematicCar
75#endif /* _KINEMATIC_CAR_ */
ob::SE2StateSpace::StateType State
Definition: Primitives.h:12
double stop()
Stops the timer.
Definition: Stopwatch.hpp:32
void resume()
Continues the stop watch from when it was stopped.
Definition: Stopwatch.hpp:51
Definition: kinematic_car.hpp:12
void propagate(const oc::SpaceInformation *si, const ob::State *state, const oc::Control *control, const double duration, ob::State *result)
Definition: kinematic_car.hpp:41
void kinematicCarODE(const oc::ODESolver::StateType &q, const oc::Control *control, oc::ODESolver::StateType &qdot)
Definition: kinematic_car.hpp:15
void kinematicCarPostIntegration(const ob::State *, const oc::Control *, const double, ob::State *result)
Definition: kinematic_car.hpp:32
Property< double > car_length
Length of the wheel axis.
Definition: PlannerSettings.h:556
Property< double > dt
Integration time step.
Definition: PlannerSettings.h:561
Stopwatch steering_timer
Definition: PlannerSettings.h:414
PlannerSettings::GlobalSettings::OmplSettings ompl
PlannerSettings::GlobalSettings::ForwardPropagationSettings forwardpropagation
static PlannerSettings::GlobalSettings settings
Definition: PlannerSettings.h:699