spatial-dyn
articulated_body_cache.h
1 
10 #ifndef SPATIAL_DYN_STRUCTS_ARTICULATED_BODY_CACHE_H_
11 #define SPATIAL_DYN_STRUCTS_ARTICULATED_BODY_CACHE_H_
12 
13 #include "spatial_dyn/structs/articulated_body.h"
14 
15 #include <vector> // std::vector
16 
17 namespace spatial_dyn {
18 
20 struct ArticulatedBody::Cache {
21 
22  struct TransformData {
23  bool is_T_to_parent_computed = false; // Reusable with same position
24  std::vector<Eigen::Isometry3d> T_to_parent;
25 
26  bool is_T_to_world_computed = false; // Reusable with same position
27  std::vector<Eigen::Isometry3d> T_to_world;
28  };
29  TransformData T_data_;
30 
31  struct VelocityData {
32  bool is_computed = false; // Reusable with same position, velocity
33  std::vector<SpatialMotiond> v; // Rigid body velocities
34  };
35  VelocityData vel_data_;
36 
37  struct JacobianData {
38  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
39  int link;
40  Eigen::Vector3d offset;
41 
42  bool is_computed = false; // Reusable with same position, link, offset
43  Eigen::Matrix6Xd J;
44  };
45  JacobianData jac_data_;
46 
47  struct CentrifugalCoriolisData {
48  bool is_computed = false; // Reusable with same position, velocity
49  std::vector<SpatialMotiond> c_c; // Composite centrifugal accelerations
50  std::vector<SpatialForced> f_c; // Rigid body centrifugal and Coriolis forces
51  Eigen::VectorXd C; // Joint space centrifugal and Coriolis forces
52  };
53  CentrifugalCoriolisData cc_data_;
54 
55  struct GravityData {
56  bool is_computed = false; // Reusable with same position, gravity
57  std::vector<SpatialForced> f_g; // Rigid body gravity force
58  Eigen::VectorXd G; // Joint space gravity
59  };
60  GravityData grav_data_;
61 
62  struct RneaData {
63  std::vector<SpatialMotiond> a; // Rigid body accelerations
64  std::vector<SpatialForced> f; // Rigid body forces
65  };
66  RneaData rnea_data_;
67 
68  struct CrbaData {
69  bool is_computed = false; // Reusable with same position
70  std::vector<SpatialInertiad> I_c; // Composite inertia
71  Eigen::MatrixXd A; // Joint space inertia
72 
73  bool is_inv_computed = false; // Reusable with same position
74  Eigen::LDLT<Eigen::MatrixXd> A_inv; // Robust Cholesky decomposition of joint space inertia
75  };
76  CrbaData crba_data_;
77 
78  struct AbaData {
79  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
80  bool is_computed = false; // Reusable with same position
81  std::vector<SpatialInertiaMatrixd> I_a;
82  std::vector<SpatialForced> h;
83  std::vector<double> d;
84 
85  bool is_A_inv_computed = false; // Reusable with same position
86  Eigen::MatrixXd A_inv; // Inverse inertia computed with ABA
87  std::vector<SpatialForceXd> P;
88  std::vector<SpatialMotionXd> A;
89  };
90  AbaData aba_data_;
91 
92  struct OpspaceData {
93  Eigen::MatrixXd J;
94  double svd_epsilon;
95 
96  bool is_lambda_computed = false;
97  Eigen::MatrixXd Lambda;
98 
99  bool is_lambda_inv_computed = false;
100  Eigen::MatrixXd Lambda_inv;
101  Eigen::MatrixXd A_inv_J_T;
102  bool is_singular;
103 
104  bool is_jbar_computed = false;
105  Eigen::MatrixXd J_bar;
106  };
107  OpspaceData opspace_data_;
108 
109  struct OpspaceAbaData {
110  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
111  int idx_link;
112  Eigen::Vector3d offset;
113  double svd_epsilon;
114 
115  bool is_lambda_computed = false; // Reusable with same position
116  Eigen::Matrix6d Lambda;
117 
118  bool is_lambda_inv_computed = false; // Reusable with same position
119  Eigen::Matrix6d Lambda_inv;
120 
121  std::vector<SpatialForce6d> p;
122  std::vector<Eigen::Matrix<double,1,6>> u;
123  };
124  OpspaceAbaData opspace_aba_data_;
125 
126  struct DrneaData {
127  Eigen::VectorXd q_prev;
128  double dt = 0.;
129  bool is_q_prev_valid = false;
130 
131  std::vector<Eigen::Isometry3d> T_to_prev;
132  std::vector<SpatialForced> p_prev;
133  bool is_prev_computed = false; // Reusable with same q_prev, position
134 
135  std::vector<Eigen::Isometry3d> T_from_next;
136  std::vector<SpatialForced> p;
137  std::vector<SpatialForced> dp;
138  };
139  DrneaData drnea_data_;
140 
141 };
143 
144 } // namespace spatial_dyn
145 
146 #endif // SPATIAL_DYN_STRUCTS_ARTICULATED_BODY_CACHE_H_
const Eigen::Isometry3d & T_to_world(int i) const
Definition: articulated_body.cc:196
const Eigen::Isometry3d & T_to_parent(int i) const
Definition: articulated_body.cc:178
Definition: discrete_dynamics.cc:21