MRPT  2.0.4
CKinematicChain.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <mrpt/poses/CPose3D.h>
14 #include <vector>
15 
16 namespace mrpt
17 {
18 namespace kinematics
19 {
20 /** An individual kinematic chain element (one link) which builds up a
21  * CKinematicChain.
22  * The parameterization of the SE(3) transformation from the starting point to
23  * the end point
24  * follows a Denavit-Hartenberg standard parameterization: [theta, d, a,
25  * alpha].
26  */
28 {
29  /** Rotation from X_i to X_{i+1} (radians) */
30  double theta{0};
31  /** Distance along Z_i to the common normal between Z_i and Z_{i+1} */
32  double d{0};
33  /** Distance along the common normal (in the same direction than the new
34  * X_{i+1}) */
35  double a{0};
36  /** Rotation along X_{i+1} to transform Z_i into Z_{i+1} */
37  double alpha{0};
38 
39  /** "false": Is revolute ("q_i" is "theta"), "true": is prismatic ("q_i" is
40  * "d") */
41  bool is_prismatic{false};
42 
44  double _theta, double _d, double _a, double _alpha, bool _is_prismatic)
45  : theta(_theta),
46  d(_d),
47  a(_a),
48  alpha(_alpha),
49  is_prismatic(_is_prismatic)
50  {
51  }
52  TKinematicLink() = default;
53 };
54 
56  mrpt::serialization::CArchive& in, TKinematicLink& o);
58  mrpt::serialization::CArchive& 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,
170  std::vector<mrpt::poses::CPose3D>* out_all_poses = nullptr) const;
171 
172  /** Read getAs3DObject() for a description.
173  * \param[out] out_all_poses Optional output vector, will contain the poses
174  * in the format of recomputeAllPoses()
175  */
176  void update3DObject(
177  std::vector<mrpt::poses::CPose3D>* out_all_poses = nullptr) const;
178 
179  /** Go thru all the links of the chain and compute the global pose of each
180  * link. The "ground" link pose "pose0" defaults to the origin of
181  * coordinates,
182  * but anything else can be passed as the optional argument.
183  * The returned vector has N+1 elements (N=number of links), since [0]
184  * contains the base frame, [1] the pose after the first link, and so on.
185  */
186  void recomputeAllPoses(
187  std::vector<mrpt::poses::CPose3D>& poses,
188  const mrpt::poses::CPose3D& pose0 = mrpt::poses::CPose3D()) const;
189 
190 }; // End of class def.
191 
192 } // namespace kinematics
193 
194 // Specialization must occur in the same namespace
195 // (This is to ease serialization)
196 namespace typemeta
197 {
199 } // namespace typemeta
200 
201 } // namespace mrpt
std::vector< TKinematicLink > m_links
The links of this robot arm.
#define MRPT_DECLARE_TTYPENAME_NAMESPACE(_TYPE, __NS)
Declares a typename to be "namespace::type".
Definition: TTypeName.h:119
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, TKinematicLink &o)
mrpt::poses::CPose3D m_origin
The pose of the first link.
TKinematicLink & getLinkRef(const size_t idx)
Get a ref to a given link (read-write)
void removeLink(const size_t idx)
Removes one link from the kinematic chain (0<=idx<N)
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
void update3DObject(std::vector< mrpt::poses::CPose3D > *out_all_poses=nullptr) const
Read getAs3DObject() for a description.
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...
void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &inout_gl_obj, std::vector< mrpt::poses::CPose3D > *out_all_poses=nullptr) const
Constructs a 3D representation of the kinematic chain, in its current state.
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...
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const TKinematicLink &o)
const mrpt::poses::CPose3D & getOriginPose() const
Returns the current pose of the first link.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
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...
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const TKinematicLink & getLink(const size_t idx) const
Get a ref to a given link (read-only)
A open-loop kinematic chain model, suitable to robotic manipulators.
void clear()
Erases all links and leave the robot arm empty.
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...
void recomputeAllPoses(std::vector< mrpt::poses::CPose3D > &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.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020