All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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 control
48  {
49 
54  class PathControl : public base::Path
55  {
56  public:
57 
60 
62  PathControl(const PathControl &path);
63 
64  virtual ~PathControl(void)
65  {
66  freeMemory();
67  }
68 
70  PathControl& operator=(const PathControl& other);
71 
73  virtual double length(void) const;
74 
76  virtual bool check(void) const;
77 
79  virtual void print(std::ostream &out) const;
89  virtual void printAsMatrix(std::ostream &out) const;
90 
93 
99  void append(const base::State *state);
100 
103  void append(const base::State *state, const Control *control, double duration);
104 
106  void interpolate(void);
107 
109  void random(void);
110 
112  bool randomValid(unsigned int attempts);
113 
120  std::vector<base::State*>& getStates(void)
121  {
122  return states_;
123  }
124 
126  std::vector<Control*>& getControls(void)
127  {
128  return controls_;
129  }
130 
132  std::vector<double>& getControlDurations(void)
133  {
134  return controlDurations_;
135  }
136 
138  base::State* getState(unsigned int index)
139  {
140  return states_[index];
141  }
142 
144  const base::State* getState(unsigned int index) const
145  {
146  return states_[index];
147  }
148 
150  Control* getControl(unsigned int index)
151  {
152  return controls_[index];
153  }
154 
156  const Control* getControl(unsigned int index) const
157  {
158  return controls_[index];
159  }
160 
162  double getControlDuration(unsigned int index) const
163  {
164  return controlDurations_[index];
165  }
166 
168  std::size_t getStateCount(void) const
169  {
170  return states_.size();
171  }
172 
174  std::size_t getControlCount(void) const
175  {
176  return controls_.size();
177  }
178 
181  protected:
182 
184  std::vector<base::State*> states_;
185 
187  std::vector<Control*> controls_;
188 
190  std::vector<double> controlDurations_;
191 
193  void freeMemory(void);
194 
196  void copyFrom(const PathControl& other);
197 
198  };
199 
200  }
201 }
202 
203 #endif
virtual void printAsMatrix(std::ostream &out) const
Print the path as a real-valued matrix where the i-th row represents the i-th state along the path...
PathControl & operator=(const PathControl &other)
Assignment operator.
void freeMemory(void)
Free the memory allocated by the path.
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:150
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:162
void append(const base::State *state)
Append state to the end of the path; it is assumed state is the first state, so no control is applied...
Definition of an abstract control.
Definition: Control.h:48
virtual double length(void) const
The path length (sum of control durations)
Definition of a control path.
Definition: PathControl.h:54
virtual void print(std::ostream &out) const
Print the path to a stream.
std::vector< base::State * > & getStates(void)
Get the states that make up the path (as a reference, so it can be modified, hence the function is no...
Definition: PathControl.h:120
base::State * getState(unsigned int index)
Get the state located at index along the path.
Definition: PathControl.h:138
geometric::PathGeometric asGeometric(void) const
Convert this path into a geometric path (interpolation is performed and then states are copied) ...
Definition: PathControl.cpp:93
const base::State * getState(unsigned int index) const
Get the state located at index along the path.
Definition: PathControl.h:144
std::vector< Control * > & getControls(void)
Get the controls that make up the path (as a reference, so it can be modified, hence the function is ...
Definition: PathControl.h:126
void random(void)
Set this path to a random segment.
bool randomValid(unsigned int attempts)
Set this path to a random valid segment. Sample attempts times for valid segments. Returns true on success.
Abstract definition of a path.
Definition: Path.h:67
void interpolate(void)
Make the path such that all controls are applied for a single time step (computes intermediate states...
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:156
std::size_t getControlCount(void) const
Get the number of controls applied along this path. This should be equal to getStateCount() - 1 unles...
Definition: PathControl.h:174
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:190
std::vector< base::State * > states_
The list of states that make up the path.
Definition: PathControl.h:184
PathControl(const base::SpaceInformationPtr &si)
Constructor.
Definition: PathControl.cpp:82
virtual bool check(void) const
Check if the path is valid.
Definition of a geometric path.
Definition: PathGeometric.h:55
std::vector< double > & getControlDurations(void)
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:132
void copyFrom(const PathControl &other)
Copy the content of a path to this one.
std::size_t getStateCount(void) const
Get the number of states (way-points) that make up this path.
Definition: PathControl.h:168
std::vector< Control * > controls_
The control applied at each state. This array contains one element less than the list of states...
Definition: PathControl.h:187