benchmark.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <algorithm>
4 #include <string>
5 #include <vector>
6 #include <cstdlib>
7 #include <iomanip>
8 #include <sstream>
9 
13 #include "rdl_benchmark/Timer.h"
14 #include "rdl_dynamics/Contacts.h"
15 #include "rdl_dynamics/Dynamics.h"
16 #include "rdl_dynamics/Model.h"
18 
19 bool have_urdfreader = true;
20 bool urdf_floating_base = false;
21 
22 using namespace std;
23 using namespace RobotDynamics;
24 using namespace RobotDynamics::Math;
25 
28 
32 bool benchmark_run_crba = true;
33 bool benchmark_run_nle = true;
36 
37 string model_file = "";
38 
40 {
42 };
43 
44 double run_forward_dynamics_ABA_benchmark(ModelPtr model, int sample_count)
45 {
46  SampleData sample_data;
47  sample_data.fillRandom(model->dof_count, sample_count);
48 
49  TimerInfo tinfo;
50  timer_start(&tinfo);
51 
52  for(int i = 0; i < sample_count; i++)
53  {
54  forwardDynamics(*model, sample_data.q[i], sample_data.qdot[i], sample_data.tau[i], sample_data.qddot[i]);
55  }
56 
57  double duration = timer_stop(&tinfo);
58 
59  cout << "#DOF: " << setw(3) << model->dof_count << " #samples: " << sample_count << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
60 
61  return duration;
62 }
63 
64 double run_forward_dynamics_lagrangian_benchmark(ModelPtr model, int sample_count)
65 {
66  SampleData sample_data;
67  sample_data.fillRandom(model->dof_count, sample_count);
68 
69  TimerInfo tinfo;
70  timer_start(&tinfo);
71 
72  MatrixNd H(MatrixNd::Zero(model->dof_count, model->dof_count));
73  VectorNd C(VectorNd::Zero(model->dof_count));
74 
75  for(int i = 0; i < sample_count; i++)
76  {
77  forwardDynamicsLagrangian(*model, sample_data.q[i], sample_data.qdot[i], sample_data.tau[i], sample_data.qddot[i], H, C, Math::LinearSolverPartialPivLU, NULL);
78  }
79 
80  double duration = timer_stop(&tinfo);
81 
82  cout << "#DOF: " << setw(3) << model->dof_count << " #samples: " << sample_count << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
83 
84  return duration;
85 }
86 
87 double run_inverse_dynamics_RNEA_benchmark(ModelPtr model, int sample_count)
88 {
89  SampleData sample_data;
90  sample_data.fillRandom(model->dof_count, sample_count);
91 
92  TimerInfo tinfo;
93  timer_start(&tinfo);
94 
95  for(int i = 0; i < sample_count; i++)
96  {
97  inverseDynamics(*model, sample_data.q[i], sample_data.qdot[i], sample_data.qddot[i], sample_data.tau[i]);
98  }
99 
100  double duration = timer_stop(&tinfo);
101 
102  cout << "#DOF: " << setw(3) << model->dof_count << " #samples: " << sample_count << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
103 
104  return duration;
105 }
106 
107 double run_CRBA_benchmark(ModelPtr model, int sample_count)
108 {
109  SampleData sample_data;
110  sample_data.fillRandom(model->dof_count, sample_count);
111 
112  Math::MatrixNd H = Math::MatrixNd::Zero(model->dof_count, model->dof_count);
113  Math::MatrixNd identity = Math::MatrixNd::Identity(model->dof_count, model->dof_count);
114  Math::MatrixNd Hinv = Math::MatrixNd::Zero(model->dof_count, model->dof_count);
115 
116  TimerInfo tinfo;
117  timer_start(&tinfo);
118 
119  for(int i = 0; i < sample_count; i++)
120  {
121  compositeRigidBodyAlgorithm(*model, sample_data.q[i], H, true);
122  }
123 
124  double duration = timer_stop(&tinfo);
125 
126  cout << "#DOF: " << setw(3) << model->dof_count << " #samples: " << sample_count << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
127 
128  return duration;
129 }
130 
131 double run_nle_benchmark(ModelPtr model, int sample_count)
132 {
133  SampleData sample_data;
134  sample_data.fillRandom(model->dof_count, sample_count);
135 
136  TimerInfo tinfo;
137  timer_start(&tinfo);
138 
139  for(int i = 0; i < sample_count; i++)
140  {
141  nonlinearEffects(*model, sample_data.q[i], sample_data.qdot[i], sample_data.tau[i]);
142  }
143 
144  double duration = timer_stop(&tinfo);
145 
146  cout << "#DOF: " << setw(3) << model->dof_count << " #samples: " << sample_count << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
147 
148  return duration;
149 }
150 
151 double run_calc_minv_times_tau_benchmark(ModelPtr model, int sample_count)
152 {
153  SampleData sample_data;
154  sample_data.fillRandom(model->dof_count, sample_count);
155 
156  calcMInvTimesTau(*model, sample_data.q[0], sample_data.tau[0], sample_data.qddot[0]);
157 
158  TimerInfo tinfo;
159  timer_start(&tinfo);
160 
161  for(int i = 0; i < sample_count; i++)
162  {
163  calcMInvTimesTau(*model, sample_data.q[i], sample_data.tau[i], sample_data.qddot[i]);
164  }
165 
166  double duration = timer_stop(&tinfo);
167 
168  cout << "#DOF: " << setw(3) << model->dof_count << " #samples: " << sample_count << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
169 
170  return duration;
171 }
172 
173 double run_contacts_lagrangian_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
174 {
175  SampleData sample_data;
176  sample_data.fillRandom(model->dof_count, sample_count);
177 
178  TimerInfo tinfo;
179  timer_start(&tinfo);
180 
181  for(int i = 0; i < sample_count; i++)
182  {
183  forwardDynamicsContactsDirect(*model, sample_data.q[i], sample_data.qdot[i], sample_data.tau[i], *constraint_set, sample_data.qddot[i]);
184  }
185 
186  double duration = timer_stop(&tinfo);
187 
188  return duration;
189 }
190 
191 double run_contacts_lagrangian_sparse_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
192 {
193  SampleData sample_data;
194  sample_data.fillRandom(model->dof_count, sample_count);
195 
196  TimerInfo tinfo;
197  timer_start(&tinfo);
198 
199  for(int i = 0; i < sample_count; i++)
200  {
201  forwardDynamicsContactsRangeSpaceSparse(*model, sample_data.q[i], sample_data.qdot[i], sample_data.tau[i], *constraint_set, sample_data.qddot[i]);
202  }
203 
204  double duration = timer_stop(&tinfo);
205 
206  return duration;
207 }
208 
209 double run_contacts_null_space(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
210 {
211  SampleData sample_data;
212  sample_data.fillRandom(model->dof_count, sample_count);
213 
214  TimerInfo tinfo;
215  timer_start(&tinfo);
216 
217  for(int i = 0; i < sample_count; i++)
218  {
219  forwardDynamicsContactsNullSpace(*model, sample_data.q[i], sample_data.qdot[i], sample_data.tau[i], *constraint_set, sample_data.qddot[i]);
220  }
221 
222  double duration = timer_stop(&tinfo);
223 
224  return duration;
225 }
226 
227 double run_contacts_kokkevis_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
228 {
229  SampleData sample_data;
230  sample_data.fillRandom(model->dof_count, sample_count);
231 
232  TimerInfo tinfo;
233  timer_start(&tinfo);
234 
235  for(int i = 0; i < sample_count; i++)
236  {
237  forwardDynamicsContactsKokkevis(*model, sample_data.q[i], sample_data.qdot[i], sample_data.tau[i], *constraint_set, sample_data.qddot[i]);
238  }
239 
240  double duration = timer_stop(&tinfo);
241 
242  return duration;
243 }
244 
245 double contacts_benchmark(int sample_count, ContactsMethod contacts_method)
246 {
247  // initialize the human model
248  ModelPtr model(new Model());
249  generate_human36model(model);
250 
251  // initialize the constraint sets
252  unsigned int foot_r = model->GetBodyId("foot_r");
253  unsigned int foot_l = model->GetBodyId("foot_l");
254  unsigned int hand_r = model->GetBodyId("hand_r");
255  unsigned int hand_l = model->GetBodyId("hand_l");
256 
257  ConstraintSet one_body_one_constraint;
258  ConstraintSet two_bodies_one_constraint;
259  ConstraintSet four_bodies_one_constraint;
260 
261  ConstraintSet one_body_four_constraints;
262  ConstraintSet two_bodies_four_constraints;
263  ConstraintSet four_bodies_four_constraints;
264 
265  LinearSolver linear_solver = LinearSolverPartialPivLU;
266 
267  one_body_one_constraint.linear_solver = linear_solver;
268  two_bodies_one_constraint.linear_solver = linear_solver;
269  four_bodies_one_constraint.linear_solver = linear_solver;
270  one_body_four_constraints.linear_solver = linear_solver;
271  two_bodies_four_constraints.linear_solver = linear_solver;
272  four_bodies_four_constraints.linear_solver = linear_solver;
273 
274  // one_body_one
275  one_body_one_constraint.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
276  one_body_one_constraint.bind(*model);
277 
278  // two_bodies_one
279  two_bodies_one_constraint.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
280  two_bodies_one_constraint.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
281  two_bodies_one_constraint.bind(*model);
282 
283  // four_bodies_one
284  four_bodies_one_constraint.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
285  four_bodies_one_constraint.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
286  four_bodies_one_constraint.addConstraint(hand_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
287  four_bodies_one_constraint.addConstraint(hand_l, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
288  four_bodies_one_constraint.bind(*model);
289 
290  // one_body_four
291  one_body_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
292  one_body_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 1., 0.));
293  one_body_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 0., 1.));
294  one_body_four_constraints.addConstraint(foot_r, Vector3d(-0.1, 0., -0.05), Vector3d(1., 0., 0.));
295  one_body_four_constraints.bind(*model);
296 
297  // two_bodies_four
298  two_bodies_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
299  two_bodies_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 1., 0.));
300  two_bodies_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 0., 1.));
301  two_bodies_four_constraints.addConstraint(foot_r, Vector3d(-0.1, 0., -0.05), Vector3d(1., 0., 0.));
302 
303  two_bodies_four_constraints.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
304  two_bodies_four_constraints.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(0., 1., 0.));
305  two_bodies_four_constraints.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(0., 0., 1.));
306  two_bodies_four_constraints.addConstraint(foot_l, Vector3d(-0.1, 0., -0.05), Vector3d(1., 0., 0.));
307 
308  two_bodies_four_constraints.bind(*model);
309 
310  // four_bodies_four
311  four_bodies_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
312  four_bodies_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 1., 0.));
313  four_bodies_four_constraints.addConstraint(foot_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 0., 1.));
314  four_bodies_four_constraints.addConstraint(foot_r, Vector3d(-0.1, 0., -0.05), Vector3d(1., 0., 0.));
315 
316  four_bodies_four_constraints.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
317  four_bodies_four_constraints.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(0., 1., 0.));
318  four_bodies_four_constraints.addConstraint(foot_l, Vector3d(0.1, 0., -0.05), Vector3d(0., 0., 1.));
319  four_bodies_four_constraints.addConstraint(foot_l, Vector3d(-0.1, 0., -0.05), Vector3d(1., 0., 0.));
320 
321  four_bodies_four_constraints.addConstraint(hand_r, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
322  four_bodies_four_constraints.addConstraint(hand_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 1., 0.));
323  four_bodies_four_constraints.addConstraint(hand_r, Vector3d(0.1, 0., -0.05), Vector3d(0., 0., 1.));
324  four_bodies_four_constraints.addConstraint(hand_r, Vector3d(-0.1, 0., -0.05), Vector3d(1., 0., 0.));
325 
326  four_bodies_four_constraints.addConstraint(hand_l, Vector3d(0.1, 0., -0.05), Vector3d(1., 0., 0.));
327  four_bodies_four_constraints.addConstraint(hand_l, Vector3d(0.1, 0., -0.05), Vector3d(0., 1., 0.));
328  four_bodies_four_constraints.addConstraint(hand_l, Vector3d(0.1, 0., -0.05), Vector3d(0., 0., 1.));
329  four_bodies_four_constraints.addConstraint(hand_l, Vector3d(-0.1, 0., -0.05), Vector3d(1., 0., 0.));
330 
331  four_bodies_four_constraints.bind(*model);
332 
333  cout << "= #DOF: " << setw(3) << model->dof_count << endl;
334  cout << "= #samples: " << sample_count << endl;
335  cout << "= No constraints (Articulated Body Algorithm):" << endl;
336  run_forward_dynamics_ABA_benchmark(model, sample_count);
337  cout << "= Constraints:" << endl;
338  double duration;
339 
340  // one body one
341  if(contacts_method == ContactsMethodLagrangian)
342  {
343  duration = run_contacts_lagrangian_benchmark(model, &one_body_one_constraint, sample_count);
344  }
345  else if(contacts_method == ContactsMethodRangeSpaceSparse)
346  {
347  duration = run_contacts_lagrangian_sparse_benchmark(model, &one_body_one_constraint, sample_count);
348  }
349  else if(contacts_method == ContactsMethodNullSpace)
350  {
351  duration = run_contacts_null_space(model, &one_body_one_constraint, sample_count);
352  }
353  else
354  {
355  duration = run_contacts_kokkevis_benchmark(model, &one_body_one_constraint, sample_count);
356  }
357 
358  cout << "ConstraintSet: 1 Body 1 Constraint : " << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
359 
360  // two_bodies_one
361  if(contacts_method == ContactsMethodLagrangian)
362  {
363  duration = run_contacts_lagrangian_benchmark(model, &two_bodies_one_constraint, sample_count);
364  }
365  else if(contacts_method == ContactsMethodRangeSpaceSparse)
366  {
367  duration = run_contacts_lagrangian_sparse_benchmark(model, &two_bodies_one_constraint, sample_count);
368  }
369  else if(contacts_method == ContactsMethodNullSpace)
370  {
371  duration = run_contacts_null_space(model, &two_bodies_one_constraint, sample_count);
372  }
373  else
374  {
375  duration = run_contacts_kokkevis_benchmark(model, &two_bodies_one_constraint, sample_count);
376  }
377 
378  cout << "ConstraintSet: 2 Bodies 1 Constraint : " << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
379 
380 
381  // four_bodies_one
382  if(contacts_method == ContactsMethodLagrangian)
383  {
384  duration = run_contacts_lagrangian_benchmark(model, &four_bodies_one_constraint, sample_count);
385  }
386  else if(contacts_method == ContactsMethodRangeSpaceSparse)
387  {
388  duration = run_contacts_lagrangian_sparse_benchmark(model, &four_bodies_one_constraint, sample_count);
389  }
390  else if(contacts_method == ContactsMethodNullSpace)
391  {
392  duration = run_contacts_null_space(model, &four_bodies_one_constraint, sample_count);
393  }
394  else
395  {
396  duration = run_contacts_kokkevis_benchmark(model, &four_bodies_one_constraint, sample_count);
397  }
398 
399  cout << "ConstraintSet: 4 Bodies 1 Constraint : " << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
400 
401  // one_body_four
402  if(contacts_method == ContactsMethodLagrangian)
403  {
404  duration = run_contacts_lagrangian_benchmark(model, &one_body_four_constraints, sample_count);
405  }
406  else if(contacts_method == ContactsMethodRangeSpaceSparse)
407  {
408  duration = run_contacts_lagrangian_sparse_benchmark(model, &one_body_four_constraints, sample_count);
409  }
410  else if(contacts_method == ContactsMethodNullSpace)
411  {
412  duration = run_contacts_null_space(model, &one_body_four_constraints, sample_count);
413  }
414  else
415  {
416  duration = run_contacts_kokkevis_benchmark(model, &one_body_four_constraints, sample_count);
417  }
418 
419  cout << "ConstraintSet: 1 Body 4 Constraints : " << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
420 
421  // two_bodies_four
422  if(contacts_method == ContactsMethodLagrangian)
423  {
424  duration = run_contacts_lagrangian_benchmark(model, &two_bodies_four_constraints, sample_count);
425  }
426  else if(contacts_method == ContactsMethodRangeSpaceSparse)
427  {
428  duration = run_contacts_lagrangian_sparse_benchmark(model, &two_bodies_four_constraints, sample_count);
429  }
430  else if(contacts_method == ContactsMethodNullSpace)
431  {
432  duration = run_contacts_null_space(model, &two_bodies_four_constraints, sample_count);
433  }
434  else
435  {
436  duration = run_contacts_kokkevis_benchmark(model, &two_bodies_four_constraints, sample_count);
437  }
438 
439  cout << "ConstraintSet: 2 Bodies 4 Constraints: " << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
440 
441 
442  // four_bodies_four
443  if(contacts_method == ContactsMethodLagrangian)
444  {
445  duration = run_contacts_lagrangian_benchmark(model, &four_bodies_four_constraints, sample_count);
446  }
447  else if(contacts_method == ContactsMethodRangeSpaceSparse)
448  {
449  duration = run_contacts_lagrangian_sparse_benchmark(model, &four_bodies_four_constraints, sample_count);
450  }
451  else if(contacts_method == ContactsMethodNullSpace)
452  {
453  duration = run_contacts_null_space(model, &four_bodies_four_constraints, sample_count);
454  }
455  else
456  {
457  duration = run_contacts_kokkevis_benchmark(model, &four_bodies_four_constraints, sample_count);
458  }
459 
460  cout << "ConstraintSet: 4 Bodies 4 Constraints: " << " duration = " << setw(10) << duration << "(s)" << " (~" << setw(10) << duration / sample_count << "(s) per call)" << endl;
461 
462  return duration;
463 }
464 
466 {
467  cout << "Usage: benchmark [--count|-c <sample_count>] [--depth|-d <depth>]" << endl;
468 #
469 
470  cout << "Simple benchmark tool for the Rigid Body Dynamics Library." << endl;
471  cout << " --count | -c <sample_count> : sets the number of sample states that should" << endl;
472  cout << " be calculated (default: 1000)" << endl;
473  cout << " --depth | -d <depth> : sets maximum depth for the branched test model" << endl;
474  cout << " which is created increased from 1 to <depth> (default: 5)." << endl;
475 #if defined RBDL_BUILD_ADDON_URDFREADER
476  cout << " --floating-base | -f : the specified URDF model is a floating base model." << endl;
477 #endif
478  cout << " --no-fd : disables benchmarking of forward dynamics." << endl;
479  cout << " --no-fd-aba : disables benchmark for forwards dynamics using" << endl;
480  cout << " the Articulated Body Algorithm" << endl;
481  cout << " --no-fd-lagrangian : disables benchmark for forward dynamics via" << endl;
482  cout << " solving the lagrangian equation." << endl;
483  cout << " --no-id-rnea : disables benchmark for inverse dynamics using" << endl;
484  cout << " the recursive newton euler algorithm." << endl;
485  cout << " --no-crba : disables benchmark for joint space inertia" << endl;
486  cout << " matrix computation using the composite rigid" << endl;
487  cout << " body algorithm." << endl;
488  cout << " --no-nle : disables benchmark for the nonlinear effects." << endl;
489  cout << " --no-calc-minv : disables benchmark M^-1 * tau benchmark." << endl;
490  cout << " --only-contacts | -C : only runs contact model benchmarks." << endl;
491  cout << " --help | -h : prints this help." << endl;
492 }
493 
495 {
496  benchmark_run_fd_aba = false;
498  benchmark_run_id_rnea = false;
499  benchmark_run_crba = false;
500  benchmark_run_nle = false;
502  benchmark_run_contacts = false;
503 }
504 
505 void parse_args(int argc, char *argv[])
506 {
507  int argi = 1;
508 
509  while(argi < argc)
510  {
511  string arg = argv[argi];
512 
513  if(arg == "--help" || arg == "-h")
514  {
515  print_usage();
516  exit(1);
517  }
518  else if(arg == "--count" || arg == "-c")
519  {
520  if(argi == argc - 1)
521  {
522  print_usage();
523 
524  cerr << "Error: missing number of samples!" << endl;
525  exit(1);
526  }
527 
528  argi++;
529  stringstream count_stream(argv[argi]);
530 
531  count_stream >> benchmark_sample_count;
532  }
533  else if(arg == "--depth" || arg == "-d")
534  {
535  if(argi == argc - 1)
536  {
537  print_usage();
538 
539  cerr << "Error: missing number for model depth!" << endl;
540  exit(1);
541  }
542 
543  argi++;
544  stringstream depth_stream(argv[argi]);
545 
546  depth_stream >> benchmark_model_max_depth;
547 #ifdef RBDL_BUILD_ADDON_URDFREADER
548  } else if (arg == "--floating-base" || arg == "-f") {
549  urdf_floating_base = true;
550 #endif
551  }
552  else if(arg == "--no-fd")
553  {
554  benchmark_run_fd_aba = false;
556  }
557  else if(arg == "--no-fd-aba")
558  {
559  benchmark_run_fd_aba = false;
560  }
561  else if(arg == "--no-fd-lagrangian")
562  {
564  }
565  else if(arg == "--no-id-rnea")
566  {
567  benchmark_run_id_rnea = false;
568  }
569  else if(arg == "--no-crba")
570  {
571  benchmark_run_crba = false;
572  }
573  else if(arg == "--no-nle")
574  {
575  benchmark_run_nle = false;
576  }
577  else if(arg == "--no-calc-minv")
578  {
580  }
581  else if(arg == "--only-contacts" || arg == "-C")
582  {
584  benchmark_run_contacts = true;
585  }
586  else
587  {
588  print_usage();
589  cerr << "Invalid argument '" << arg << "'." << endl;
590  exit(1);
591  }
592  argi++;
593  }
594 }
595 
596 int main(int argc, char *argv[])
597 {
598  parse_args(argc, argv);
599 
600  ModelPtr model(new Model());
601 
602  if(model_file != "")
603  {
605 
607  {
608  cout << "= Forward Dynamics: ABA =" << endl;
610  }
611 
613  {
614  cout << "= Forward Dynamics: Lagrangian (Piv. LU decomposition) =" << endl;
616  }
617 
619  {
620  cout << "= Inverse Dynamics: RNEA =" << endl;
622  }
623 
625  {
626  cout << "= Joint Space Inertia Matrix: CRBA =" << endl;
628  }
629 
631  {
632  cout << "= Nonlinear effects =" << endl;
634  }
635 
636  return 0;
637  }
638 
639  cout << endl;
640 
642  {
643  cout << "= Forward Dynamics: ABA =" << endl;
644  for(int depth = 1; depth <= benchmark_model_max_depth; depth++)
645  {
646  model.reset(new Model());
647  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
648 
649  generate_planar_tree(model, depth);
650 
652  }
653  cout << endl;
654  }
655 
657  {
658  cout << "= Forward Dynamics: Lagrangian (Piv. LU decomposition) =" << endl;
659  for(int depth = 1; depth <= benchmark_model_max_depth; depth++)
660  {
661  model.reset(new Model());
662  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
663 
664  generate_planar_tree(model, depth);
665 
667  }
668  cout << endl;
669  }
670 
672  {
673  cout << "= Inverse Dynamics: RNEA =" << endl;
674  for(int depth = 1; depth <= benchmark_model_max_depth; depth++)
675  {
676  model.reset(new Model());
677  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
678 
679  generate_planar_tree(model, depth);
680 
682  }
683  cout << endl;
684  }
685 
687  {
688  cout << "= Joint Space Inertia Matrix: CRBA =" << endl;
689  for(int depth = 1; depth <= benchmark_model_max_depth; depth++)
690  {
691  model.reset(new Model());
692  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
693 
694  generate_planar_tree(model, depth);
695 
697  }
698  cout << endl;
699  }
700 
702  {
703  cout << "= Nonlinear Effects =" << endl;
704  for(int depth = 1; depth <= benchmark_model_max_depth; depth++)
705  {
706  model.reset(new Model());
707  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
708 
709  generate_planar_tree(model, depth);
710 
712  }
713  cout << endl;
714  }
715 
717  {
718  cout << "= CalcMInvTimesTau =" << endl;
719  for(int depth = 1; depth <= benchmark_model_max_depth; depth++)
720  {
721  model.reset(new Model());
722  model->gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
723 
724  generate_planar_tree(model, depth);
725 
727  }
728  cout << endl;
729  }
730 
732  {
733  cout << "= Contacts: ForwardDynamicsContactsLagrangian" << endl;
735 
736  cout << "= Contacts: ForwardDynamicsContactsRangeSpaceSparse" << endl;
738 
739  cout << "= Contacts: ForwardDynamicsContactsNullSpace" << endl;
741 
742  cout << "= Contacts: ForwardDynamicsContactsKokkevis" << endl;
744  }
745 
746  return 0;
747 }
bool benchmark_run_contacts
Definition: benchmark.cc:35
void compositeRigidBodyAlgorithm(Model &model, const Math::VectorNd &Q, Math::MatrixNd &H, bool update_kinematics=true)
int benchmark_sample_count
Definition: benchmark.cc:26
double run_inverse_dynamics_RNEA_benchmark(ModelPtr model, int sample_count)
Definition: benchmark.cc:87
bool have_urdfreader
Definition: benchmark.cc:19
bool benchmark_run_calc_minv_times_tau
Definition: benchmark.cc:34
std::shared_ptr< Model > ModelPtr
double contacts_benchmark(int sample_count, ContactsMethod contacts_method)
Definition: benchmark.cc:245
void generate_planar_tree(RobotDynamics::ModelPtr model, int depth)
unsigned int addConstraint(unsigned int body_id, const Math::Vector3d &body_point, const Math::Vector3d &world_normal, const char *constraint_name=NULL, double normal_acceleration=0.)
bool benchmark_run_fd_aba
Definition: benchmark.cc:29
bool benchmark_run_id_rnea
Definition: benchmark.cc:31
RobotDynamics::Math::VectorNd * qddot
Definition: SampleData.h:48
void forwardDynamicsContactsRangeSpaceSparse(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, ConstraintSet &CS, Math::VectorNd &QDDot)
double timer_stop(TimerInfo *timer)
Definition: Timer.h:27
double run_forward_dynamics_ABA_benchmark(ModelPtr model, int sample_count)
Definition: benchmark.cc:44
LinearSolver
void forwardDynamicsContactsDirect(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, ConstraintSet &CS, Math::VectorNd &QDDot)
void generate_human36model(RobotDynamics::ModelPtr model)
Definition: Human36Model.cc:30
double run_CRBA_benchmark(ModelPtr model, int sample_count)
Definition: benchmark.cc:107
RobotDynamics::Math::VectorNd * tau
Definition: SampleData.h:49
bool benchmark_run_nle
Definition: benchmark.cc:33
double run_contacts_kokkevis_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
Definition: benchmark.cc:227
double run_contacts_null_space(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
Definition: benchmark.cc:209
double run_forward_dynamics_lagrangian_benchmark(ModelPtr model, int sample_count)
Definition: benchmark.cc:64
Eigen::VectorXd VectorNd
void forwardDynamicsContactsNullSpace(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, ConstraintSet &CS, Math::VectorNd &QDDot)
string model_file
Definition: benchmark.cc:37
bool urdf_floating_base
Definition: benchmark.cc:20
int benchmark_model_max_depth
Definition: benchmark.cc:27
void timer_start(TimerInfo *timer)
Definition: Timer.h:18
LinearSolverPartialPivLU
void calcMInvTimesTau(Model &model, const Math::VectorNd &Q, const Math::VectorNd &Tau, Math::VectorNd &QDDot, bool update_kinematics=true)
bool bind(const Model &model)
void disable_all_benchmarks()
Definition: benchmark.cc:494
int main(int argc, char *argv[])
Definition: benchmark.cc:596
double run_nle_benchmark(ModelPtr model, int sample_count)
Definition: benchmark.cc:131
Eigen::MatrixXd MatrixNd
RobotDynamics::Math::VectorNd * q
Definition: SampleData.h:46
bool urdfReadFromFile(const char *filename, ModelPtr model, bool floating_base, bool verbose=false)
Definition: Timer.h:6
Math::LinearSolver linear_solver
double run_contacts_lagrangian_sparse_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
Definition: benchmark.cc:191
ContactsMethod
Definition: benchmark.cc:39
double run_calc_minv_times_tau_benchmark(ModelPtr model, int sample_count)
Definition: benchmark.cc:151
double run_contacts_lagrangian_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
Definition: benchmark.cc:173
void inverseDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, Math::VectorNd &Tau, Math::SpatialForceV *f_ext=nullptr, bool update_kinematics=true)
void print_usage()
Definition: benchmark.cc:465
void forwardDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, Math::VectorNd &QDDot, Math::SpatialForceV *f_ext=nullptr, bool update_kinematics=true)
void fillRandom(int dof_count, int sample_count)
Definition: SampleData.h:80
void forwardDynamicsLagrangian(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, Math::VectorNd &QDDot, Math::MatrixNd &H, Math::VectorNd &C, Math::LinearSolver linear_solver=Math::LinearSolverColPivHouseholderQR, Math::SpatialForceV *f_ext=nullptr, bool update_kinematics=true)
void nonlinearEffects(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::VectorNd &Tau, bool update_kinematics=true)
bool benchmark_run_fd_lagrangian
Definition: benchmark.cc:30
void parse_args(int argc, char *argv[])
Definition: benchmark.cc:505
RobotDynamics::Math::VectorNd * qdot
Definition: SampleData.h:47
bool benchmark_run_crba
Definition: benchmark.cc:32
void forwardDynamicsContactsKokkevis(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, ConstraintSet &CS, Math::VectorNd &QDDot)


rdl_benchmark
Author(s):
autogenerated on Tue Apr 20 2021 02:25:39