| Directory: | ./ |
|---|---|
| File: | bindings/python/algorithm/expose-kinematics-derivatives.cpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 32 | 44 | 72.7% |
| Branches: | 24 | 80 | 30.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2018-2021 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #include "pinocchio/bindings/python/algorithm/algorithms.hpp" | ||
| 6 | #include "pinocchio/algorithm/kinematics-derivatives.hpp" | ||
| 7 | #include "pinocchio/algorithm/center-of-mass-derivatives.hpp" | ||
| 8 | |||
| 9 | #include <boost/python/tuple.hpp> | ||
| 10 | |||
| 11 | namespace pinocchio | ||
| 12 | { | ||
| 13 | namespace python | ||
| 14 | { | ||
| 15 | namespace bp = boost::python; | ||
| 16 | |||
| 17 | 5 | bp::tuple getJointVelocityDerivatives_proxy( | |
| 18 | const context::Model & model, | ||
| 19 | context::Data & data, | ||
| 20 | const JointIndex jointId, | ||
| 21 | ReferenceFrame rf) | ||
| 22 | { | ||
| 23 | typedef context::Data::Matrix6x Matrix6x; | ||
| 24 | |||
| 25 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | Matrix6x partial_dq(Matrix6x::Zero(6, model.nv)); |
| 26 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | Matrix6x partial_dv(Matrix6x::Zero(6, model.nv)); |
| 27 | |||
| 28 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | getJointVelocityDerivatives(model, data, jointId, rf, partial_dq, partial_dv); |
| 29 | |||
| 30 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | return bp::make_tuple(partial_dq, partial_dv); |
| 31 | 5 | } | |
| 32 | |||
| 33 | ✗ | bp::tuple getPointVelocityDerivatives_proxy( | |
| 34 | const context::Model & model, | ||
| 35 | context::Data & data, | ||
| 36 | const JointIndex joint_id, | ||
| 37 | const context::SE3 & placement, | ||
| 38 | ReferenceFrame rf) | ||
| 39 | { | ||
| 40 | typedef context::Data::Matrix3x Matrix3x; | ||
| 41 | |||
| 42 | ✗ | Matrix3x v_partial_dq(Matrix3x::Zero(3, model.nv)); | |
| 43 | ✗ | Matrix3x v_partial_dv(Matrix3x::Zero(3, model.nv)); | |
| 44 | |||
| 45 | ✗ | getPointVelocityDerivatives(model, data, joint_id, placement, rf, v_partial_dq, v_partial_dv); | |
| 46 | |||
| 47 | ✗ | return bp::make_tuple(v_partial_dq, v_partial_dv); | |
| 48 | } | ||
| 49 | |||
| 50 | 5 | bp::tuple getJointAccelerationDerivatives_proxy( | |
| 51 | const context::Model & model, | ||
| 52 | context::Data & data, | ||
| 53 | const JointIndex jointId, | ||
| 54 | ReferenceFrame rf) | ||
| 55 | { | ||
| 56 | typedef context::Data::Matrix6x Matrix6x; | ||
| 57 | |||
| 58 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | Matrix6x v_partial_dq(Matrix6x::Zero(6, model.nv)); |
| 59 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | Matrix6x a_partial_dq(Matrix6x::Zero(6, model.nv)); |
| 60 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | Matrix6x a_partial_dv(Matrix6x::Zero(6, model.nv)); |
| 61 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | Matrix6x a_partial_da(Matrix6x::Zero(6, model.nv)); |
| 62 | |||
| 63 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | getJointAccelerationDerivatives( |
| 64 | model, data, jointId, rf, v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da); | ||
| 65 | |||
| 66 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | return bp::make_tuple(v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da); |
| 67 | 5 | } | |
| 68 | |||
| 69 | ✗ | bp::tuple getPointClassicAccelerationDerivatives_proxy( | |
| 70 | const context::Model & model, | ||
| 71 | context::Data & data, | ||
| 72 | const JointIndex joint_id, | ||
| 73 | const context::SE3 & placement, | ||
| 74 | ReferenceFrame rf) | ||
| 75 | { | ||
| 76 | typedef context::Data::Matrix3x Matrix3x; | ||
| 77 | |||
| 78 | ✗ | Matrix3x v_partial_dq(Matrix3x::Zero(3, model.nv)); | |
| 79 | ✗ | Matrix3x a_partial_dq(Matrix3x::Zero(3, model.nv)); | |
| 80 | ✗ | Matrix3x a_partial_dv(Matrix3x::Zero(3, model.nv)); | |
| 81 | ✗ | Matrix3x a_partial_da(Matrix3x::Zero(3, model.nv)); | |
| 82 | |||
| 83 | ✗ | getPointClassicAccelerationDerivatives( | |
| 84 | model, data, joint_id, placement, rf, v_partial_dq, a_partial_dq, a_partial_dv, | ||
| 85 | a_partial_da); | ||
| 86 | |||
| 87 | ✗ | return bp::make_tuple(v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da); | |
| 88 | } | ||
| 89 | |||
| 90 | context::Data::Matrix3x | ||
| 91 | 1 | getCoMVelocityDerivatives_proxy(const context::Model & model, context::Data & data) | |
| 92 | { | ||
| 93 | typedef context::Data::Matrix3x Matrix3x; | ||
| 94 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | Matrix3x partial_dq(Matrix3x::Zero(3, model.nv)); |
| 95 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | getCenterOfMassVelocityDerivatives(model, data, partial_dq); |
| 96 | 1 | return partial_dq; | |
| 97 | } | ||
| 98 | |||
| 99 | 69 | void exposeKinematicsDerivatives() | |
| 100 | { | ||
| 101 | typedef context::Scalar Scalar; | ||
| 102 | typedef context::VectorXs VectorXs; | ||
| 103 | enum | ||
| 104 | { | ||
| 105 | Options = context::Options | ||
| 106 | }; | ||
| 107 | |||
| 108 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::def( |
| 109 | "computeForwardKinematicsDerivatives", | ||
| 110 | &computeForwardKinematicsDerivatives< | ||
| 111 | Scalar, Options, JointCollectionDefaultTpl, VectorXs, VectorXs, VectorXs>, | ||
| 112 | 138 | bp::args("model", "data", "q", "v", "a"), | |
| 113 | "Computes all the terms required to compute the derivatives of the placement, " | ||
| 114 | "spatial velocity and acceleration\n" | ||
| 115 | "for any joint of the model.\n" | ||
| 116 | "The results are stored in data.\n\n" | ||
| 117 | "Parameters:\n" | ||
| 118 | "\tmodel: model of the kinematic tree\n" | ||
| 119 | "\tdata: data related to the model\n" | ||
| 120 | "\tq: the joint configuration vector (size model.nq)\n" | ||
| 121 | "\tv: the joint velocity vector (size model.nv)\n" | ||
| 122 | "\ta: the joint acceleration vector (size model.nv)\n"); | ||
| 123 | |||
| 124 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::def( |
| 125 | "getJointVelocityDerivatives", getJointVelocityDerivatives_proxy, | ||
| 126 | 138 | bp::args("model", "data", "joint_id", "reference_frame"), | |
| 127 | "Computes the partial derivatives of the spatial velocity of a given joint with respect " | ||
| 128 | "to\n" | ||
| 129 | "the joint configuration and velocity and returns them as a tuple.\n" | ||
| 130 | "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the " | ||
| 131 | "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of " | ||
| 132 | "reference_frame.\n" | ||
| 133 | "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n" | ||
| 134 | "Parameters:\n" | ||
| 135 | "\tmodel: model of the kinematic tree\n" | ||
| 136 | "\tdata: data related to the model\n" | ||
| 137 | "\tjoint_id: index of the joint\n" | ||
| 138 | "\treference_frame: reference frame in which the resulting derivatives are expressed\n"); | ||
| 139 | |||
| 140 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::def( |
| 141 | "getPointVelocityDerivatives", getPointVelocityDerivatives_proxy, | ||
| 142 | 138 | bp::args("model", "data", "joint_id", "placement", "reference_frame"), | |
| 143 | "Computes the partial derivatives of the velocity of a point given by its placement " | ||
| 144 | "information w.r.t. the joint frame and returns them as a tuple.\n" | ||
| 145 | "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the " | ||
| 146 | "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of " | ||
| 147 | "reference_frame.\n" | ||
| 148 | "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n" | ||
| 149 | "Parameters:\n" | ||
| 150 | "\tmodel: model of the kinematic tree\n" | ||
| 151 | "\tdata: data related to the model\n" | ||
| 152 | "\tjoint_id: index of the joint\n" | ||
| 153 | "\tplacement: relative placement of the point w.r.t. the joint frame\n" | ||
| 154 | "\treference_frame: reference frame in which the resulting derivatives are expressed\n"); | ||
| 155 | |||
| 156 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::def( |
| 157 | "getPointClassicAccelerationDerivatives", getPointClassicAccelerationDerivatives_proxy, | ||
| 158 | 138 | bp::args("model", "data", "joint_id", "placement", "reference_frame"), | |
| 159 | "Computes the partial derivatives of the classic acceleration of a point given by its " | ||
| 160 | "placement information w.r.t. the joint frame and returns them as a tuple.\n" | ||
| 161 | "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the " | ||
| 162 | "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of " | ||
| 163 | "reference_frame.\n" | ||
| 164 | "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n" | ||
| 165 | "Parameters:\n" | ||
| 166 | "\tmodel: model of the kinematic tree\n" | ||
| 167 | "\tdata: data related to the model\n" | ||
| 168 | "\tjoint_id: index of the joint\n" | ||
| 169 | "\tplacement: relative placement of the point w.r.t. the joint frame\n" | ||
| 170 | "\treference_frame: reference frame in which the resulting derivatives are expressed\n"); | ||
| 171 | |||
| 172 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::def( |
| 173 | "getJointAccelerationDerivatives", getJointAccelerationDerivatives_proxy, | ||
| 174 | 138 | bp::args("model", "data", "joint_id", "reference_frame"), | |
| 175 | "Computes the partial derivatives of the spatial acceleration of a given joint with " | ||
| 176 | "respect to\n" | ||
| 177 | "the joint configuration, velocity and acceleration and returns them as a tuple.\n" | ||
| 178 | "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the " | ||
| 179 | "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of " | ||
| 180 | "reference_frame.\n" | ||
| 181 | "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n" | ||
| 182 | "Parameters:\n" | ||
| 183 | "\tmodel: model of the kinematic tree\n" | ||
| 184 | "\tdata: data related to the model\n" | ||
| 185 | "\tjoint_id: index of the joint\n" | ||
| 186 | "\treference_frame: reference frame in which the resulting derivatives are expressed\n"); | ||
| 187 | |||
| 188 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::def( |
| 189 | "getCenterOfMassVelocityDerivatives", getCoMVelocityDerivatives_proxy, | ||
| 190 | 138 | bp::args("model", "data"), | |
| 191 | "Computes the partial derivaties of the center of mass velocity with respect to\n" | ||
| 192 | "the joint configuration.\n" | ||
| 193 | "You must first call computeAllTerms(model,data,q,v) or centerOfMass(model,data,q,v) " | ||
| 194 | "before calling this function.\n\n" | ||
| 195 | "Parameters:\n" | ||
| 196 | "\tmodel: model of the kinematic tree\n" | ||
| 197 | "\tdata: data related to the model\n"); | ||
| 198 | 69 | } | |
| 199 | |||
| 200 | } // namespace python | ||
| 201 | } // namespace pinocchio | ||
| 202 |