GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: examples/kinematics-derivatives.cpp Lines: 16 16 100.0 %
Date: 2024-01-23 21:41:47 Branches: 25 58 43.1 %

Line Branch Exec Source
1
#include "pinocchio/parsers/urdf.hpp"
2
3
#include "pinocchio/algorithm/joint-configuration.hpp"
4
#include "pinocchio/algorithm/kinematics-derivatives.hpp"
5
6
#include <iostream>
7
8
// PINOCCHIO_MODEL_DIR is defined by the CMake but you can define your own directory here.
9
#ifndef PINOCCHIO_MODEL_DIR
10
  #define PINOCCHIO_MODEL_DIR "path_to_the_model_dir"
11
#endif
12
1
int main(int argc, char ** argv)
13
{
14
  using namespace pinocchio;
15
16
  // You should change here to set up your own URDF file or just pass it as an argument of this example.
17





3
  const std::string urdf_filename = (argc<=1) ? PINOCCHIO_MODEL_DIR + std::string("/example-robot-data/robots/ur_description/urdf/ur5_robot.urdf") : argv[1];
18
19
  // Load the URDF model
20
2
  Model model;
21
1
  pinocchio::urdf::buildModel(urdf_filename,model);
22
23
  // Build a data related to model
24
2
  Data data(model);
25
26
  // Sample a random joint configuration as well as random joint velocity and acceleration
27
2
  Eigen::VectorXd q = randomConfiguration(model);
28

2
  Eigen::VectorXd v = Eigen::VectorXd::Zero(model.nv);
29

2
  Eigen::VectorXd a = Eigen::VectorXd::Zero(model.nv);
30
31
  // Computes the kinematics derivatives for all the joints of the robot
32
1
  computeForwardKinematicsDerivatives(model, data, q, v, a);
33
34
  // Retrieve the kinematics derivatives of a specific joint, expressed in the LOCAL frame of the joints.
35
1
  JointIndex joint_id = (JointIndex)(model.njoints-1);
36


2
  Data::Matrix6x v_partial_dq(6,model.nv), a_partial_dq(6,model.nv), a_partial_dv(6,model.nv), a_partial_da(6,model.nv);
37
1
  v_partial_dq.setZero();
38

1
  a_partial_dq.setZero(); a_partial_dv.setZero(); a_partial_da.setZero();
39
1
  getJointAccelerationDerivatives(model,data,joint_id,LOCAL,v_partial_dq,
40
                                  a_partial_dq,a_partial_dv,a_partial_da);
41
42
  // Remark: we are not directly computing the quantity v_partial_dv as it is also equal to a_partial_da.
43
44
  // But we can also expressed the same quantities in the frame centered on the end-effector joint, but expressed in the axis aligned with the world frame.
45
1
  getJointAccelerationDerivatives(model,data,joint_id,WORLD,v_partial_dq,
46
                                  a_partial_dq,a_partial_dv,a_partial_da);
47
48
1
}