ReferenceFrame.hpp
Go to the documentation of this file.
1 /*
2  * RDL - Robot Dynamics Library
3  * Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
4  *
5  * Licensed under the zlib license. See LICENSE for more details.
6  */
7 
8 #ifndef __RDL_REFERENCE_FRAME_HPP__
9 #define __RDL_REFERENCE_FRAME_HPP__
10 
15 #include <climits>
16 #include <memory>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
23 
24 namespace RobotDynamics
25 {
71 class ReferenceFrame;
73 typedef std::shared_ptr<ReferenceFrame> ReferenceFramePtr;
74 typedef std::shared_ptr<FixedReferenceFrame> FixedReferenceFramePtr;
75 typedef std::vector<ReferenceFramePtr> ReferenceFramePtrV;
76 typedef std::vector<FixedReferenceFramePtr> FixedReferenceFramePtrV;
89 {
90  public:
95  ReferenceFrame(const ReferenceFrame& referenceFrameToCopy)
96  : frameName(referenceFrameToCopy.frameName)
97  , parentFrame(referenceFrameToCopy.parentFrame)
98  , transformFromParent(referenceFrameToCopy.transformFromParent)
99  , transformToRoot(referenceFrameToCopy.transformToRoot)
100  , inverseTransformToRoot(referenceFrameToCopy.inverseTransformToRoot)
101  , rootFrame(referenceFrameToCopy.rootFrame)
102  , isWorldFrame(referenceFrameToCopy.isWorldFrame)
103  , isBodyFrame(referenceFrameToCopy.isBodyFrame)
104  , movableBodyId(referenceFrameToCopy.movableBodyId)
105  {
106  }
107 
118  // cppcheck-suppress passedByValue
120  unsigned int movableBodyId)
121  : frameName(frameName)
122  , parentFrame(parentFrame)
123  , transformFromParent(transformFromParent)
124  , isWorldFrame(false)
125  , isBodyFrame(isBodyFrame)
126  , movableBodyId(movableBodyId)
127  {
128  if (parentFrame == nullptr)
129  {
130  throw ReferenceFrameException("You are not allowed to create a frame with parentFrame=nullptr. Only a root frame and the world frame may have "
131  "parentFrame=nullptr");
132  }
133 
134  ReferenceFramePtr root = parentFrame;
135 
136  while (root->getParentFrame() != nullptr)
137  {
138  root = root->getParentFrame();
139  }
140 
141  rootFrame = root.get();
142 
143  update();
144  }
145 
150  {
151  }
152 
154  {
155  return rootFrame;
156  }
157 
161  virtual ~ReferenceFrame()
162  {
163  }
164 
172  void update();
173 
179  // cppcheck-suppress passedByValue
180  inline void getTransformToDesiredFrame(RobotDynamics::Math::SpatialTransform& transformToPack, ReferenceFramePtr desiredFrame)
181  {
182  transformToPack = getTransformToDesiredFrame(desiredFrame);
183  }
184 
190  virtual RobotDynamics::Math::SpatialTransform getTransformToDesiredFrame(ReferenceFramePtr desiredFrame);
191 
197  void verifyFramesHaveSameRoot(ReferenceFramePtr frame);
198 
205  {
206  this->transformFromParent = transformFromParent;
207  }
208 
213  void checkReferenceFramesMatch(ReferenceFramePtr referenceFrame) const;
214 
215  void checkReferenceFramesMatch(ReferenceFrame* referenceFrame) const;
216 
222  {
223  return this->transformToRoot;
224  }
225 
231  {
232  return this->inverseTransformToRoot;
233  }
234 
239  inline ReferenceFramePtr getParentFrame()
240  {
241  return this->parentFrame;
242  }
243 
248  inline std::string getName() const
249  {
250  return this->frameName;
251  }
252 
258  static ReferenceFramePtr createARootFrame(const std::string& frameName)
259  {
260  return ReferenceFramePtr(new ReferenceFrame(frameName, false, 0, true));
261  }
262 
267  static ReferenceFramePtr getWorldFrame()
268  {
269  return worldFrame;
270  }
271 
277  {
278  return this->transformFromParent;
279  }
280 
286  {
287  return this->transformFromParent.inverse();
288  }
289 
294  inline bool getIsWorldFrame() const
295  {
296  return this->isWorldFrame;
297  }
298 
303  inline unsigned int getMovableBodyId() const
304  {
305  return this->movableBodyId;
306  }
307 
313  inline bool getIsBodyFrame() const
314  {
315  return this->isBodyFrame;
316  }
317 
319  {
320  worldFrame = other.worldFrame;
321  frameName = other.frameName;
322  parentFrame = other.parentFrame;
326  isWorldFrame = other.isWorldFrame;
327  isBodyFrame = other.isBodyFrame;
329  rootFrame = other.rootFrame;
330 
331  return *this;
332  }
333 
334  protected:
342  ReferenceFrame(const std::string& frameName, bool isWorldFrame, unsigned int movableBodyId, bool isBodyFrame)
343  : frameName(frameName), parentFrame(nullptr), isWorldFrame(isWorldFrame), isBodyFrame(isBodyFrame), movableBodyId(movableBodyId)
344  {
345  rootFrame = this;
346  update();
347  }
348 
354  static ReferenceFramePtr createAWorldFrame(const std::string& frameName = "world")
355  {
356  return ReferenceFramePtr(new ReferenceFrame(frameName, true, 0, true));
357  }
358 
359  static ReferenceFramePtr worldFrame;
360  std::string frameName;
361  ReferenceFramePtr parentFrame;
371  bool isBodyFrame;
374  unsigned int movableBodyId;
376 };
377 
379 {
380  FixedReferenceFrame(const FixedReferenceFrame&) = delete;
381  void operator=(const FixedReferenceFrame&) = delete;
382 
383  public:
384  // cppcheck-suppress passedByValue
386  unsigned int movableBodyId)
387  : ReferenceFrame(frameName, parentFrame, transformFromParent, false, movableBodyId)
388  {
389  }
390 
392  {
393  }
394 
396  {
397  transformToRoot = parentFrame->getTransformToRoot() * transformFromParent.inverse();
398  return transformToRoot;
399  }
400 
406  {
407  inverseTransformToRoot = transformFromParent * parentFrame->getInverseTransformToRoot();
408  return inverseTransformToRoot;
409  }
410 };
411 } // namespace RobotDynamics
412 
417 #endif // ifndef __RDL_REFERENCE_FRAME_HPP__
std::string getName() const
Get the frame name.
ReferenceFramePtr getParentFrame()
get a pointer to this frames parent
std::vector< ReferenceFramePtr > ReferenceFramePtrV
std::shared_ptr< FixedReferenceFrame > FixedReferenceFramePtr
ReferenceFrame(const std::string &frameName, bool isWorldFrame, unsigned int movableBodyId, bool isBodyFrame)
static ReferenceFramePtr worldFrame
A custom exception for frame operations.
ReferenceFrame()
Empty constructor. All contained ptrs will be initialize to nullptr.
static ReferenceFramePtr createARootFrame(const std::string &frameName)
Creates a root frame with ReferenceFrame::parentFrame=nullptr.
RobotDynamics::Math::SpatialTransform transformToRoot
void setTransformFromParent(const RobotDynamics::Math::SpatialTransform &transformFromParent)
Set a frames ReferenceFrame::transformToParent. For frames connected by a joint, this needs to be upd...
void checkReferenceFramesMatch(ReferenceFramePtr referenceFrame) const
Check if the argument ReferenceFrame equals this.
bool getIsBodyFrame() const
Get boolean telling if this frame is a body frame or not. If it is a body frame, A pointer to this fr...
std::vector< FixedReferenceFramePtr > FixedReferenceFramePtrV
static ReferenceFramePtr getWorldFrame()
Get a pointer to the world frame.
RobotDynamics::Math::SpatialTransform getTransformToParent()
Get spatial transform this frame to its parent.
RobotDynamics::Math::SpatialTransform getInverseTransformToRoot() override
Get this frames ReferenceFrame::inverseTransformToRoot.
RobotDynamics::Math::SpatialTransform transformFromParent
ReferenceFrame & operator=(const ReferenceFrame &other)
bool getIsWorldFrame() const
Get a boolean telling if this frame is the world frame.
ReferenceFrame(const ReferenceFrame &referenceFrameToCopy)
Copy constructor.
virtual ~ReferenceFrame()
Destructor.
RobotDynamics::Math::SpatialTransform inverseTransformToRoot
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
unsigned int getMovableBodyId() const
Get the ID of the movable body this frame is attached to.
Compact representation of spatial transformations.
SpatialTransform inverse() const
Returns inverse of transform.
virtual RobotDynamics::Math::SpatialTransform getTransformToRoot()
Get this frames ReferenceFrame::transformToRoot.
void verifyFramesHaveSameRoot(ReferenceFramePtr frame)
Check if two frames have the same roots.
virtual RobotDynamics::Math::SpatialTransform getInverseTransformToRoot()
Get this frames ReferenceFrame::inverseTransformToRoot.
ReferenceFrame object used to tell what frame objects are expressed in. Every ReferenceFrame has a po...
ReferenceFrame(const std::string &frameName, ReferenceFramePtr parentFrame, const RobotDynamics::Math::SpatialTransform &transformFromParent, bool isBodyFrame, unsigned int movableBodyId)
Constructor.
FixedReferenceFrame(const std::string &frameName, ReferenceFramePtr parentFrame, const RobotDynamics::Math::SpatialTransform &transformFromParent, unsigned int movableBodyId)
void getTransformToDesiredFrame(RobotDynamics::Math::SpatialTransform &transformToPack, ReferenceFramePtr desiredFrame)
Get the spatial transform from this frame to desiredFrame and store it in transformToPack.
RobotDynamics::Math::SpatialTransform getTransformToRoot() override
Get this frames ReferenceFrame::transformToRoot.
static ReferenceFramePtr createAWorldFrame(const std::string &frameName="world")
Helper method to create a world frame.
RobotDynamics::Math::SpatialTransform getTransformFromParent()
Get spatial transform from parent to this frame.
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
void update()
Recalculates this frames ReferenceFrame::transformToRoot and ReferenceFrame::inverseTransformToRoot w...


rdl_dynamics
Author(s):
autogenerated on Tue Apr 20 2021 02:25:28