Robot Dynamics Library
SpatialForce.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_SPATIAL_FORCE_HPP__
6 #define __RDL_SPATIAL_FORCE_HPP__
7 
18 
19 namespace RobotDynamics
20 {
21 namespace Math
22 {
29 class SpatialForce : public ForceVector, public FrameObject
30 {
31  public:
36  {
37  }
38 
44  {
45  }
46 
57  SpatialForce(ReferenceFramePtr referenceFrame, const double mx, const double my, const double mz, const double fx, const double fy, const double fz)
59  {
60  }
61 
69  : ForceVector(m.x(), m.y(), m.z(), f.x(), f.y(), f.z()), FrameObject(referenceFrame)
70  {
71  }
72 
74  {
77  return *this;
78  }
79 
81  {
82  return this;
83  }
84 
91  {
92  SpatialForce ret = *this;
94  return ret;
95  }
96 
102  {
103  return FrameVector(this->referenceFrame, this->getLinearPart());
104  }
105 
111  {
112  return FrameVector(this->referenceFrame, this->getAngularPart());
113  }
114 
119  SpatialForce(const SpatialForce& spatialForce) : ForceVector(spatialForce), FrameObject(spatialForce.referenceFrame)
120  {
121  }
122 
129  {
130  }
131 
136  inline ForceVector toForceVector() const
137  {
138  return ForceVector(this->mx(), this->my(), this->mz(), this->fx(), this->fy(), this->fz());
139  }
140 
142  {
143  this->set(v);
144  this->referenceFrame = referenceFrame;
145  }
146 
147  void setIncludingFrame(ReferenceFramePtr referenceFrame, double wx, double wy, double wz, double vx, double vy, double vz)
148  {
149  this->SpatialVector::set(wx, wy, wz, vx, vy, vz);
150  this->referenceFrame = referenceFrame;
151  }
152 
154  {
155  this->SpatialVector::set(m.x(), m.y(), m.z(), f.x(), f.y(), f.z());
156  this->referenceFrame = referenceFrame;
157  }
158 
164  inline SpatialForce operator*=(double scale)
165  {
166  mx() *= scale;
167  my() *= scale;
168  mz() *= scale;
169 
170  fx() *= scale;
171  fy() *= scale;
172  fz() *= scale;
173 
174  return *this;
175  }
176 
183  {
184  this->checkReferenceFramesMatch(&f);
185 
186  this->mx() += f.mx();
187  this->my() += f.my();
188  this->mz() += f.mz();
189 
190  this->fx() += f.fx();
191  this->fy() += f.fy();
192  this->fz() += f.fz();
193 
194  return *this;
195  }
196 
203  {
204  this->checkReferenceFramesMatch(&f);
205 
206  this->mx() -= f.mx();
207  this->my() -= f.my();
208  this->mz() -= f.mz();
209 
210  this->fx() -= f.fx();
211  this->fy() -= f.fy();
212  this->fz() -= f.fz();
213 
214  return *this;
215  }
216 };
217 
226 {
227  return f1 += f2;
228 }
229 
238 {
239  return f1 -= f2;
240 }
241 
248 inline SpatialForce operator*(SpatialForce f1, double scale)
249 {
250  return f1 *= scale;
251 }
252 typedef std::vector<SpatialForce, Eigen::aligned_allocator<SpatialForce>> SpatialForceV;
253 } // namespace Math
254 } // namespace RobotDynamics
255 
256 #endif // ifndef __RDL_SPATIAL_FORCE_HPP__
Contains various geometric objects that have methods for transforming themselves into different frame...
An interface that objects with a ReferenceFrame extend to inherit the FrameObject::changeFrame method...
Definition: FrameObject.hpp:26
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
Definition: FrameObject.cpp:9
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
ReferenceFramePtr referenceFrame
Definition: FrameObject.hpp:78
A ForceVector is a SpatialVector containing 3 moments and 3 linear forces.
Definition: ForceVector.hpp:23
EIGEN_STRONG_INLINE double & fx()
Get reference to x-linear component.
Definition: ForceVector.hpp:145
EIGEN_STRONG_INLINE ForceVector()
Empty constructor.
Definition: ForceVector.hpp:50
EIGEN_STRONG_INLINE double & my()
Get reference to y-angular component.
Definition: ForceVector.hpp:100
EIGEN_STRONG_INLINE void set(const ForceVector &f)
Setter.
Definition: ForceVector.hpp:82
EIGEN_STRONG_INLINE double & fy()
Get reference to y-linear component.
Definition: ForceVector.hpp:154
EIGEN_STRONG_INLINE double & mz()
Get reference to z-angular component.
Definition: ForceVector.hpp:109
EIGEN_STRONG_INLINE double & fz()
Get reference to z-linear component.
Definition: ForceVector.hpp:163
EIGEN_STRONG_INLINE double & mx()
Get reference to x-angular component.
Definition: ForceVector.hpp:91
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
Definition: FrameVector.hpp:31
A SpatialForce is a spatial vector with the angular part being three moments and the linear part bein...
Definition: SpatialForce.hpp:30
SpatialForce(ReferenceFramePtr referenceFrame, const double mx, const double my, const double mz, const double fx, const double fy, const double fz)
Constructor.
Definition: SpatialForce.hpp:57
void setIncludingFrame(ReferenceFramePtr referenceFrame, const Vector3d &m, const Vector3d &f)
Definition: SpatialForce.hpp:153
SpatialForce(ReferenceFramePtr referenceFrame)
Constructor. Force vector elements will be zero.
Definition: SpatialForce.hpp:43
SpatialForce(const SpatialForce &spatialForce)
Copy constructor.
Definition: SpatialForce.hpp:119
SpatialForce(ReferenceFramePtr referenceFrame, const Vector3d &m, const Vector3d f)
Constructor.
Definition: SpatialForce.hpp:68
SpatialForce operator-=(const SpatialForce &f)
Overloaded -= operator. Frame checks are performed.
Definition: SpatialForce.hpp:202
void setIncludingFrame(ReferenceFramePtr referenceFrame, const SpatialVector &v)
Definition: SpatialForce.hpp:141
SpatialForce changeFrameAndCopy(ReferenceFramePtr referenceFrame) const
Copy and change frame.
Definition: SpatialForce.hpp:90
FrameVector getFramedLinearPart() const
Get linear part of spatial force as a frame vector.
Definition: SpatialForce.hpp:101
SpatialForce()
Constructor. RobotDynamics::FrameObject::referenceFrame is initialized to nullptr.
Definition: SpatialForce.hpp:35
SpatialForce(ReferenceFramePtr referenceFrame, const SpatialVector &spatialVector)
Constructor.
Definition: SpatialForce.hpp:128
SpatialForce operator+=(const SpatialForce &f)
Overloaded += operator. Frame checks are performed.
Definition: SpatialForce.hpp:182
ForceVector toForceVector() const
Get copy of this SpatialForce as type ForceVector.
Definition: SpatialForce.hpp:136
SpatialForce & operator=(const SpatialForce &f)
Definition: SpatialForce.hpp:73
SpatialForce operator*=(double scale)
Operator for scaling a spatial force vector.
Definition: SpatialForce.hpp:164
Math::TransformableGeometricObject * getTransformableGeometricObject()
Pure virtual method that FrameObjects are required to implement so the FrameObject::changeFrame metho...
Definition: SpatialForce.hpp:80
FrameVector getFramedAngularPart() const
Get angular part of spatial force as a frame vector.
Definition: SpatialForce.hpp:110
void setIncludingFrame(ReferenceFramePtr referenceFrame, double wx, double wy, double wz, double vx, double vy, double vz)
Definition: SpatialForce.hpp:147
Definition: rdl_eigenmath.hpp:187
SpatialVector & operator=(const Eigen::MatrixBase< OtherDerived > &other)
Definition: rdl_eigenmath.hpp:198
EIGEN_STRONG_INLINE void set(const double &v0, const double &v1, const double &v2, const double &v3, const double &v4, const double &v5)
Definition: rdl_eigenmath.hpp:223
EIGEN_STRONG_INLINE Vector3d getLinearPart() const
Definition: rdl_eigenmath.hpp:235
EIGEN_STRONG_INLINE Vector3d getAngularPart() const
Definition: rdl_eigenmath.hpp:230
The TransformableGeometricObject class is an essential interface because it forces all geometric obje...
Definition: rdl_eigenmath.hpp:43
Definition: rdl_eigenmath.hpp:54
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
Definition: ReferenceFrame.hpp:68
std::vector< SpatialForce, Eigen::aligned_allocator< SpatialForce > > SpatialForceV
Definition: SpatialForce.hpp:252
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