rtree_planner_context.h
Go to the documentation of this file.
1 /// @deprecated this file is unmaintained but kept as a reference, remove when appropriate
2 ///
3 /// Copyright (c) 2014-2016 Andrew Hundt, Johns Hopkins University
4 ///
5 /// @author Andrew Hundt <ATHundt@gmail.com>
6 ///
7 ///
8 /// Dual licensed under the BSD or Apache License, Version 2.0
9 /// (the "Licenses") licenses at users option. Contributions shall be made such
10 /// that users can continue to choose between the Licenses.
11 /// You may not use this project except in compliance with the Licenses.
12 ///
13 /// BSD license:
14 /// ------------
15 ///
16 /// Redistribution and use in source and binary forms, with or without
17 /// modification, are permitted provided that the following conditions are met:
18 ///
19 /// 1. Redistributions of source code must retain the above copyright notice, this
20 /// list of conditions and the following disclaimer.
21 /// 2. Redistributions in binary form must reproduce the above copyright notice,
22 /// this list of conditions and the following disclaimer in the documentation
23 /// and/or other materials provided with the distribution.
24 ///
25 /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 /// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 /// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 /// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
29 /// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 /// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 /// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 /// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 /// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ///
36 /// The views and conclusions contained in the software and documentation are those
37 /// of the authors and should not be interpreted as representing official policies,
38 /// either expressed or implied, of the grl Project.
39 ///
40 /// Apache v2 license:
41 /// ------------------
42 ///
43 /// You may obtain a copy of the Apache License, Version 2.0 (the "License") at
44 ///
45 /// http://www.apache.org/licenses/LICENSE-2.0
46 ///
47 /// Unless required by applicable law or agreed to in writing, software
48 /// distributed under the License is distributed on an "AS IS" BASIS,
49 /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
50 /// See the License for the specific language governing permissions and
51 /// limitations under the License.
52 
53 #include <ros/ros.h>
54 #include <moveit/planning_interface/planning_interface.h>
55 
57 
58 class RTreeContext : public planning_interface::PlanningContext {
59 
60 public:
61 
62  typedef boost::array<double,6> vertex;
63  typedef std::size_t index;
64  typedef std::pair<index,index> edge;
65  typedef std::vector<index> path;
66 
67  RTreeContext( const robot_model::RobotModelConstPtr& model,
68  const std::string &name,
69  const std::string& group,
70  const ros::NodeHandle &nh = ros::NodeHandle("~") );
71  virtual ~RTreeContext();
72 
73  virtual bool solve( planning_interface::MotionPlanResponse &res );
74  virtual bool solve( planning_interface::MotionPlanDetailedResponse &res );
75 
76  virtual void clear();
77  virtual bool terminate();
78 
79  /**
80  Feel free to change this method if you can do better.
81 
82  Test if a state collides with the scene.
83  Call this method if you need to find if the robot collides with the
84  environment in the given robot's state.
85  \param[in] q The robot state
86  \return true if the robot state collides. false otherwise
87  */
88  bool state_collides( const vertex& q ) const;
89 
90  /**
91  Feel free to change this method if you can do better.
92 
93  Test if a linear trajectory between two states collides with the
94  environment. Call this method if you need to find if the robot collides
95  with the environment if it moves linearly between two states.
96  \param[in] qA The start robot state
97  \param[in] qB The final robot state
98  \param step The joint step used in between configurations
99  \return true if the robot trajectory collides. false otherwise
100  */
101  bool edge_collides( const vertex& qA,
102  const vertex& qB,
103  double step=0.01 )const;
104 
105  /**
106  TODO
107 
108  Create a vector of N vertices. Each vertex represent a collision-free
109  configuration (i.e. 6 joints) of the robot.
110  \param N The number of vertices in the graph
111  \return A vector of N collision-free configurations
112  */
113  std::vector<vertex> make_vertices( int N )const;
114 
115 template<typename Container>
116 void make_vertices(Container& nRandomPos, std::size_t N);
117 
118  /**
119  TODO
120 
121  Create a vector of edges. Each vertex represent a pair of vertex indices.
122  For example, the pair (1,10) connects the vertices V[1] to V[10]. There is
123  no restriction on how many edges your graph requires.
124  \param[in] V A vector of N collision-free configurations
125  \return A vector of collision-free edges
126  */
127  std::vector<edge> make_edges( const std::vector<vertex>& V )const;
128 
129  /**
130  TODO
131 
132  Search for a vertex that is accessible from a start configuration with a
133  collision-free trajectory. The method returns the index of the accessible
134  vertex.
135  \param[in] V A vector of N collision-free configurations
136  \param[in] q The start configuration
137  \return The index of the accessible vertex
138  */
139  index search_accessibility( const std::vector<vertex>& V, const vertex& q )const;
140 
141  /**
142  TODO
143 
144  Search for a vertex that is "departable" to a final configuration with a
145  collision-free trajectory. The method returns the index of the departable
146  vertex.
147  \param[in] V A vector of N collision-free configurations
148  \param[in] q The final configuration
149  \return The index of the departable vertex
150  */
151  index search_departability( const std::vector<vertex>& V, const vertex& q )const;
152 
153  /**
154  TODO
155 
156  Search the graph (V,E) for a path between two vertices.
157  collision-free trajectory. The method returns the index of the departable
158  vertex.
159  \param[in] V A vector of N collision-free configurations
160  \param[in] E A vector of collision-free edges
161  \param[in] access_idx The index of the accessible vertex
162  \param[in] depart_idx The index of the departable vertex
163  \return A vector representing a sequence of vertices
164  */
165  path search_path( const std::vector<vertex>& V,
166  const std::vector<edge>& E,
167  index access_idx,
168  index depart_idx )const;
169 
170 
171 protected:
172 
173  robot_model::RobotModelConstPtr robotmodel;
174 
175 };
176 
index search_departability(const std::vector< vertex > &V, const vertex &q) const
std::vector< edge > make_edges(const std::vector< vertex > &V) const
MOVEIT_CLASS_FORWARD(RTreeContext)
std::pair< index, index > edge
path search_path(const std::vector< vertex > &V, const std::vector< edge > &E, index access_idx, index depart_idx) const
boost::array< double, 6 > vertex
virtual bool solve(planning_interface::MotionPlanResponse &res)
robot_model::RobotModelConstPtr robotmodel
std::vector< vertex > make_vertices(int N) const
virtual void clear()
RTreeContext(const robot_model::RobotModelConstPtr &model, const std::string &name, const std::string &group, const ros::NodeHandle &nh=ros::NodeHandle("~"))
std::vector< index > path
virtual bool terminate()
bool edge_collides(const vertex &qA, const vertex &qB, double step=0.01) const
index search_accessibility(const std::vector< vertex > &V, const vertex &q) const
bool state_collides(const vertex &q) const