PathControl.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_CONTROL_PATH_CONTROL_
38 #define OMPL_CONTROL_PATH_CONTROL_
39 
40 #include "ompl/control/SpaceInformation.h"
41 #include "ompl/base/Path.h"
42 #include "ompl/geometric/PathGeometric.h"
43 #include <vector>
44 
45 namespace ompl
46 {
47  namespace base
48  {
50  OMPL_CLASS_FORWARD(OptimizationObjective);
52  }
53 
54  namespace control
55  {
60  class PathControl : public base::Path
61  {
62  public:
63 
66 
68  PathControl(const PathControl &path);
69 
70  virtual ~PathControl()
71  {
72  freeMemory();
73  }
74 
76  PathControl& operator=(const PathControl &other);
77 
79  virtual base::Cost cost(const base::OptimizationObjectivePtr& obj) const;
80 
82  virtual double length() const;
83 
85  virtual bool check() const;
86 
88  virtual void print(std::ostream &out) const;
98  virtual void printAsMatrix(std::ostream &out) const;
99 
101  geometric::PathGeometric asGeometric() const;
102 
108  void append(const base::State *state);
109 
112  void append(const base::State *state, const Control *control, double duration);
113 
115  void interpolate();
116 
118  void random();
119 
121  bool randomValid(unsigned int attempts);
122 
129  std::vector<base::State*>& getStates()
130  {
131  return states_;
132  }
133 
135  std::vector<Control*>& getControls()
136  {
137  return controls_;
138  }
139 
141  std::vector<double>& getControlDurations()
142  {
143  return controlDurations_;
144  }
145 
147  base::State* getState(unsigned int index)
148  {
149  return states_[index];
150  }
151 
153  const base::State* getState(unsigned int index) const
154  {
155  return states_[index];
156  }
157 
159  Control* getControl(unsigned int index)
160  {
161  return controls_[index];
162  }
163 
165  const Control* getControl(unsigned int index) const
166  {
167  return controls_[index];
168  }
169 
171  double getControlDuration(unsigned int index) const
172  {
173  return controlDurations_[index];
174  }
175 
177  std::size_t getStateCount() const
178  {
179  return states_.size();
180  }
181 
183  std::size_t getControlCount() const
184  {
185  return controls_.size();
186  }
187 
190  protected:
191 
193  std::vector<base::State*> states_;
194 
196  std::vector<Control*> controls_;
197 
199  std::vector<double> controlDurations_;
200 
202  void freeMemory();
203 
205  void copyFrom(const PathControl &other);
206 
207  };
208 
209  }
210 }
211 
212 #endif
Control * getControl(unsigned int index)
Get the control located at index along the path. This is the control that gets applied to the state l...
Definition: PathControl.h:159
std::vector< base::State * > & getStates()
Get the states that make up the path (as a reference, so it can be modified, hence the function is no...
Definition: PathControl.h:129
double getControlDuration(unsigned int index) const
Get the duration of the control at index, which gets applied to the state at index.
Definition: PathControl.h:171
Definition of an abstract control.
Definition: Control.h:48
std::size_t getControlCount() const
Get the number of controls applied along this path. This should be equal to getStateCount() - 1 unles...
Definition: PathControl.h:183
std::vector< Control * > & getControls()
Get the controls that make up the path (as a reference, so it can be modified, hence the function is ...
Definition: PathControl.h:135
Definition of a control path.
Definition: PathControl.h:60
base::State * getState(unsigned int index)
Get the state located at index along the path.
Definition: PathControl.h:147
std::size_t getStateCount() const
Get the number of states (way-points) that make up this path.
Definition: PathControl.h:177
Main namespace. Contains everything in this library.
Definition: Cost.h:42
const base::State * getState(unsigned int index) const
Get the state located at index along the path.
Definition: PathControl.h:153
Abstract definition of a path.
Definition: Path.h:67
A boost shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:50
const Control * getControl(unsigned int index) const
Get the control located at index along the path. This is the control that gets applied to the state l...
Definition: PathControl.h:165
std::vector< double > controlDurations_
The duration of the control applied at each state. This array contains one element less than the list...
Definition: PathControl.h:199
A boost shared pointer wrapper for ompl::base::OptimizationObjective.
std::vector< base::State * > states_
The list of states that make up the path.
Definition: PathControl.h:193
std::vector< double > & getControlDurations()
Get the control durations used along the path (as a reference, so it can be modified, hence the function is not const)
Definition: PathControl.h:141
Definition of a geometric path.
Definition: PathGeometric.h:60
std::vector< Control * > controls_
The control applied at each state. This array contains one element less than the list of states...
Definition: PathControl.h:196
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47