Robot Dynamics Library
FrameVectorPair.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
2 // RDL - Robot Dynamics Library
3 // Licensed under the zlib license. See LICENSE for more details.
4 
5 #ifndef __RDL_FRAME_VECTOR_PAIR_HPP__
6 #define __RDL_FRAME_VECTOR_PAIR_HPP__
7 
20 
21 namespace RobotDynamics
22 {
23 namespace Math
24 {
31 {
32  public:
36  FrameVectorPair() : lin(nullptr, 0., 0., 0.), ang(nullptr, 0., 0., 0.)
37  {
38  }
39 
40  /*
41  * @brief constructor
42  * @param linear Linear part
43  * @param angular Angular part
44  */
46  {
48  }
49 
50  /*
51  * @brief constructor
52  * @param referenceFrame pointer to a reference frame
53  */
54  explicit FrameVectorPair(ReferenceFramePtr referenceFrame) : lin(referenceFrame), ang(referenceFrame)
55  {
56  }
57 
62  explicit FrameVectorPair(const SpatialMotion& v)
63  {
66  }
67 
74  FrameVectorPair(ReferenceFramePtr referenceFrame, const Vector3d& linear, const Vector3d& angular) : lin(referenceFrame, linear), ang(referenceFrame, angular)
75  {
76  }
77 
83  FrameVectorPair(ReferenceFramePtr referenceFrame, const SpatialVector& v) : lin(referenceFrame, v.getLinearPart()), ang(referenceFrame, v.getAngularPart())
84  {
85  }
86 
90  virtual ~FrameVectorPair()
91  {
92  }
93 
109  void changeFrame(ReferenceFramePtr referenceFrame)
110  {
111  assert(referenceFrame);
112  lin.changeFrame(referenceFrame);
113  ang.changeFrame(referenceFrame);
114  }
115 
122  {
123  FrameVectorPair p = *this;
124  p.changeFrame(referenceFrame);
125  return p;
126  }
127 
131  inline void setToZero()
132  {
133  lin.setZero();
134  ang.setZero();
135  }
136 
142  {
143  lin.setReferenceFrame(referenceFrame);
144  ang.setReferenceFrame(referenceFrame);
145  }
146 
153  inline void setIncludingFrame(ReferenceFramePtr referenceFrame, const Vector3d& linear, const Vector3d& angular)
154  {
155  assert(referenceFrame);
156 
157  lin.setIncludingFrame(linear, referenceFrame);
158  ang.setIncludingFrame(angular, referenceFrame);
159  }
160 
166  inline void setIncludingFrame(ReferenceFramePtr referenceFrame, const SpatialVector& v)
167  {
168  assert(referenceFrame);
169 
170  lin.setIncludingFrame(v.getLinearPart(), referenceFrame);
171  ang.setIncludingFrame(v.getAngularPart(), referenceFrame);
172  }
173 
179  inline void setIncludingFrame(ReferenceFramePtr referenceFrame, const MotionVector& v)
180  {
181  assert(referenceFrame);
182 
183  lin.setIncludingFrame(v.getLinearPart(), referenceFrame);
184  ang.setIncludingFrame(v.getAngularPart(), referenceFrame);
185  }
186 
191  inline void setIncludingFrame(const SpatialMotion& v)
192  {
195  }
196 
201  inline void setLinearPart(const Vector3d& v)
202  {
203  lin.set(v);
204  }
205 
210  inline void setAngularPart(const Vector3d& v)
211  {
212  ang.set(v);
213  }
214 
219  inline FrameVector linear() const
220  {
221  return lin;
222  }
223 
228  inline FrameVector angular() const
229  {
230  return ang;
231  }
232 
233  template <typename T>
234  void operator*=(const T scale)
235  {
236  lin *= scale;
237  ang *= scale;
238  }
239 
241  {
242  lin += v.linear();
243  ang += v.angular();
244  }
245 
247  {
248  lin -= v.linear();
249  ang -= v.angular();
250  }
251 
257  {
258  return &lin;
259  }
260 
266  {
267  return &ang;
268  }
269 
270  protected:
273 };
274 
275 template <typename T>
276 inline FrameVectorPair operator*(FrameVectorPair pair, const T scalar)
277 {
278  pair *= scalar;
279  return pair;
280 }
281 
282 template <typename T>
283 inline FrameVectorPair operator*(const T scalar, FrameVectorPair pair)
284 {
285  pair *= scalar;
286  return pair;
287 }
288 
289 // cppcheck-suppress passedByValue
291 {
292  v1 += v2;
293  return v1;
294 }
295 
296 // cppcheck-suppress passedByValue
298 {
299  v1 -= v2;
300  return v1;
301 }
302 } // namespace Math
303 } // namespace RobotDynamics
304 
305 #endif // ifndef __RDL_FRAME_VECTOR_HPP__
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
Definition: FrameObject.cpp:9
void setReferenceFrame(ReferenceFramePtr frame)
Set frame objects internal reference frame.
Definition: FrameObject.hpp:58
void checkReferenceFramesMatch(const FrameObject *frameObject) const
Check if two FrameObjects hold the same ReferenceFrame.
Definition: FrameObject.hpp:67
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
Definition: FrameObject.hpp:49
A FrameVector is a pair of 3D vector with a ReferenceFrame.
Definition: FrameVectorPair.hpp:31
void setIncludingFrame(ReferenceFramePtr referenceFrame, const Vector3d &linear, const Vector3d &angular)
Set the components and the ReferenceFrame these components are expressed in.
Definition: FrameVectorPair.hpp:153
FrameVector lin
Definition: FrameVectorPair.hpp:271
FrameVector ang
Definition: FrameVectorPair.hpp:272
void setIncludingFrame(const SpatialMotion &v)
Set the components and the ReferenceFrame these components are expressed in.
Definition: FrameVectorPair.hpp:191
void operator-=(const FrameVectorPair &v)
Definition: FrameVectorPair.hpp:246
FrameVectorPair changeFrameAndCopy(ReferenceFramePtr referenceFrame) const
copy into new frame vector and change the frame of that
Definition: FrameVectorPair.hpp:121
void setLinearPart(const Vector3d &v)
Set the linear vector.
Definition: FrameVectorPair.hpp:201
void changeFrame(ReferenceFramePtr referenceFrame)
Change the frame of the two 3d vectors. Equivalent to the following math expression.
Definition: FrameVectorPair.hpp:109
void setIncludingFrame(ReferenceFramePtr referenceFrame, const MotionVector &v)
Set the components and the ReferenceFrame these components are expressed in.
Definition: FrameVectorPair.hpp:179
FrameVector linear() const
Get copy of linear component.
Definition: FrameVectorPair.hpp:219
virtual ~FrameVectorPair()
Destructor.
Definition: FrameVectorPair.hpp:90
void setIncludingFrame(ReferenceFramePtr referenceFrame, const SpatialVector &v)
Set the components and the ReferenceFrame these components are expressed in.
Definition: FrameVectorPair.hpp:166
FrameVectorPair(ReferenceFramePtr referenceFrame, const SpatialVector &v)
Constructor.
Definition: FrameVectorPair.hpp:83
void operator+=(const FrameVectorPair &v)
Definition: FrameVectorPair.hpp:240
FrameVectorPair()
Default constructor. Initializes its ReferenceFrame to nullptr.
Definition: FrameVectorPair.hpp:36
void setReferenceFrame(ReferenceFramePtr referenceFrame)
Set the reference frame.
Definition: FrameVectorPair.hpp:141
FrameVectorPair(const FrameVector &linear, const FrameVector &angular)
Definition: FrameVectorPair.hpp:45
FrameVectorPair(ReferenceFramePtr referenceFrame)
Definition: FrameVectorPair.hpp:54
FrameVectorPair(ReferenceFramePtr referenceFrame, const Vector3d &linear, const Vector3d &angular)
Constructor.
Definition: FrameVectorPair.hpp:74
FrameVector * linearPtr()
Get pointer to linear vector.
Definition: FrameVectorPair.hpp:256
FrameVectorPair(const SpatialMotion &v)
Constructor.
Definition: FrameVectorPair.hpp:62
void operator*=(const T scale)
Definition: FrameVectorPair.hpp:234
void setAngularPart(const Vector3d &v)
Set the angular vector.
Definition: FrameVectorPair.hpp:210
void setToZero()
Set x, y, and z components of linear and angular to 0.
Definition: FrameVectorPair.hpp:131
FrameVector * angularPtr()
Get pointer to angular vector.
Definition: FrameVectorPair.hpp:265
FrameVector angular() const
Get copy of angular component.
Definition: FrameVectorPair.hpp:228
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
Definition: FrameVector.hpp:31
void setIncludingFrame(const double x, const double y, const double z, ReferenceFramePtr referenceFrame)
Set the x, y, and z components and the ReferenceFrame these components are expressed in.
Definition: FrameVector.hpp:113
Definition: MotionVector.hpp:21
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in....
Definition: SpatialMotion.hpp:33
Definition: rdl_eigenmath.hpp:187
EIGEN_STRONG_INLINE Vector3d getLinearPart() const
Definition: rdl_eigenmath.hpp:235
EIGEN_STRONG_INLINE Vector3d getAngularPart() const
Definition: rdl_eigenmath.hpp:230
Definition: rdl_eigenmath.hpp:54
void set(const Eigen::Vector3d &v)
Definition: rdl_eigenmath.hpp:82
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
Definition: ReferenceFrame.hpp:68
FramePoint operator-(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:410
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:404
ForceVector operator*(const SpatialTransform &X, ForceVector f)
Operator for transforming a ForceVector. Calls the ForceVector::transform method.
Definition: ForceVector.hpp:248
Namespace for all structures of the RobotDynamics library.
Definition: examples.hpp:19