Main MRPT website > C++ reference for MRPT 1.9.9
CKinematicChain.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef mrpt_CKinematicChain_H
10 #define mrpt_CKinematicChain_H
11 
12 #include <mrpt/poses/CPose3D.h>
16 
17 namespace mrpt
18 {
19 namespace kinematics
20 {
21 /** An individual kinematic chain element (one link) which builds up a
22  * CKinematicChain.
23  * The parameterization of the SE(3) transformation from the starting point to
24  * the end point
25  * follows a Denavit-Hartenberg standard parameterization: [theta, d, a,
26  * alpha].
27  */
29 {
30  /** Rotation from X_i to X_{i+1} (radians) */
31  double theta;
32  /** Distance along Z_i to the common normal between Z_i and Z_{i+1} */
33  double d;
34  /** Distance along the common normal (in the same direction than the new
35  * X_{i+1}) */
36  double a;
37  /** Rotation along X_{i+1} to transform Z_i into Z_{i+1} */
38  double alpha;
39 
40  /** "false": Is revolute ("q_i" is "theta"), "true": is prismatic ("q_i" is
41  * "d") */
43 
45  double _theta, double _d, double _a, double _alpha, bool _is_prismatic)
46  : theta(_theta),
47  d(_d),
48  a(_a),
49  alpha(_alpha),
50  is_prismatic(_is_prismatic)
51  {
52  }
53  TKinematicLink() : theta(0), d(0), a(0), alpha(0), is_prismatic(false) {}
54 };
55 
58  mrpt::utils::CStream& out, const TKinematicLink& o);
59 
60 /** A open-loop kinematic chain model, suitable to robotic manipulators.
61  * Each link is parameterized with standard Denavit-Hartenberg standard
62  * parameterization [theta, d, a, alpha].
63  *
64  * The orientation of the first link can be modified with setOriginPose(),
65  * which defaults to standard XYZ axes with +Z pointing upwards.
66  *
67  * \sa CPose3D
68  * \ingroup kinematics_grp
69  */
71 {
73 
74  private:
75  /** Smart pointers to the last objects for each link, as returned in
76  * getAs3DObject(), for usage within update3DObject() */
77  mutable std::vector<mrpt::opengl::CRenderizable::Ptr> m_last_gl_objects;
78 
79  /** The links of this robot arm */
80  std::vector<TKinematicLink> m_links;
81  /** The pose of the first link. */
83 
84  public:
85  /** Return the number of links */
86  size_t size() const { return m_links.size(); }
87  /** Erases all links and leave the robot arm empty. */
88  void clear();
89 
90  /** Appends a new link to the robotic arm, with the given Denavit-Hartenberg
91  * parameters (see TKinematicLink for further details) */
92  void addLink(
93  double theta, double d, double a, double alpha, bool is_prismatic);
94 
95  /** Removes one link from the kinematic chain (0<=idx<N) */
96  void removeLink(const size_t idx);
97 
98  /** Get a ref to a given link (read-only) */
99  const TKinematicLink& getLink(const size_t idx) const;
100 
101  /** Get a ref to a given link (read-write) */
102  TKinematicLink& getLinkRef(const size_t idx);
103 
104  /** Can be used to define a first degree of freedom along a +Z axis which
105  * does not coincide with the global +Z axis. */
106  void setOriginPose(const mrpt::poses::CPose3D& new_pose);
107 
108  /** Returns the current pose of the first link. */
109  const mrpt::poses::CPose3D& getOriginPose() const;
110 
111  /** Get all the DOFs of the arm at once, returning them in a vector with all
112  * the "q_i" values, which
113  * can be interpreted as rotations (radians) or displacements (meters)
114  * depending on links being "revolute" or "prismatic".
115  * The vector is automatically resized to the correct size (the number of
116  * links).
117  * \tparam VECTOR Can be any Eigen vector, mrpt::math::CVectorDouble, or
118  * std::vector<double>
119  */
120  template <class VECTOR>
121  void getConfiguration(VECTOR& v) const
122  {
123  const size_t N = m_links.size();
124  v.resize(N);
125  for (size_t i = 0; i < N; i++)
126  {
127  if (m_links[i].is_prismatic)
128  v[i] = m_links[i].d;
129  else
130  v[i] = m_links[i].theta;
131  }
132  }
133 
134  /** Set all the DOFs of the arm at once, from a vector with all the "q_i"
135  * values, which
136  * are interpreted as rotations (radians) or displacements (meters)
137  * depending on links being "revolute" or "prismatic".
138  * \exception std::exception If the size of the vector doesn't match the
139  * number of links.
140  * \tparam VECTOR Can be any Eigen vector, mrpt::math::CVectorDouble, or
141  * std::vector<double>
142  */
143  template <class VECTOR>
144  void setConfiguration(const VECTOR& v)
145  {
146  ASSERT_EQUAL_(v.size(), this->size())
147  const size_t N = m_links.size();
148  for (size_t i = 0; i < N; i++)
149  {
150  if (m_links[i].is_prismatic)
151  m_links[i].d = v[i];
152  else
153  m_links[i].theta = v[i];
154  }
155  }
156 
157  /** Constructs a 3D representation of the kinematic chain, in its current
158  * state.
159  * You can call update3DObject() to update the kinematic state of these
160  * OpenGL objects in the future, since
161  * an internal list of smart pointers to the constructed objects is kept
162  * internally. This is more efficient
163  * than calling this method again to build a new representation.
164  * \param[out] out_all_poses Optional output vector, will contain the poses
165  * in the format of recomputeAllPoses()
166  * \sa update3DObject
167  */
168  void getAs3DObject(
169  mrpt::opengl::CSetOfObjects::Ptr& inout_gl_obj,
171  out_all_poses = nullptr) const;
172 
173  /** Read getAs3DObject() for a description.
174  * \param[out] out_all_poses Optional output vector, will contain the poses
175  * in the format of recomputeAllPoses()
176  */
177  void update3DObject(
179  out_all_poses = nullptr) const;
180 
181  /** Go thru all the links of the chain and compute the global pose of each
182  * link. The "ground" link pose "pose0" defaults to the origin of
183  * coordinates,
184  * but anything else can be passed as the optional argument.
185  * The returned vector has N+1 elements (N=number of links), since [0]
186  * contains the base frame, [1] the pose after the first link, and so on.
187  */
188  void recomputeAllPoses(
190  const mrpt::poses::CPose3D& pose0 = mrpt::poses::CPose3D()) const;
191 
192 }; // End of class def.
193 
194 } // End of namespace
195 
196 // Specialization must occur in the same namespace
197 // (This is to ease serialization)
198 namespace utils
199 {
201 } // End of namespace
202 
203 } // End of namespace
204 
205 #endif
#define ASSERT_EQUAL_(__A, __B)
std::vector< TKinematicLink > m_links
The links of this robot arm.
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3525
#define MRPT_DECLARE_TTYPENAME_NAMESPACE(_TYPE, __NS)
Definition: TTypeName.h:79
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
void update3DObject(mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t *out_all_poses=nullptr) const
Read getAs3DObject() for a description.
mrpt::poses::CPose3D m_origin
The pose of the first link.
void recomputeAllPoses(mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t &poses, const mrpt::poses::CPose3D &pose0=mrpt::poses::CPose3D()) const
Go thru all the links of the chain and compute the global pose of each link.
TKinematicLink & getLinkRef(const size_t idx)
Get a ref to a given link (read-write)
mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, TKinematicLink &o)
void removeLink(const size_t idx)
Removes one link from the kinematic chain (0<=idx<N)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
void getConfiguration(VECTOR &v) const
Get all the DOFs of the arm at once, returning them in a vector with all the "q_i" values...
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
void setConfiguration(const VECTOR &v)
Set all the DOFs of the arm at once, from a vector with all the "q_i" values, which are interpreted a...
void addLink(double theta, double d, double a, double alpha, bool is_prismatic)
Appends a new link to the robotic arm, with the given Denavit-Hartenberg parameters (see TKinematicLi...
const mrpt::poses::CPose3D & getOriginPose() const
Returns the current pose of the first link.
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
GLuint in
Definition: glext.h:7274
void setOriginPose(const mrpt::poses::CPose3D &new_pose)
Can be used to define a first degree of freedom along a +Z axis which does not coincide with the glob...
const TKinematicLink & getLink(const size_t idx) const
Get a ref to a given link (read-only)
void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &inout_gl_obj, mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t *out_all_poses=nullptr) const
Constructs a 3D representation of the kinematic chain, in its current state.
A open-loop kinematic chain model, suitable to robotic manipulators.
void clear()
Erases all links and leave the robot arm empty.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
size_t size() const
Return the number of links.
std::vector< mrpt::opengl::CRenderizable::Ptr > m_last_gl_objects
Smart pointers to the last objects for each link, as returned in getAs3DObject(), for usage within up...
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const TKinematicLink &o)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019