47 sample_data.
fillRandom(model->dof_count, sample_count);
52 for(
int i = 0; i < sample_count; i++)
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;
67 sample_data.
fillRandom(model->dof_count, sample_count);
72 MatrixNd H(MatrixNd::Zero(model->dof_count, model->dof_count));
73 VectorNd C(VectorNd::Zero(model->dof_count));
75 for(
int i = 0; i < sample_count; i++)
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;
90 sample_data.
fillRandom(model->dof_count, sample_count);
95 for(
int i = 0; i < sample_count; i++)
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;
110 sample_data.
fillRandom(model->dof_count, sample_count);
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);
119 for(
int i = 0; i < sample_count; i++)
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;
134 sample_data.
fillRandom(model->dof_count, sample_count);
139 for(
int i = 0; i < sample_count; i++)
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;
154 sample_data.
fillRandom(model->dof_count, sample_count);
161 for(
int i = 0; i < sample_count; i++)
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;
176 sample_data.
fillRandom(model->dof_count, sample_count);
181 for(
int i = 0; i < sample_count; i++)
194 sample_data.
fillRandom(model->dof_count, sample_count);
199 for(
int i = 0; i < sample_count; i++)
212 sample_data.
fillRandom(model->dof_count, sample_count);
217 for(
int i = 0; i < sample_count; i++)
230 sample_data.
fillRandom(model->dof_count, sample_count);
235 for(
int i = 0; i < sample_count; i++)
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");
276 one_body_one_constraint.
bind(*model);
281 two_bodies_one_constraint.
bind(*model);
288 four_bodies_one_constraint.
bind(*model);
295 one_body_four_constraints.
bind(*model);
308 two_bodies_four_constraints.
bind(*model);
331 four_bodies_four_constraints.
bind(*model);
333 cout <<
"= #DOF: " << setw(3) << model->dof_count << endl;
334 cout <<
"= #samples: " << sample_count << endl;
335 cout <<
"= No constraints (Articulated Body Algorithm):" << endl;
337 cout <<
"= Constraints:" << endl;
358 cout <<
"ConstraintSet: 1 Body 1 Constraint : " <<
" duration = " << setw(10) << duration <<
"(s)" <<
" (~" << setw(10) << duration / sample_count <<
"(s) per call)" << endl;
378 cout <<
"ConstraintSet: 2 Bodies 1 Constraint : " <<
" duration = " << setw(10) << duration <<
"(s)" <<
" (~" << setw(10) << duration / sample_count <<
"(s) per call)" << endl;
399 cout <<
"ConstraintSet: 4 Bodies 1 Constraint : " <<
" duration = " << setw(10) << duration <<
"(s)" <<
" (~" << setw(10) << duration / sample_count <<
"(s) per call)" << endl;
419 cout <<
"ConstraintSet: 1 Body 4 Constraints : " <<
" duration = " << setw(10) << duration <<
"(s)" <<
" (~" << setw(10) << duration / sample_count <<
"(s) per call)" << endl;
439 cout <<
"ConstraintSet: 2 Bodies 4 Constraints: " <<
" duration = " << setw(10) << duration <<
"(s)" <<
" (~" << setw(10) << duration / sample_count <<
"(s) per call)" << endl;
460 cout <<
"ConstraintSet: 4 Bodies 4 Constraints: " <<
" duration = " << setw(10) << duration <<
"(s)" <<
" (~" << setw(10) << duration / sample_count <<
"(s) per call)" << endl;
467 cout <<
"Usage: benchmark [--count|-c <sample_count>] [--depth|-d <depth>]" << endl;
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;
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;
511 string arg = argv[argi];
513 if(arg ==
"--help" || arg ==
"-h")
518 else if(arg ==
"--count" || arg ==
"-c")
524 cerr <<
"Error: missing number of samples!" << endl;
529 stringstream count_stream(argv[argi]);
533 else if(arg ==
"--depth" || arg ==
"-d")
539 cerr <<
"Error: missing number for model depth!" << endl;
544 stringstream depth_stream(argv[argi]);
547 #ifdef RBDL_BUILD_ADDON_URDFREADER 548 }
else if (arg ==
"--floating-base" || arg ==
"-f") {
552 else if(arg ==
"--no-fd")
557 else if(arg ==
"--no-fd-aba")
561 else if(arg ==
"--no-fd-lagrangian")
565 else if(arg ==
"--no-id-rnea")
569 else if(arg ==
"--no-crba")
573 else if(arg ==
"--no-nle")
577 else if(arg ==
"--no-calc-minv")
581 else if(arg ==
"--only-contacts" || arg ==
"-C")
589 cerr <<
"Invalid argument '" << arg <<
"'." << endl;
596 int main(
int argc,
char *argv[])
608 cout <<
"= Forward Dynamics: ABA =" << endl;
614 cout <<
"= Forward Dynamics: Lagrangian (Piv. LU decomposition) =" << endl;
620 cout <<
"= Inverse Dynamics: RNEA =" << endl;
626 cout <<
"= Joint Space Inertia Matrix: CRBA =" << endl;
632 cout <<
"= Nonlinear effects =" << endl;
643 cout <<
"= Forward Dynamics: ABA =" << endl;
646 model.reset(
new Model());
658 cout <<
"= Forward Dynamics: Lagrangian (Piv. LU decomposition) =" << endl;
661 model.reset(
new Model());
673 cout <<
"= Inverse Dynamics: RNEA =" << endl;
676 model.reset(
new Model());
688 cout <<
"= Joint Space Inertia Matrix: CRBA =" << endl;
691 model.reset(
new Model());
703 cout <<
"= Nonlinear Effects =" << endl;
706 model.reset(
new Model());
718 cout <<
"= CalcMInvTimesTau =" << endl;
721 model.reset(
new Model());
733 cout <<
"= Contacts: ForwardDynamicsContactsLagrangian" << endl;
736 cout <<
"= Contacts: ForwardDynamicsContactsRangeSpaceSparse" << endl;
739 cout <<
"= Contacts: ForwardDynamicsContactsNullSpace" << endl;
742 cout <<
"= Contacts: ForwardDynamicsContactsKokkevis" << endl;
bool benchmark_run_contacts
void compositeRigidBodyAlgorithm(Model &model, const Math::VectorNd &Q, Math::MatrixNd &H, bool update_kinematics=true)
int benchmark_sample_count
double run_inverse_dynamics_RNEA_benchmark(ModelPtr model, int sample_count)
bool benchmark_run_calc_minv_times_tau
std::shared_ptr< Model > ModelPtr
double contacts_benchmark(int sample_count, ContactsMethod contacts_method)
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
bool benchmark_run_id_rnea
RobotDynamics::Math::VectorNd * qddot
double timer_stop(TimerInfo *timer)
double run_forward_dynamics_ABA_benchmark(ModelPtr model, int sample_count)
void generate_human36model(RobotDynamics::ModelPtr model)
double run_CRBA_benchmark(ModelPtr model, int sample_count)
RobotDynamics::Math::VectorNd * tau
double run_contacts_kokkevis_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
double run_contacts_null_space(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
double run_forward_dynamics_lagrangian_benchmark(ModelPtr model, int sample_count)
int benchmark_model_max_depth
void timer_start(TimerInfo *timer)
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()
int main(int argc, char *argv[])
double run_nle_benchmark(ModelPtr model, int sample_count)
RobotDynamics::Math::VectorNd * q
bool urdfReadFromFile(const char *filename, ModelPtr model, bool floating_base, bool verbose=false)
Math::LinearSolver linear_solver
double run_contacts_lagrangian_sparse_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
double run_calc_minv_times_tau_benchmark(ModelPtr model, int sample_count)
double run_contacts_lagrangian_benchmark(ModelPtr model, ConstraintSet *constraint_set, int sample_count)
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 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)
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
void parse_args(int argc, char *argv[])
RobotDynamics::Math::VectorNd * qdot