Robot.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_tvm/CoM.h>
8 #include <mc_tvm/Limits.h>
9 #include <mc_tvm/Momentum.h>
10 
11 #include <mc_rbdyn/Robot.h>
12 
13 #include <tvm/Variable.h>
14 #include <tvm/VariableVector.h>
15 #include <tvm/graph/abstract/Node.h>
16 
17 #include <RBDyn/FD.h>
18 
19 namespace mc_tvm
20 {
21 
48 struct MC_TVM_DLLAPI Robot : public tvm::graph::abstract::Node<Robot>
49 {
50  SET_OUTPUTS(Robot, FK, FV, FA, NormalAcceleration, tau, H, C)
51  SET_UPDATES(Robot, FK, FV, FA, NormalAcceleration, H, C)
52 
53  friend struct mc_rbdyn::Robot;
54  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
55 
56  using mimic_variables_t = std::pair<tvm::VariableVector, Eigen::VectorXd>;
57 
58 protected:
60  {
61  };
62 
63 public:
64  Robot(NewRobotToken, const mc_rbdyn::Robot & robot);
65 
66  Robot(Robot &&) = delete;
67  Robot & operator=(Robot &&) = delete;
68 
69  Robot(const Robot &) = delete;
70  Robot & operator=(const Robot &) = delete;
71 
76  inline const mc_rbdyn::Robot & robot() const { return robot_; }
77 
79  inline const Limits & limits() const noexcept { return limits_; }
80 
82  inline Limits & limits() noexcept { return limits_; }
83 
85  inline const tvm::VariablePtr & q() const noexcept { return q_; }
87  inline tvm::VariablePtr & q() noexcept { return q_; }
88 
90  inline const tvm::VariablePtr & alpha() const noexcept { return dq_; }
92  inline tvm::VariablePtr & alpha() noexcept { return dq_; }
93 
95  inline const tvm::VariablePtr & alphaD() const noexcept { return ddq_; }
97  inline tvm::VariablePtr & alphaD() noexcept { return ddq_; }
98 
100  inline const tvm::VariablePtr & qFloatingBase() const noexcept { return q_fb_; }
102  inline tvm::VariablePtr & qFloatingBase() noexcept { return q_fb_; }
103 
105  inline const tvm::VariablePtr & qJoints() const noexcept { return q_joints_; }
107  inline tvm::VariablePtr & qJoints() noexcept { return q_joints_; }
108 
117  tvm::VariablePtr qJoint(size_t jIdx);
118 
125  inline tvm::VariablePtr qJoint(const std::string & jName) { return qJoint(robot().jointIndexByName(jName)); }
126 
128  inline const std::map<tvm::VariablePtr, mimic_variables_t> & mimics() const noexcept { return mimics_; }
130  inline std::map<tvm::VariablePtr, mimic_variables_t> & mimics() noexcept { return mimics_; }
131 
133  inline const tvm::VariablePtr & tau() const noexcept { return tau_; }
135  inline tvm::VariablePtr & tau() { return tau_; }
136 
138  inline const CoM & comAlgo() const noexcept { return *com_; }
139 
141  inline CoM & comAlgo() noexcept { return *com_; }
142 
144  inline const Momentum & momentumAlgo() const noexcept { return *momentum_; }
145 
147  inline Momentum & momentumAlgo() noexcept { return *momentum_; }
148 
150  inline const Eigen::MatrixXd & H() const noexcept { return fd_.H(); }
151 
153  inline const Eigen::VectorXd & C() const noexcept { return fd_.C(); }
154 
156  inline const std::vector<sva::MotionVecd> & normalAccB() const noexcept { return normalAccB_; }
157 
168  inline Eigen::DenseIndex refJointIndexToQIndex(size_t jointIndex) const
169  {
170  return refJointIndexToQIndex_.at(jointIndex);
171  }
172 
184  inline Eigen::DenseIndex refJointIndexToQDotIndex(size_t jointIndex) const
185  {
186  return refJointIndexToQDotIndex_.at(jointIndex);
187  }
188 
189 private:
191  const mc_rbdyn::Robot & robot_;
193  Limits limits_;
195  tvm::VariablePtr q_fb_;
197  tvm::VariablePtr q_joints_;
199  tvm::VariablePtr q_;
201  std::map<tvm::VariablePtr, mimic_variables_t> mimics_;
203  tvm::VariablePtr dq_;
205  tvm::VariablePtr ddq_;
207  tvm::VariablePtr tau_;
209  std::vector<sva::MotionVecd> normalAccB_;
211  rbd::ForwardDynamics fd_;
213  CoMPtr com_;
215  MomentumPtr momentum_;
217  std::vector<Eigen::DenseIndex> refJointIndexToQIndex_;
219  std::vector<Eigen::DenseIndex> refJointIndexToQDotIndex_;
220 
221  /* Update functions */
222  void updateFK();
223  void updateFV();
224  void updateFA();
225  void updateNormalAcceleration();
226  void updateH();
227  void updateC();
228 };
229 
230 } // namespace mc_tvm
mc_tvm::Momentum
Definition: Momentum.h:26
mc_tvm::Robot::refJointIndexToQDotIndex
Eigen::DenseIndex refJointIndexToQDotIndex(size_t jointIndex) const
Definition: Robot.h:184
mc_tvm::Robot::q
tvm::VariablePtr & q() noexcept
Definition: Robot.h:87
mc_tvm::Robot::alphaD
tvm::VariablePtr & alphaD() noexcept
Definition: Robot.h:97
mc_tvm::Robot::mimics
std::map< tvm::VariablePtr, mimic_variables_t > & mimics() noexcept
Definition: Robot.h:130
mc_tvm::Robot::momentumAlgo
Momentum & momentumAlgo() noexcept
Definition: Robot.h:147
MC_TVM_DLLAPI
#define MC_TVM_DLLAPI
Definition: api.h:47
Limits.h
mc_rbdyn::Robot
Definition: Robot.h:62
mc_tvm::Robot::qJoint
tvm::VariablePtr qJoint(const std::string &jName)
Definition: Robot.h:125
mc_tvm::Robot::tau
const tvm::VariablePtr & tau() const noexcept
Definition: Robot.h:133
mc_tvm::Robot::limits
const Limits & limits() const noexcept
Definition: Robot.h:79
mc_tvm::Robot::qJoints
tvm::VariablePtr & qJoints() noexcept
Definition: Robot.h:107
mc_tvm::Robot::alpha
tvm::VariablePtr & alpha() noexcept
Definition: Robot.h:92
mc_tvm::Robot
Definition: Robot.h:48
mc_tvm
Definition: CollisionFunction.h:15
mc_tvm::Robot::limits
Limits & limits() noexcept
Definition: Robot.h:82
mc_tvm::Robot::normalAccB
const std::vector< sva::MotionVecd > & normalAccB() const noexcept
Definition: Robot.h:156
mc_tvm::Limits
Definition: Limits.h:15
mc_tvm::Robot::qFloatingBase
const tvm::VariablePtr & qFloatingBase() const noexcept
Definition: Robot.h:100
CoM.h
mc_tvm::Robot::mimics
const std::map< tvm::VariablePtr, mimic_variables_t > & mimics() const noexcept
Definition: Robot.h:128
Momentum.h
mc_tvm::Robot::alpha
const tvm::VariablePtr & alpha() const noexcept
Definition: Robot.h:90
mc_tvm::Robot::alphaD
const tvm::VariablePtr & alphaD() const noexcept
Definition: Robot.h:95
mc_tvm::Robot::mimic_variables_t
std::pair< tvm::VariableVector, Eigen::VectorXd > mimic_variables_t
Definition: Robot.h:56
Robot.h
mc_tvm::Robot::comAlgo
CoM & comAlgo() noexcept
Definition: Robot.h:141
mc_tvm::Robot::q
const tvm::VariablePtr & q() const noexcept
Definition: Robot.h:85
mc_tvm::Robot::momentumAlgo
const Momentum & momentumAlgo() const noexcept
Definition: Robot.h:144
mc_tvm::Robot::H
const Eigen::MatrixXd & H() const noexcept
Definition: Robot.h:150
mc_tvm::Robot::refJointIndexToQIndex
Eigen::DenseIndex refJointIndexToQIndex(size_t jointIndex) const
Definition: Robot.h:168
mc_tvm::Robot::robot
const mc_rbdyn::Robot & robot() const
Definition: Robot.h:76
mc_tvm::CoM
Definition: CoM.h:33
std
Definition: Contact.h:66
mc_tvm::CoMPtr
std::unique_ptr< CoM > CoMPtr
Definition: fwd.h:13
mc_tvm::Robot::qJoints
const tvm::VariablePtr & qJoints() const noexcept
Definition: Robot.h:105
mc_tvm::MomentumPtr
std::unique_ptr< Momentum > MomentumPtr
Definition: fwd.h:22
mc_tvm::Robot::comAlgo
const CoM & comAlgo() const noexcept
Definition: Robot.h:138
mc_rbdyn
Definition: generic_gripper.h:14
mc_tvm::Robot::C
const Eigen::VectorXd & C() const noexcept
Definition: Robot.h:153
mc_tvm::Robot::tau
tvm::VariablePtr & tau()
Definition: Robot.h:135
mc_tvm::Robot::qFloatingBase
tvm::VariablePtr & qFloatingBase() noexcept
Definition: Robot.h:102
mc_tvm::Robot::NewRobotToken
Definition: Robot.h:59