DynamicCarPlanning.h
1 /*********************************************************************
2 * Rice University Software Distribution License
3 *
4 * Copyright (c) 2010, Rice University
5 * All Rights Reserved.
6 *
7 * For a full description see the file named LICENSE.
8 *
9 *********************************************************************/
10 
11 /* Author: Mark Moll */
12 
13 #ifndef OMPLAPP_DYNAMIC_CAR_PLANNING_
14 #define OMPLAPP_DYNAMIC_CAR_PLANNING_
15 
16 #include "omplapp/apps/AppBase.h"
17 #include <ompl/base/spaces/SE2StateSpace.h>
18 #include <ompl/control/ODESolver.h>
19 #include <ompl/control/spaces/RealVectorControlSpace.h>
20 
21 namespace ompl
22 {
23  namespace app
24  {
42  class DynamicCarPlanning : public AppBase<AppType::CONTROL>
43  {
44  public:
45  DynamicCarPlanning()
46  : AppBase<AppType::CONTROL>(constructControlSpace(), Motion_2D),
47  odeSolver(std::make_shared<control::ODEBasicSolver<>>(si_, [this](const control::ODESolver::StateType& q, const control::Control *ctrl, control::ODESolver::StateType& qdot)
48  {
49  ode(q, ctrl, qdot);
50  }))
51  {
52  name_ = std::string("Dynamic car");
53  setDefaultBounds();
54 
55  si_->setStatePropagator(control::ODESolver::getStatePropagator(odeSolver,
56  [this](const base::State* state, const control::Control* control, const double duration, base::State* result)
57  {
58  postPropagate(state, control, duration, result);
59  }));
60  }
61  ~DynamicCarPlanning() override = default;
62 
63  bool isSelfCollisionEnabled() const override
64  {
65  return false;
66  }
67  unsigned int getRobotCount() const override
68  {
69  return 1;
70  }
71  base::ScopedState<> getDefaultStartState() const override;
72  base::ScopedState<> getFullStateFromGeometricComponent(const base::ScopedState<> &state) const override
73  {
74  base::ScopedState<> r(si_);
75  r = 0.0;
76  r[0] = state[0];
77  r[1] = state[1];
78  r[2] = state[2];
79  return r;
80  }
81 
82  const base::StateSpacePtr& getGeometricComponentStateSpace() const override
83  {
84  return getStateSpace()->as<base::CompoundStateSpace>()->getSubspace(0);
85  }
86 
87  double getVehicleLength()
88  {
89  return 1./lengthInv_;
90  }
91  void setVehicleLength(double length)
92  {
93  lengthInv_ = 1./length;
94  }
95  double getMass()
96  {
97  return mass_;
98  }
99  void setMass(double mass)
100  {
101  mass_ = mass;
102  }
103  virtual void setDefaultBounds();
104 
105  protected:
106 
107  const base::State* getGeometricComponentStateInternal(const base::State* state, unsigned int /*index*/) const override
108  {
109  return state->as<base::CompoundState>()->components[0];
110  }
111 
112  virtual void ode(const control::ODESolver::StateType& q, const control::Control *ctrl, control::ODESolver::StateType& qdot);
113 
114  virtual void postPropagate(const base::State* state, const control::Control* control, double duration, base::State* result);
115 
116  static control::ControlSpacePtr constructControlSpace()
117  {
118  return std::make_shared<control::RealVectorControlSpace>(constructStateSpace(), 2);
119  }
120  static base::StateSpacePtr constructStateSpace()
121  {
122  auto stateSpace(std::make_shared<base::CompoundStateSpace>());
123  stateSpace->addSubspace(std::make_shared<base::SE2StateSpace>(), 1.);
124  stateSpace->addSubspace(std::make_shared<base::RealVectorStateSpace>(2), .3);
125  stateSpace->lock();
126  return stateSpace;
127  }
128 
129  double timeStep_{1e-2};
130  double lengthInv_{1.};
131  double mass_{1.};
132  control::ODESolverPtr odeSolver;
133  };
134 
135  }
136 }
137 
138 #endif
const base::StateSpacePtr & getStateSpace() const
Get the current instance of the state space.
Definition: SimpleSetup.h:156
static StatePropagatorPtr getStatePropagator(ODESolverPtr solver, const PostPropagationEvent &postEvent=nullptr)
Retrieve a StatePropagator object that solves a system of ordinary differential equations defined by ...
Definition: ODESolver.h:191
base::SpaceInformationPtr si_
The created space information.
Definition: SimpleSetup.h:346
std::vector< double > StateType
Portable data type for the state values.
Definition: ODESolver.h:141
Main namespace. Contains everything in this library.
Definition: AppBase.h:21