-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamics.hpp
93 lines (74 loc) · 2.58 KB
/
dynamics.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef DYNAMICS_HPP
#define DYNAMICS_HPP
#include "cppTypes.h"
#include <string>
#include <vector>
#include <pinocchio/fwd.hpp> // always include it before any other header
#include "pinocchio/algorithm/frames.hpp"
#include "pinocchio/algorithm/jacobian.hpp"
#include "pinocchio/algorithm/joint-configuration.hpp"
#include "pinocchio/algorithm/kinematics.hpp"
#include "pinocchio/algorithm/rnea.hpp"
#include "pinocchio/parsers/sample-models.hpp"
#include "pinocchio/parsers/urdf.hpp"
#include "pinocchio/spatial/explog.hpp"
#include "pinocchio/algorithm/crba.hpp"
#include "pinocchio/multibody/model.hpp"
#include "pinocchio/math/rpy.hpp"
struct FBModelState {
Quat bodyOrientation; // world frame [wxyz]
Vec3 bodyPosition; // world frame
SVec bodyVelocity; // local frame [ang_vel, linVel]
Vec12 q; // q here is 12 dof and the order should be "FL", "FR", "RL", "RR"
Vec12 qd; // qd here is 12 dof
};
class FBDynModel {
public:
// vector<D6Mat<T>> _J;
// vector<SVec<T>> _Jdqd;
FBDynModel(
const std::string urdf_filename = "../unitree_a1_desc/urdf/a1.urdf") {
pinocchio::urdf::buildModel(urdf_filename, model);
pinocchio::Data temp_data(model);
data = temp_data;
_Jc.resize(4);
_Jcdqd.resize(4);
_pGC.resize(4);
_vGC.resize(4);
// std::cout<<
// model.getFrameId("FL_hip")<<"," <<
// model.getFrameId("FL_thigh")<<"," <<
// model.getFrameId("FL_calf")<<"," <<
// model.getFrameId("FL_foot")<<"," <<
// model.getFrameId("FR_foot")<<"," <<
// model.getFrameId("RL_foot")<<"," <<
// model.getFrameId("RR_foot")<<"," <<
// std::endl;
}
~FBDynModel() {}
std::vector<D3Mat> _Jc; // contact jacobian list (foot point jacobian)
D3Mat _Jcd; // contact jacobian time derivation
std::vector<Vec3> _Jcdqd;
FBModelState _state;
std::vector<Vec3> _pGC; // foot point position (global)
std::vector<Vec3> _vGC; // foot point velocity (global)
pinocchio::Model model;
pinocchio::Data data;
DMat _A;
DMat _Ainv;
DVec _grav;
DVec _coriolis;
Vec18 _full_config;
void updateModel(const FBModelState &state);
protected:
Vec19
q; // first 7 [global_base_position, global_base_quaternion] in pinocchio
Vec18 v; // first 6 [local_base_velocity_linear, local_base_velocity_angular]
// in pinocchio
Vec18 qd;
std::vector<std::string> _foots = {"FL_foot", "FR_foot", "RL_foot",
"RR_foot"};
void _updateMBkinmatics();
void _updateMBdynamics();
};
#endif