Frame.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2022 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_rbdyn/api.h>
8 #include <mc_rbdyn/fwd.h>
9 #include <mc_rbdyn/hat.h>
10 
11 #include <mc_tvm/fwd.h>
12 
13 #include <mc_rtc/shared.h>
14 
15 #include <SpaceVecAlg/SpaceVecAlg>
16 
17 namespace mc_rbdyn
18 {
19 
27 struct MC_RBDYN_DLLAPI Frame : public mc_rtc::shared<Frame>
28 {
29 protected:
31  {
32  };
33 
34 public:
36  Frame(NewFrameToken, const std::string & name) noexcept;
37 
39  Frame(NewFrameToken, const std::string & name, Frame & parent, sva::PTransformd X_p_f, bool bake) noexcept;
40 
41  virtual ~Frame();
42 
43  /* Prevent copy and move */
44  Frame(const Frame &) = delete;
45  Frame(Frame &&) = delete;
46  Frame & operator=(const Frame &) = delete;
47  Frame & operator=(Frame &&) = delete;
48 
53  inline static FramePtr make(const std::string & name) noexcept
54  {
55  return std::make_shared<Frame>(NewFrameToken{}, name);
56  }
57 
74  static FramePtr make(const std::string & name, Frame & parent, sva::PTransformd X_p_f, bool baked);
75 
77  inline const std::string & name() const noexcept { return name_; }
78 
80  virtual inline sva::PTransformd position() const noexcept
81  {
82  return parent_ ? position_ * parent_->position() : position_;
83  }
84 
86  virtual inline sva::MotionVecd velocity() const noexcept
87  {
88  if(!parent_) { return velocity_; }
89  auto vel = parent_->velocity();
90  auto X_0_p = parent_->position();
91  vel.linear() += -hat(X_0_p.rotation().transpose() * position_.translation()) * vel.angular();
92  return vel;
93  }
94 
101  inline Frame & position(sva::PTransformd pos) noexcept
102  {
103  position_ = pos;
104  return *this;
105  }
106 
113  inline Frame & velocity(sva::MotionVecd velocity) noexcept
114  {
115  velocity_ = velocity;
116  return *this;
117  }
118 
120  inline const FramePtr & parent() const noexcept { return parent_; }
121 
126  inline mc_tvm::Frame & tvm_frame() const
127  {
128  if(!tvm_frame_) { init_tvm_frame(); }
129  return *tvm_frame_;
130  }
131 
132 protected:
134  std::string name_;
136  FramePtr parent_ = nullptr;
138  sva::PTransformd position_ = sva::PTransformd::Identity();
140  sva::MotionVecd velocity_ = sva::MotionVecd::Zero();
147  virtual void init_tvm_frame() const;
148 };
149 
150 } // namespace mc_rbdyn
mc_rbdyn::Frame::parent
const FramePtr & parent() const noexcept
Definition: Frame.h:120
mc_tvm::FramePtr
std::unique_ptr< Frame > FramePtr
Definition: fwd.h:19
mc_rbdyn::Frame::name
const std::string & name() const noexcept
Definition: Frame.h:77
mc_rbdyn::Frame::position
virtual sva::PTransformd position() const noexcept
Definition: Frame.h:80
mc_rtc::shared
Definition: shared.h:27
mc_rbdyn::Frame::tvm_frame
mc_tvm::Frame & tvm_frame() const
Definition: Frame.h:126
mc_rbdyn::Frame::velocity
virtual sva::MotionVecd velocity() const noexcept
Definition: Frame.h:86
mc_rbdyn::Frame
Definition: Frame.h:27
mc_rbdyn::FramePtr
std::shared_ptr< Frame > FramePtr
Definition: fwd.h:28
api.h
fwd.h
fwd.h
mc_rbdyn::Frame::name_
std::string name_
Definition: Frame.h:134
MC_RBDYN_DLLAPI
#define MC_RBDYN_DLLAPI
Definition: api.h:50
mc_rbdyn::hat
Eigen::Matrix3d hat(const Eigen::Vector3d &v)
Definition: hat.h:12
mc_rbdyn::Frame::tvm_frame_
mc_tvm::FramePtr tvm_frame_
Definition: Frame.h:145
mc_rbdyn::Frame::make
static FramePtr make(const std::string &name) noexcept
Definition: Frame.h:53
mc_rbdyn::Frame::velocity
Frame & velocity(sva::MotionVecd velocity) noexcept
Definition: Frame.h:113
mc_rbdyn::Frame::NewFrameToken
Definition: Frame.h:30
mc_tvm::Frame
Definition: Frame.h:33
mc_rbdyn
Definition: generic_gripper.h:14
shared.h
mc_rbdyn::Frame::position
Frame & position(sva::PTransformd pos) noexcept
Definition: Frame.h:101
hat.h