Robotics Library  0.7.0
Kinematics.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 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_KIN_KINEMATICS_H
28 #define RL_KIN_KINEMATICS_H
29 
30 #include <memory>
31 #include <string>
32 #include <vector>
33 #include <boost/graph/adjacency_list.hpp>
34 #include <rl/math/Transform.h>
35 #include <rl/math/Unit.h>
36 #include <rl/math/Vector.h>
37 
38 namespace rl
39 {
43  namespace kin
44  {
45  class Element;
46  class Frame;
47  class Link;
48  class Joint;
49  class Transform;
50 
51  class Kinematics
52  {
53  public:
54  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
55 
56  Kinematics();
57 
58  virtual ~Kinematics();
59 
63  bool areColliding(const ::std::size_t& i, const ::std::size_t& j) const;
64 
70  virtual void clip(::rl::math::Vector& q) const;
71 
72  virtual Kinematics* clone() const;
73 
74  static Kinematics* create(const ::std::string& filename);
75 
83 
91  virtual const ::rl::math::Transform& forwardPosition(const ::std::size_t& i = 0) const;
92 
104  virtual void forwardForce(const ::rl::math::Vector& tau, ::rl::math::Vector& f) const;
105 
116  virtual void forwardVelocity(const ::rl::math::Vector& qdot, ::rl::math::Vector& xdot) const;
117 
119 
121 
125  ::std::size_t getBodies() const;
126 
130  ::std::size_t getDof() const;
131 
137  const ::rl::math::Transform& getFrame(const ::std::size_t& i) const;
138 
145 
152 
153  Joint* getJoint(const ::std::size_t& i) const;
154 
161 
162  ::std::string getManufacturer() const;
163 
164  ::rl::math::Real getMaximum(const ::std::size_t& i) const;
165 
166  void getMaximum(::rl::math::Vector& max) const;
167 
168  ::rl::math::Real getMinimum(const ::std::size_t& i) const;
169 
170  void getMinimum(::rl::math::Vector& min) const;
171 
172  ::std::string getName() const;
173 
177  ::std::size_t getOperationalDof() const;
178 
184  void getPosition(::rl::math::Vector& q) const;
185 
186  void getPositionUnits(::Eigen::Matrix< ::rl::math::Unit, ::Eigen::Dynamic, 1>& units) const;
187 
188  void getSpeed(::rl::math::Vector& speed) const;
189 
190  void getSpeedUnits(::Eigen::Matrix< ::rl::math::Unit, ::Eigen::Dynamic, 1>& units) const;
191 
193 
204  virtual void inverseForce(const ::rl::math::Vector& f, ::rl::math::Vector& tau) const;
205 
207 
211  virtual bool inversePosition(
213  ::rl::math::Vector& q,
214  const ::std::size_t& leaf = 0,
215  const ::rl::math::Real& delta = ::std::numeric_limits< ::rl::math::Real>::infinity(),
216  const ::rl::math::Real& epsilon = 1.0e-3f,
217  const ::std::size_t& iterations = 1000
218  );
219 
230  virtual void inverseVelocity(const ::rl::math::Vector& xdot, ::rl::math::Vector& qdot) const;
231 
235  bool isColliding(const ::std::size_t& i) const;
236 
240  virtual bool isSingular() const;
241 
247  virtual bool isValid(const ::rl::math::Vector& q) const;
248 
250 
252 
254 
255  virtual ::rl::math::Real newDistance(const ::rl::math::Real& dist, const ::rl::math::Real& oldOff, const ::rl::math::Real& newOff, const int& cuttingDimension) const;
256 
260  void setColliding(const ::std::size_t& i, const bool& doesCollide);
261 
265  void setColliding(const ::std::size_t& i, const ::std::size_t& j, const bool& doCollide);
266 
273 
274  virtual void step(const ::rl::math::Vector& q1, const ::rl::math::Vector& qdot, ::rl::math::Vector& q2) const;
275 
276  ::rl::math::Transform& tool(const ::std::size_t& i = 0);
277 
278  const ::rl::math::Transform& tool(const ::std::size_t& i = 0) const;
279 
281 
283 
285 
293  virtual void updateFrames();
294 
302  virtual void updateJacobian();
303 
315  virtual void updateJacobianInverse(const ::rl::math::Real& lambda = 0.0f, const bool& doSvd = true);
316 
318 
320 
321  protected:
322  typedef ::boost::adjacency_list<
323  ::boost::vecS,
324  ::boost::vecS,
325  ::boost::bidirectionalS,
326  ::std::shared_ptr<Frame>,
327  ::std::shared_ptr<Transform>,
328  ::boost::no_property,
329  ::boost::vecS
330  > Tree;
331 
332  typedef ::boost::graph_traits<Tree>::edge_descriptor Edge;
333 
334  typedef ::boost::graph_traits<Tree>::edge_iterator EdgeIterator;
335 
336  typedef ::std::pair<EdgeIterator, EdgeIterator> EdgeIteratorPair;
337 
338  typedef ::boost::graph_traits<Tree>::in_edge_iterator InEdgeIterator;
339 
340  typedef ::std::pair<InEdgeIterator, InEdgeIterator> InEdgeIteratorPair;
341 
342  typedef ::boost::graph_traits<Tree>::out_edge_iterator OutEdgeIterator;
343 
344  typedef ::std::pair<OutEdgeIterator, OutEdgeIterator> OutEdgeIteratorPair;
345 
346  typedef ::boost::graph_traits<Tree>::vertex_descriptor Vertex;
347 
348  typedef ::boost::graph_traits<Tree>::vertex_iterator VertexIterator;
349 
350  typedef ::std::pair<VertexIterator, VertexIterator> VertexIteratorPair;
351 
352  void update();
353 
354  void update(Vertex& u);
355 
356  ::std::vector<Element*> elements;
357 
358  ::std::vector<Frame*> frames;
359 
360  ::std::vector<Vertex> leaves;
361 
362  ::std::vector<Link*> links;
363 
365 
367 
368  ::std::vector<Joint*> joints;
369 
370  ::std::string manufacturer;
371 
372  ::std::string name;
373 
375 
376  ::std::vector<Edge> tools;
377 
378  ::std::vector<Transform*> transforms;
379 
381 
382  private:
383 
384  };
385  }
386 }
387 
388 #endif // RL_KIN_KINEMATICS_H
rl::kin::Kinematics::jacobianInverse
::rl::math::Matrix jacobianInverse
Definition: Kinematics.h:366
rl::kin::Kinematics::generatePositionUniform
::rl::math::Vector generatePositionUniform(const ::rl::math::Vector &rand) const
Definition: Kinematics.cpp:442
rl::kin::Kinematics::areColliding
bool areColliding(const ::std::size_t &i, const ::std::size_t &j) const
See if specified bodies should be tested for collisions with each other.
Definition: Kinematics.cpp:76
rl::kin::Kinematics::root
Vertex root
Definition: Kinematics.h:374
rl::kin::Kinematics::getManipulabilityMeasure
::rl::math::Real getManipulabilityMeasure() const
Get manipulability measure.
Definition: Kinematics.cpp:495
rl::math::Matrix
::Eigen::Matrix< Real, ::Eigen::Dynamic, ::Eigen::Dynamic > Matrix
Definition: Matrix.h:42
rl::kin::Kinematics::joints
::std::vector< Joint * > joints
Definition: Kinematics.h:368
rl::kin::Kinematics::getDof
::std::size_t getDof() const
Get number of degrees of freedom (DOF).
Definition: Kinematics.cpp:461
rl::kin::Kinematics::distance
virtual ::rl::math::Real distance(const ::rl::math::Vector &q1, const ::rl::math::Vector &q2) const
Calculate distance measure between specified configuration.
Definition: Kinematics.cpp:397
rl::math::Transform
::Eigen::Transform< Real, 3, ::Eigen::Affine > Transform
Rigid transformation in 3D.
Definition: Transform.h:46
rl::kin::Kinematics::getPositionUnits
void getPositionUnits(::Eigen::Matrix< ::rl::math::Unit, ::Eigen::Dynamic, 1 > &units) const
Definition: Kinematics.cpp:564
rl::kin::Kinematics::getPosition
void getPosition(::rl::math::Vector &q) const
Get current joint position.
Definition: Kinematics.cpp:553
rl::kin::Kinematics::OutEdgeIteratorPair
::std::pair< OutEdgeIterator, OutEdgeIterator > OutEdgeIteratorPair
Definition: Kinematics.h:344
rl::kin::Kinematics::InEdgeIterator
::boost::graph_traits< Tree >::in_edge_iterator InEdgeIterator
Definition: Kinematics.h:338
rl::kin::Joint
Definition: Joint.h:40
rl::kin::Kinematics::getSpeedUnits
void getSpeedUnits(::Eigen::Matrix< ::rl::math::Unit, ::Eigen::Dynamic, 1 > &units) const
Definition: Kinematics.cpp:582
rl::kin::Kinematics::getMaximum
::rl::math::Real getMaximum(const ::std::size_t &i) const
Definition: Kinematics.cpp:507
rl::kin::Kinematics::updateJacobianInverse
virtual void updateJacobianInverse(const ::rl::math::Real &lambda=0.0f, const bool &doSvd=true)
Update Jacobian-Inverse.
Definition: Kinematics.cpp:1055
rl::kin::Kinematics::interpolate
virtual void interpolate(const ::rl::math::Vector &q1, const ::rl::math::Vector &q2, const ::rl::math::Real &alpha, ::rl::math::Vector &q) const
Definition: Kinematics.cpp:591
rl::kin::Kinematics::clip
virtual void clip(::rl::math::Vector &q) const
Clip specified configuration to be within joint limits.
Definition: Kinematics.cpp:92
rl::kin::Kinematics::inverseOfTransformedDistance
virtual ::rl::math::Real inverseOfTransformedDistance(const ::rl::math::Real &d) const
Definition: Kinematics.cpp:649
rl::kin::Kinematics::OutEdgeIterator
::boost::graph_traits< Tree >::out_edge_iterator OutEdgeIterator
Definition: Kinematics.h:342
rl::kin::Kinematics::EdgeIteratorPair
::std::pair< EdgeIterator, EdgeIterator > EdgeIteratorPair
Definition: Kinematics.h:336
rl::kin::Kinematics::Vertex
::boost::graph_traits< Tree >::vertex_descriptor Vertex
Definition: Kinematics.h:346
rl::kin::Kinematics::transformedDistance
virtual ::rl::math::Real transformedDistance(const ::rl::math::Real &d) const
Definition: Kinematics.cpp:901
rl::kin::Kinematics::leaves
::std::vector< Vertex > leaves
Definition: Kinematics.h:360
rl::kin::Kinematics::jacobian
::rl::math::Matrix jacobian
Definition: Kinematics.h:364
rl::math::Vector
::Eigen::Matrix< Real, ::Eigen::Dynamic, 1 > Vector
Definition: Vector.h:42
rl::kin::Kinematics::tools
::std::vector< Edge > tools
Definition: Kinematics.h:376
rl::kin::Kinematics::tree
Tree tree
Definition: Kinematics.h:380
rl::kin::Kinematics::name
::std::string name
Definition: Kinematics.h:372
rl::kin::Kinematics::isColliding
bool isColliding(const ::std::size_t &i) const
See if specified body should be tested for collisions with the environment.
Definition: Kinematics.cpp:732
Vector.h
rl::kin::Kinematics::getSpeed
void getSpeed(::rl::math::Vector &speed) const
Definition: Kinematics.cpp:573
rl::kin::Kinematics::create
static Kinematics * create(const ::std::string &filename)
Definition: Kinematics.cpp:128
rl::kin::Kinematics::clone
virtual Kinematics * clone() const
Definition: Kinematics.cpp:122
rl::kin::Kinematics::getJacobianInverse
const ::rl::math::Matrix & getJacobianInverse() const
Get Jacobian-Inverse.
Definition: Kinematics.cpp:481
rl::kin::Kinematics::newDistance
virtual ::rl::math::Real newDistance(const ::rl::math::Real &dist, const ::rl::math::Real &oldOff, const ::rl::math::Real &newOff, const int &cuttingDimension) const
Definition: Kinematics.cpp:827
rl::kin::Kinematics::getFrame
const ::rl::math::Transform & getFrame(const ::std::size_t &i) const
Get link frame.
Definition: Kinematics.cpp:467
rl::kin::Kinematics::updateFrames
virtual void updateFrames()
Update frames.
Definition: Kinematics.cpp:1028
rl::kin::Kinematics::updateJacobian
virtual void updateJacobian()
Update Jacobian.
Definition: Kinematics.cpp:1037
rl::kin::Kinematics::elements
::std::vector< Element * > elements
Definition: Kinematics.h:356
rl::kin::Kinematics::Tree
::boost::adjacency_list< ::boost::vecS, ::boost::vecS, ::boost::bidirectionalS, ::std::shared_ptr< Frame >, ::std::shared_ptr< Transform >, ::boost::no_property, ::boost::vecS > Tree
Definition: Kinematics.h:330
rl::kin::Kinematics::getOperationalDof
::std::size_t getOperationalDof() const
Get number of end effectors.
Definition: Kinematics.cpp:547
rl::kin::Kinematics::isSingular
virtual bool isSingular() const
Check if current configuration is singular.
Definition: Kinematics.cpp:740
rl::kin::Kinematics::VertexIterator
::boost::graph_traits< Tree >::vertex_iterator VertexIterator
Definition: Kinematics.h:348
rl::kin::Kinematics::setPosition
void setPosition(const ::rl::math::Vector &q)
Update current joint position.
Definition: Kinematics.cpp:859
rl::kin::Kinematics::InEdgeIteratorPair
::std::pair< InEdgeIterator, InEdgeIterator > InEdgeIteratorPair
Definition: Kinematics.h:340
rl::kin::Kinematics::getMinimum
::rl::math::Real getMinimum(const ::std::size_t &i) const
Definition: Kinematics.cpp:524
rl::kin::Kinematics::transforms
::std::vector< Transform * > transforms
Definition: Kinematics.h:378
rl::kin::Kinematics::maxDistanceToRectangle
virtual ::rl::math::Real maxDistanceToRectangle(const ::rl::math::Vector &q, const ::rl::math::Vector &min, const ::rl::math::Vector &max) const
Definition: Kinematics.cpp:767
rl::kin::Kinematics::inverseForce
virtual void inverseForce(const ::rl::math::Vector &f, ::rl::math::Vector &tau) const
Calculate inverse force kinematics.
Definition: Kinematics.cpp:640
rl::kin::Kinematics::step
virtual void step(const ::rl::math::Vector &q1, const ::rl::math::Vector &qdot, ::rl::math::Vector &q2) const
Definition: Kinematics.cpp:870
rl::kin::Kinematics::forwardVelocity
virtual void forwardVelocity(const ::rl::math::Vector &qdot, ::rl::math::Vector &xdot) const
Calculate forward velocity kinematics.
Definition: Kinematics.cpp:418
rl::kin::Kinematics::tool
::rl::math::Transform & tool(const ::std::size_t &i=0)
Definition: Kinematics.cpp:885
rl::kin::Kinematics::getJoint
Joint * getJoint(const ::std::size_t &i) const
Definition: Kinematics.cpp:487
rl::kin::Kinematics::forwardPosition
virtual const ::rl::math::Transform & forwardPosition(const ::std::size_t &i=0) const
Get forward position kinematics.
Definition: Kinematics.cpp:403
rl::kin::Kinematics::VertexIteratorPair
::std::pair< VertexIterator, VertexIterator > VertexIteratorPair
Definition: Kinematics.h:350
rl::kin::Kinematics::inversePosition
virtual bool inversePosition(const ::rl::math::Transform &x, ::rl::math::Vector &q, const ::std::size_t &leaf=0, const ::rl::math::Real &delta=::std::numeric_limits< ::rl::math::Real >::infinity(), const ::rl::math::Real &epsilon=1.0e-3f, const ::std::size_t &iterations=1000)
Calculate inverse position kinematics.
Definition: Kinematics.cpp:655
rl::kin::Kinematics::minDistanceToRectangle
virtual ::rl::math::Real minDistanceToRectangle(const ::rl::math::Vector &q, const ::rl::math::Vector &min, const ::rl::math::Vector &max) const
Definition: Kinematics.cpp:790
rl::kin::Kinematics::frames
::std::vector< Frame * > frames
Definition: Kinematics.h:358
rl::kin::Kinematics::isValid
virtual bool isValid(const ::rl::math::Vector &q) const
Check if specified configuration is within joint limits.
Definition: Kinematics.cpp:751
rl::kin::Kinematics::getName
::std::string getName() const
Definition: Kinematics.cpp:541
rl::kin::Kinematics::generatePositionGaussian
::rl::math::Vector generatePositionGaussian(const ::rl::math::Vector &rand, const ::rl::math::Vector &mean, const ::rl::math::Vector &sigma) const
Definition: Kinematics.cpp:427
rl::kin::Kinematics::forwardForce
virtual void forwardForce(const ::rl::math::Vector &tau, ::rl::math::Vector &f) const
Calculate forward force kinematics.
Definition: Kinematics.cpp:409
rl::kin::Kinematics::manufacturer
::std::string manufacturer
Definition: Kinematics.h:370
Transform.h
rl::kin::Kinematics::Edge
::boost::graph_traits< Tree >::edge_descriptor Edge
Definition: Kinematics.h:332
rl::kin::Kinematics::links
::std::vector< Link * > links
Definition: Kinematics.h:362
rl::kin::Kinematics
Definition: Kinematics.h:52
rl::kin::Kinematics::getBodies
::std::size_t getBodies() const
Get number of links.
Definition: Kinematics.cpp:455
rl::kin::Kinematics::EdgeIterator
::boost::graph_traits< Tree >::edge_iterator EdgeIterator
Definition: Kinematics.h:334
rl::kin::Kinematics::~Kinematics
virtual ~Kinematics()
Definition: Kinematics.cpp:71
rl::math::Real
double Real
Definition: Real.h:42
rl::kin::Kinematics::world
::rl::math::Transform & world()
Definition: Kinematics.cpp:1084
rl::kin::Kinematics::setColliding
void setColliding(const ::std::size_t &i, const bool &doesCollide)
Set if specified body should be tested for collisions with the environment.
Definition: Kinematics.cpp:833
rl::kin::Kinematics::getManufacturer
::std::string getManufacturer() const
Definition: Kinematics.cpp:501
rl::kin::Kinematics::getJacobian
const ::rl::math::Matrix & getJacobian() const
Get Jacobian.
Definition: Kinematics.cpp:475
rl::kin::Kinematics::Kinematics
Kinematics()
Definition: Kinematics.cpp:54
Unit.h
rl::kin::Kinematics::inverseVelocity
virtual void inverseVelocity(const ::rl::math::Vector &xdot, ::rl::math::Vector &qdot) const
Calculate inverse velocity kinematics.
Definition: Kinematics.cpp:723
rl::kin::Kinematics::update
void update()
Definition: Kinematics.cpp:949
rl
Robotics Library.
Definition: AnalogInput.cpp:30