pinocchio  UNKNOWN
frames.hxx
1 //
2 // Copyright (c) 2015-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_frames_hxx__
19 #define __se3_frames_hxx__
20 
21 #include "pinocchio/algorithm/kinematics.hpp"
22 #include "pinocchio/algorithm/jacobian.hpp"
23 #include "pinocchio/algorithm/check.hpp"
24 
25 namespace se3
26 {
27 
28 
29  inline void updateFramePlacements(const Model & model,
30  Data & data)
31  {
32  assert(model.check(data) && "data is not consistent with model.");
33 
34  // The following for loop starts by index 1 because the first frame is fixed
35  // and corresponds to the universe
36  for (Model::FrameIndex i=1; i < (Model::FrameIndex) model.nframes; ++i)
37  {
38  const Frame & frame = model.frames[i];
39  const Model::JointIndex & parent = frame.parent;
40  if (frame.placement.isIdentity())
41  data.oMf[i] = data.oMi[parent];
42  else
43  data.oMf[i] = data.oMi[parent]*frame.placement;
44  }
45  }
46 
47  inline const SE3 & updateFramePlacement(const Model & model,
48  Data & data,
49  const Model::FrameIndex frame_id)
50  {
51  const Frame & frame = model.frames[frame_id];
52  const Model::JointIndex & parent = frame.parent;
53  if (frame.placement.isIdentity())
54  data.oMf[frame_id] = data.oMi[parent];
55  else
56  data.oMf[frame_id] = data.oMi[parent]*frame.placement;
57  return data.oMf[frame_id];
58  }
59 
60  inline void framesForwardKinematics(const Model & model,
61  Data & data)
62  {
63  updateFramePlacements(model,data);
64  }
65 
66  inline void framesForwardKinematics(const Model & model,
67  Data & data,
68  const Eigen::VectorXd & q)
69  {
70  assert(model.check(data) && "data is not consistent with model.");
71 
72  forwardKinematics(model, data, q);
73  updateFramePlacements(model, data);
74  }
75 
76  void getFrameVelocity(const Model & model,
77  const Data & data,
78  const Model::FrameIndex frame_id,
79  Motion & frame_v)
80  {
81  assert(model.check(data) && "data is not consistent with model.");
82 
83  const Frame & frame = model.frames[frame_id];
84  const Model::JointIndex & parent = frame.parent;
85  frame_v = frame.placement.actInv(data.v[parent]);
86  }
87 
88  void getFrameAcceleration(const Model & model,
89  const Data & data,
90  const Model::FrameIndex frame_id,
91  Motion & frame_a)
92  {
93  assert(model.check(data) && "data is not consistent with model.");
94 
95  const Frame & frame = model.frames[frame_id];
96  const Model::JointIndex & parent = frame.parent;
97  frame_a = frame.placement.actInv(data.a[parent]);
98  }
99 
100  template<ReferenceFrame rf>
101  inline void getFrameJacobian(const Model & model,
102  const Data & data,
103  const Model::FrameIndex frame_id,
104  Data::Matrix6x & J)
105  {
106  assert(J.cols() == model.nv);
107  assert(data.J.cols() == model.nv);
108  assert(model.check(data) && "data is not consistent with model.");
109 
110  const Frame & frame = model.frames[frame_id];
111  const Model::JointIndex & joint_id = frame.parent;
112  if (rf == WORLD)
113  {
114  getJointJacobian<WORLD>(model,data,joint_id,J);
115  return;
116  }
117 
118  if (rf == LOCAL)
119  {
120  const SE3 & oMframe = data.oMf[frame_id];
121  const int colRef = nv(model.joints[joint_id])+idx_v(model.joints[joint_id])-1;
122 
123  for(int j=colRef;j>=0;j=data.parents_fromRow[(size_t) j])
124  {
125  J.col(j) = oMframe.actInv(Motion(data.J.col(j))).toVector();
126  }
127  return;
128  }
129  }
130 
131  inline void getFrameJacobian(const Model & model,
132  const Data & data,
133  const Model::FrameIndex frame_id,
134  Data::Matrix6x & J)
135  {
136  getFrameJacobian<LOCAL>(model,data,frame_id,J);
137  }
138 
139  template<ReferenceFrame rf>
141  const Data & data,
142  const Model::FrameIndex frameId,
143  Data::Matrix6x & dJ)
144  {
145  assert( dJ.rows() == data.dJ.rows() );
146  assert( dJ.cols() == data.dJ.cols() );
147  assert(model.check(data) && "data is not consistent with model.");
148 
149  const Frame & frame = model.frames[frameId];
150  const Model::JointIndex & joint_id = frame.parent;
151  if (rf == WORLD)
152  {
153  getJointJacobianTimeVariation<WORLD>(model,data,joint_id,dJ);
154  return;
155  }
156 
157  if (rf == LOCAL)
158  {
159  const SE3 & oMframe = data.oMf[frameId];
160  const int colRef = nv(model.joints[joint_id])+idx_v(model.joints[joint_id])-1;
161 
162  for(int j=colRef;j>=0;j=data.parents_fromRow[(size_t) j])
163  {
164  dJ.col(j) = oMframe.actInv(Motion(data.dJ.col(j))).toVector();
165  }
166  return;
167  }
168  }
169 
170 
171 } // namespace se3
172 
173 #endif // ifndef __se3_frames_hxx__
container::aligned_vector< Motion > a
Vector of joint accelerations expressed at the centers of the joints.
Definition: data.hpp:58
JointIndex parent
Index of the parent joint.
Definition: frame.hpp:96
int nv
Dimension of the velocity vector space.
Definition: model.hpp:52
PINOCCHIO_DEPRECATED void framesForwardKinematics(const Model &model, Data &data)
Updates the placement of each frame contained in the model.
Definition: frames.hxx:60
container::aligned_vector< Frame > frames
Vector of operational frames registered on the model.
Definition: model.hpp:98
void getFrameJacobian(const Model &model, const Data &data, const Model::FrameIndex frame_id, Data::Matrix6x &J)
Returns the jacobian of the frame expressed either in the LOCAL frame coordinate system or in the WOR...
Definition: frames.hxx:101
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6x
The 6d jacobian type (temporary)
Definition: data.hpp:45
void getFrameAcceleration(const Model &model, const Data &data, const Model::FrameIndex frame_id, Motion &frame_a)
Returns the spatial acceleration of the frame expressed in the LOCAL frame coordinate system...
Definition: frames.hxx:88
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
Definition: model.hpp:70
Matrix6x J
Jacobian of joint placements.
Definition: data.hpp:217
int nv(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNvVisitor to get the dimension of the joint tangent space...
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
Definition: frame.hpp:44
const SE3 & updateFramePlacement(const Model &model, Data &data, const Model::FrameIndex frame_id)
Updates the placement of the given frame.
Definition: frames.hxx:47
Matrix6x dJ
Derivative of the Jacobian with respect to the time.
Definition: data.hpp:220
void forwardKinematics(const Model &model, Data &data, const Eigen::VectorXd &q)
Update the joint placements according to the current joint configuration.
Definition: kinematics.hxx:106
void updateFramePlacements(const Model &model, Data &data)
Updates the placement of each frame contained in the model.
Definition: frames.hxx:29
container::aligned_vector< SE3 > oMf
Vector of absolute operationnel frame placements (wrt the world).
Definition: data.hpp:106
container::aligned_vector< SE3 > oMi
Vector of absolute joint placements (wrt the world).
Definition: data.hpp:87
int idx_v(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxVVisitor to get the index in the full model tangent space c...
bool check(const AlgorithmCheckerBase< D > &checker=AlgorithmCheckerBase< D >()) const
Definition: model.hpp:331
std::vector< int > parents_fromRow
First previous non-zero row in M (used in Cholesky Decomposition).
Definition: data.hpp:210
container::aligned_vector< Motion > v
Vector of joint velocities expressed at the centers of the joints.
Definition: data.hpp:67
void getFrameJacobianTimeVariation(const Model &model, const Data &data, const Model::FrameIndex frameId, Data::Matrix6x &dJ)
Computes the Jacobian time variation of a specific frame (given by frame_id) expressed either in the ...
Definition: frames.hxx:140
internal::SE3GroupAction< D >::ReturnType actInv(const D &d) const
by = aXb.actInv(ay)
Definition: se3.hpp:100
void getFrameVelocity(const Model &model, const Data &data, const Model::FrameIndex frame_id, Motion &frame_v)
Returns the spatial velocity of the frame expressed in the LOCAL frame coordinate system...
Definition: frames.hxx:76
SE3 placement
Placement of the frame wrt the parent joint.
Definition: frame.hpp:102
int nframes
Number of operational frames.
Definition: model.hpp:61