-
Notifications
You must be signed in to change notification settings - Fork 403
/
timings-cg.cpp
256 lines (214 loc) · 6.94 KB
/
timings-cg.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// Copyright (c) 2018 CNRS
// Copyright (c) 2020-2024 INRIA
//
#include "pinocchio/codegen/cppadcg.hpp"
#include "pinocchio/algorithm/joint-configuration.hpp"
#include "pinocchio/algorithm/crba.hpp"
#include "pinocchio/algorithm/centroidal.hpp"
#include "pinocchio/algorithm/aba.hpp"
#include "pinocchio/algorithm/constrained-dynamics-derivatives.hpp"
#include "pinocchio/algorithm/constrained-dynamics.hpp"
#include "pinocchio/algorithm/contact-info.hpp"
#include "pinocchio/algorithm/rnea.hpp"
#include "pinocchio/algorithm/cholesky.hpp"
#include "pinocchio/algorithm/jacobian.hpp"
#include "pinocchio/algorithm/center-of-mass.hpp"
#include "pinocchio/algorithm/compute-all-terms.hpp"
#include "pinocchio/algorithm/kinematics.hpp"
#include "pinocchio/parsers/urdf.hpp"
#include "pinocchio/multibody/sample-models.hpp"
#include "pinocchio/container/aligned-vector.hpp"
#include "pinocchio/codegen/code-generator-algo.hpp"
#include <iostream>
#include "pinocchio/utils/timer.hpp"
int main(int argc, const char ** argv)
{
using namespace Eigen;
using namespace pinocchio;
PinocchioTicToc timer(PinocchioTicToc::US);
#ifdef NDEBUG
const int NBT = 1000 * 100;
#else
const int NBT = 1;
std::cout << "(the time score in debug mode is not relevant) " << std::endl;
#endif
pinocchio::Model model;
std::string filename = PINOCCHIO_MODEL_DIR std::string("/simple_humanoid.urdf");
if (argc > 1)
filename = argv[1];
bool with_ff = true;
if (argc > 2)
{
const std::string ff_option = argv[2];
if (ff_option == "-no-ff")
with_ff = false;
}
if (filename == "H")
pinocchio::buildModels::humanoidRandom(model, true);
else if (with_ff)
pinocchio::urdf::buildModel(filename, JointModelFreeFlyer(), model);
else
pinocchio::urdf::buildModel(filename, model);
std::cout << "nq = " << model.nq << std::endl;
std::cout << "nv = " << model.nv << std::endl;
std::cout << "--" << std::endl;
pinocchio::Data data(model);
const std::string RF = "RLEG_ANKLE_R";
const std::string LF = "LLEG_ANKLE_R";
PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) contact_models_6D6D;
RigidConstraintModel ci_RF(CONTACT_6D, model, model.getFrameId(RF), LOCAL);
RigidConstraintModel ci_LF(CONTACT_6D, model, model.getFrameId(LF), LOCAL);
contact_models_6D6D.push_back(ci_RF);
contact_models_6D6D.push_back(ci_LF);
PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintData) contact_datas_6D6D;
RigidConstraintData cd_RF(ci_RF);
contact_datas_6D6D.push_back(cd_RF);
RigidConstraintData cd_LF(ci_LF);
contact_datas_6D6D.push_back(cd_LF);
VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
CodeGenRNEA<double> rnea_code_gen(model);
rnea_code_gen.initLib();
rnea_code_gen.loadLib();
CodeGenABA<double> aba_code_gen(model);
aba_code_gen.initLib();
aba_code_gen.loadLib();
CodeGenCRBA<double> crba_code_gen(model);
crba_code_gen.initLib();
crba_code_gen.loadLib();
CodeGenMinv<double> minv_code_gen(model);
minv_code_gen.initLib();
minv_code_gen.loadLib();
CodeGenRNEADerivatives<double> rnea_derivatives_code_gen(model);
rnea_derivatives_code_gen.initLib();
rnea_derivatives_code_gen.loadLib();
CodeGenABADerivatives<double> aba_derivatives_code_gen(model);
aba_derivatives_code_gen.initLib();
aba_derivatives_code_gen.loadLib();
CodeGenConstraintDynamicsDerivatives<double> constraint_dynamics_derivatives_code_gen(
model, contact_models_6D6D);
constraint_dynamics_derivatives_code_gen.initLib();
constraint_dynamics_derivatives_code_gen.loadLib();
pinocchio::container::aligned_vector<VectorXd> qs(NBT);
pinocchio::container::aligned_vector<VectorXd> qdots(NBT);
pinocchio::container::aligned_vector<VectorXd> qddots(NBT);
pinocchio::container::aligned_vector<VectorXd> taus(NBT);
for (size_t i = 0; i < NBT; i)
{
qs[i] = randomConfiguration(model, -qmax, qmax);
qdots[i] = Eigen::VectorXd::Random(model.nv);
qddots[i] = Eigen::VectorXd::Random(model.nv);
taus[i] = Eigen::VectorXd::Random(model.nv);
}
timer.tic();
SMOOTH(NBT)
{
rnea(model, data, qs[_smooth], qdots[_smooth], qddots[_smooth]);
}
std::cout << "RNEA = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
rnea_code_gen.evalFunction(qs[_smooth], qdots[_smooth], qddots[_smooth]);
}
std::cout << "RNEA generated = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
rnea_code_gen.evalJacobian(qs[_smooth], qdots[_smooth], qddots[_smooth]);
}
std::cout << "RNEA partial derivatives auto diff code gen = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
rnea_derivatives_code_gen.evalFunction(qs[_smooth], qdots[_smooth], qddots[_smooth]);
}
std::cout << "RNEA partial derivatives code gen = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
aba(model, data, qs[_smooth], qdots[_smooth], taus[_smooth], Convention::WORLD);
}
timer.toc();
timer.tic();
SMOOTH(NBT)
{
crba(model, data, qs[_smooth], Convention::WORLD);
}
std::cout << "CRBA = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
crba_code_gen.evalFunction(qs[_smooth]);
}
std::cout << "CRBA generated = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
computeMinverse(model, data, qs[_smooth]);
}
std::cout << "Minv = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
minv_code_gen.evalFunction(qs[_smooth]);
}
std::cout << "Minv generated = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
aba(model, data, qs[_smooth], qdots[_smooth], taus[_smooth], Convention::WORLD);
}
std::cout << "ABA = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
aba_code_gen.evalFunction(qs[_smooth], qdots[_smooth], taus[_smooth]);
}
std::cout << "ABA generated = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
aba_code_gen.evalJacobian(qs[_smooth], qdots[_smooth], taus[_smooth]);
}
std::cout << "ABA partial derivatives auto diff code gen = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
aba_derivatives_code_gen.evalFunction(qs[_smooth], qdots[_smooth], qddots[_smooth]);
}
std::cout << "ABA partial derivatives code gen = \t\t";
timer.toc(std::cout, NBT);
pinocchio::initConstraintDynamics(model, data, contact_models_6D6D);
timer.tic();
SMOOTH(NBT)
{
pinocchio::constraintDynamics(
model, data, qs[_smooth], qdots[_smooth], qddots[_smooth], contact_models_6D6D,
contact_datas_6D6D);
pinocchio::computeConstraintDynamicsDerivatives(
model, data, contact_models_6D6D, contact_datas_6D6D);
}
std::cout << "contact dynamics derivatives 6D,6D = \t\t";
timer.toc(std::cout, NBT);
timer.tic();
SMOOTH(NBT)
{
constraint_dynamics_derivatives_code_gen.evalFunction(
qs[_smooth], qdots[_smooth], qddots[_smooth]);
}
std::cout << "contact dynamics derivatives 6D,6D code gen = \t\t";
timer.toc(std::cout, NBT);
return 0;
}