Robotics Library  0.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Model.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the Technische Universitaet Muenchen nor the names of
14 // its contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef _RL_MDL_MODEL_H_
31 #define _RL_MDL_MODEL_H_
32 
33 #include <string>
34 #include <vector>
35 #include <boost/shared_ptr.hpp>
36 #include <boost/graph/adjacency_list.hpp>
37 #include <rl/math/Transform.h>
38 #include <rl/math/Vector.h>
39 
40 #include "Frame.h"
41 #include "Transform.h"
42 
43 namespace rl
44 {
45  namespace mdl
46  {
47  class Body;
48  class Compound;
49  class Joint;
50 
51  class Model
52  {
53  public:
54  Model();
55 
56  virtual ~Model();
57 
58  void add(Compound* compound, const Frame* a, const Frame* b);
59 
60  void add(Frame* frame);
61 
62  void add(Transform* transform, const Frame* a, const Frame* b);
63 
64  bool areColliding(const ::std::size_t& i, const ::std::size_t& j) const;
65 
66  Model* clone() const;
67 
68  void getAcceleration(::rl::math::Vector& qdd) const;
69 
70  ::std::size_t getBodies() const;
71 
72  const Body* getBody(const ::std::size_t& i) const;
73 
74  ::std::size_t getDof() const;
75 
76  const ::rl::math::Transform& getFrame(const ::std::size_t& i) const;
77 
78  const Joint* getJoint(const ::std::size_t& i) const;
79 
80  const ::rl::math::MotionVector& getOperationalAcceleration(const ::std::size_t& i) const;
81 
82  ::std::size_t getOperationalDof() const;
83 
84  const ::rl::math::ForceVector& getOperationalForce(const ::std::size_t& i) const;
85 
86  const ::rl::math::Transform& getOperationalPosition(const ::std::size_t& i) const;
87 
88  const ::rl::math::MotionVector& getOperationalVelocity(const ::std::size_t& i) const;
89 
90  const ::std::string& getManufacturer() const;
91 
92  void getMaximum(::rl::math::Vector& max) const;
93 
94  void getMinimum(::rl::math::Vector& min) const;
95 
96  const ::std::string& getName() const;
97 
98  void getPosition(::rl::math::Vector& q) const;
99 
100  void getTorque(::rl::math::Vector& tau) const;
101 
102  void getSpeed(::rl::math::Vector& speed) const;
103 
104  void getVelocity(::rl::math::Vector& qd) const;
105 
106  bool isColliding(const ::std::size_t& i) const;
107 
108  void replace(Compound* compound, Transform* transform);
109 
110  void replace(Transform* transform, Compound* compound);
111 
112  void remove(Compound* compound);
113 
114  void remove(Frame* frame);
115 
116  void remove(Transform* transform);
117 
119 
120  void setManufacturer(const ::std::string& manufacturer);
121 
122  void setName(const ::std::string& name);
123 
124  void setOperationalVelocity(const ::std::size_t& i, const ::rl::math::MotionVector& v) const;
125 
127 
129 
131 
132  ::rl::math::Transform& tool(const ::std::size_t& i = 0);
133 
134  const ::rl::math::Transform& tool(const ::std::size_t& i = 0) const;
135 
136  virtual void update();
137 
139 
141 
142  protected:
143  friend class Compound;
144 
145  typedef ::boost::adjacency_list<
146  ::boost::listS,
147  ::boost::listS,
148  ::boost::bidirectionalS,
149  ::boost::property<
150  ::boost::vertex_color_t, Compound*,
151  ::boost::shared_ptr< Frame >
152  >,
153  ::boost::property<
154  ::boost::edge_weight_t, Compound*,
155  ::boost::shared_ptr< Transform >
156  >,
157  ::boost::no_property,
158  ::boost::listS
159  > Tree;
160 
161  typedef ::boost::graph_traits< Tree >::edge_descriptor Edge;
162 
163  typedef ::boost::graph_traits< Tree >::edge_iterator EdgeIterator;
164 
165  typedef ::std::pair< EdgeIterator, EdgeIterator > EdgeIteratorPair;
166 
167  typedef ::boost::graph_traits< Tree >::in_edge_iterator InEdgeIterator;
168 
169  typedef ::std::pair< InEdgeIterator, InEdgeIterator > InEdgeIteratorPair;
170 
171  typedef ::boost::graph_traits< Tree >::out_edge_iterator OutEdgeIterator;
172 
173  typedef ::std::pair< OutEdgeIterator, OutEdgeIterator > OutEdgeIteratorPair;
174 
175  typedef ::boost::graph_traits< Tree >::vertex_descriptor Vertex;
176 
177  typedef ::boost::graph_traits< Tree >::vertex_iterator VertexIterator;
178 
179  typedef ::std::pair< VertexIterator, VertexIterator > VertexIteratorPair;
180 
181  void update(const Vertex& u);
182 
183  ::std::vector< Body* > bodies;
184 
185  ::std::vector< Element* > elements;
186 
187  ::std::vector< Frame* > frames;
188 
189  ::std::vector< Joint* > joints;
190 
191  ::std::vector< Vertex > leaves;
192 
193  ::std::string manufacturer;
194 
195  ::std::string name;
196 
198 
199  ::std::vector< Edge > tools;
200 
201  ::std::vector< Transform* > transforms;
202 
204 
205  private:
206 
207  };
208  }
209 }
210 
211 #endif // _RL_MDL_MODEL_H_