mc_rtc  2.16.0
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  { return std::make_shared<Frame>(NewFrameToken{}, name); }
55 
72  static FramePtr make(const std::string & name, Frame & parent, sva::PTransformd X_p_f, bool baked);
73 
75  inline const std::string & name() const noexcept { return name_; }
76 
78  virtual inline sva::PTransformd position() const noexcept
79  { return parent_ ? position_ * parent_->position() : position_; }
80 
82  virtual inline sva::MotionVecd velocity() const noexcept
83  {
84  if(!parent_) { return velocity_; }
85  auto vel = parent_->velocity();
86  auto X_0_p = parent_->position();
87  vel.linear() += -hat(X_0_p.rotation().transpose() * position_.translation()) * vel.angular();
88  return vel;
89  }
90 
97  inline Frame & position(sva::PTransformd pos) noexcept
98  {
99  position_ = pos;
100  return *this;
101  }
102 
110  {
111  velocity_ = velocity;
112  return *this;
113  }
114 
116  inline const FramePtr & parent() const noexcept { return parent_; }
117 
122  inline mc_tvm::Frame & tvm_frame() const
123  {
124  if(!tvm_frame_) { init_tvm_frame(); }
125  return *tvm_frame_;
126  }
127 
128 protected:
130  std::string name_;
132  FramePtr parent_ = nullptr;
143  virtual void init_tvm_frame() const;
144 };
145 
146 } // namespace mc_rbdyn
static MotionVec< T > Zero()
const vector3_t & linear() const
static PTransform< T > Identity()
std::optional< Eigen::VectorXd > velocity
#define MC_RBDYN_DLLAPI
Definition: api.h:50
Definition: generic_gripper.h:15
std::shared_ptr< Frame > FramePtr
Definition: fwd.h:28
Eigen::Matrix3d hat(const Eigen::Vector3d &v)
Definition: hat.h:12
std::unique_ptr< Frame > FramePtr
Definition: fwd.h:19
Definition: Frame.h:31
Definition: Frame.h:28
Frame & velocity(sva::MotionVecd velocity) noexcept
Definition: Frame.h:109
mc_tvm::Frame & tvm_frame() const
Definition: Frame.h:122
Frame(NewFrameToken, const std::string &name, Frame &parent, sva::PTransformd X_p_f, bool bake) noexcept
Frame & operator=(Frame &&)=delete
mc_tvm::FramePtr tvm_frame_
Definition: Frame.h:141
Frame & position(sva::PTransformd pos) noexcept
Definition: Frame.h:97
std::string name_
Definition: Frame.h:130
Frame(Frame &&)=delete
const std::string & name() const noexcept
Definition: Frame.h:75
Frame(NewFrameToken, const std::string &name) noexcept
Frame & operator=(const Frame &)=delete
static FramePtr make(const std::string &name) noexcept
Definition: Frame.h:53
virtual sva::MotionVecd velocity() const noexcept
Definition: Frame.h:82
virtual ~Frame()
virtual void init_tvm_frame() const
const FramePtr & parent() const noexcept
Definition: Frame.h:116
static FramePtr make(const std::string &name, Frame &parent, sva::PTransformd X_p_f, bool baked)
virtual sva::PTransformd position() const noexcept
Definition: Frame.h:78
Frame(const Frame &)=delete
Definition: shared.h:28
Definition: Frame.h:34