GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/algorithm/expose-jacobian.cpp Lines: 18 29 62.1 %
Date: 2024-01-23 21:41:47 Branches: 12 36 33.3 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2015-2020 CNRS INRIA
3
//
4
5
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
6
#include "pinocchio/algorithm/jacobian.hpp"
7
8
namespace pinocchio
9
{
10
  namespace python
11
  {
12
13
    static Data::Matrix6x
14
89
    compute_jacobian_proxy(const Model & model,
15
                           Data & data,
16
                           const Eigen::VectorXd & q,
17
                           Model::JointIndex jointId)
18
    {
19

89
      Data::Matrix6x J(6,model.nv); J.setZero();
20
89
      computeJointJacobian(model,data,q,jointId,J);
21
22
89
      return J;
23
    }
24
25
    static Data::Matrix6x
26
    get_jacobian_proxy(const Model & model,
27
                       Data & data,
28
                       Model::JointIndex jointId,
29
                       ReferenceFrame rf)
30
    {
31
      Data::Matrix6x J(6,model.nv); J.setZero();
32
      getJointJacobian(model,data,jointId,rf,J);
33
34
      return J;
35
    }
36
37
    static Data::Matrix6x
38
    get_jacobian_time_variation_proxy(const Model & model,
39
                                      Data & data,
40
                                      Model::JointIndex jointId,
41
                                      ReferenceFrame rf)
42
    {
43
      Data::Matrix6x dJ(6,model.nv); dJ.setZero();
44
      getJointJacobianTimeVariation(model,data,jointId,rf,dJ);
45
46
      return dJ;
47
    }
48
49
19
    void exposeJacobian()
50
    {
51
      using namespace Eigen;
52
53
19
      bp::def("computeJointJacobians",
54
              &computeJointJacobians<double,0,JointCollectionDefaultTpl,VectorXd>,
55
38
              bp::args("model","data","q"),
56
              "Computes the full model Jacobian, i.e. the stack of all the motion subspaces expressed in the coordinate world frame.\n"
57
              "The result is accessible through data.J. This function computes also the forward kinematics of the model.\n\n"
58
              "Parameters:\n"
59
              "\tmodel: model of the kinematic tree\n"
60
              "\tdata: data related to the model\n"
61
              "\tq: the joint configuration vector (size model.nq)\n",
62
              bp::return_value_policy<bp::return_by_value>());
63
64
19
      bp::def("computeJointJacobians",
65
              &computeJointJacobians<double,0,JointCollectionDefaultTpl>,
66
38
              bp::args("model","data"),
67
              "Computes the full model Jacobian, i.e. the stack of all motion subspace expressed in the world frame.\n"
68
              "The result is accessible through data.J. This function assumes that forward kinematics (pinocchio.forwardKinematics) has been called first.\n\n"
69
              "Parameters:\n"
70
              "\tmodel: model of the kinematic tree\n"
71
              "\tdata: data related to the model\n",
72
              bp::return_value_policy<bp::return_by_value>());
73
74
19
      bp::def("computeJointJacobian",compute_jacobian_proxy,
75
38
              bp::args("model","data","q","joint_id"),
76
              "Computes the Jacobian of a specific joint frame expressed in the local frame of the joint according to the given input configuration.\n\n"
77
              "Parameters:\n"
78
              "\tmodel: model of the kinematic tree\n"
79
              "\tdata: data related to the model\n"
80
              "\tq: the joint configuration vector (size model.nq)\n"
81
              "\tjoint_id: index of the joint\n");
82
83
19
      bp::def("getJointJacobian",get_jacobian_proxy,
84
38
              bp::args("model","data","joint_id","reference_frame"),
85
              "Computes the jacobian of a given given joint according to the given entries in data.\n"
86
              "If reference_frame is set to LOCAL, it returns the Jacobian expressed in the local coordinate system of the joint.\n"
87
              "If reference_frame is set to LOCAL_WORLD_ALIGNED, it returns the Jacobian expressed in the coordinate system of the frame centered on the joint, but aligned with the WORLD axes.\n"
88
              "If reference_frame is set to WORLD, it returns the Jacobian expressed in the coordinate system of the frame associated to the WORLD.\n\n"
89
              "Parameters:\n"
90
              "\tmodel: model of the kinematic tree\n"
91
              "\tdata: data related to the model\n"
92
              "\tjoint_id: index of the joint\n"
93
              "\treference_frame: reference frame in which the resulting derivatives are expressed\n");
94
95
19
      bp::def("computeJointJacobiansTimeVariation",computeJointJacobiansTimeVariation<double,0,JointCollectionDefaultTpl,VectorXd,VectorXd>,
96
38
              bp::args("model","data","q","v"),
97
              "Computes the full model Jacobian variations with respect to time. It corresponds to dJ/dt which depends both on q and v. It also computes the joint Jacobian of the model (similar to computeJointJacobians)."
98
              "The result is accessible through data.dJ and data.J.\n\n"
99
              "Parameters:\n"
100
              "\tmodel: model of the kinematic tree\n"
101
              "\tdata: data related to the model\n"
102
              "\tq: the joint configuration vector (size model.nq)\n"
103
              "\tv: the joint velocity vector (size model.nv)\n",
104
              bp::return_value_policy<bp::return_by_value>());
105
106
19
      bp::def("getJointJacobianTimeVariation",get_jacobian_time_variation_proxy,
107
38
              bp::args("model","data","joint_id","reference_frame"),
108
              "Computes the Jacobian time variation of a specific joint expressed in the requested frame provided by the value of reference_frame."
109
              "You have to call computeJointJacobiansTimeVariation first. This function also computes the full model Jacobian contained in data.J.\n"
110
              "If reference_frame is set to LOCAL, it returns the Jacobian expressed in the local coordinate system of the joint.\n"
111
              "If reference_frame is set to LOCAL_WORLD_ALIGNED, it returns the Jacobian expressed in the coordinate system of the frame centered on the joint, but aligned with the WORLD axes.\n"
112
              "If reference_frame is set to WORLD, it returns the Jacobian expressed in the coordinate system of the frame associated to the WORLD.\n\n"
113
              "Parameters:\n"
114
              "\tmodel: model of the kinematic tree\n"
115
              "\tdata: data related to the model\n"
116
              "\tjoint_id: index of the joint\n"
117
              "\treference_frame: reference frame in which the resulting derivatives are expressed\n");
118
19
    }
119
120
  } // namespace python
121
} // namespace pinocchio