inverse-dynamics.py
Go to the documentation of this file.
1 # Copyright 2023 Inria
2 # SPDX-License-Identifier: BSD-2-Clause
3 
4 
5 """
6 In this short script, we show how to compute inverse dynamics (RNEA), i.e. the
7 vector of joint torques corresponding to a given motion.
8 """
9 
10 from pathlib import Path
11 
12 import numpy as np
13 import pinocchio as pin
14 
15 # Load the model from a URDF file
16 # Change to your own URDF file here, or give a path as command-line argument
17 pinocchio_model_dir = Path(__file__).parent.parent / "models/"
18 model_path = pinocchio_model_dir / "example-robot-data/robots"
19 mesh_dir = pinocchio_model_dir
20 urdf_filename = "ur5_robot.urdf"
21 urdf_model_path = model_path / "ur_description/urdf/" / urdf_filename
22 model, _, _ = pin.buildModelsFromUrdf(urdf_model_path, package_dirs=mesh_dir)
23 
24 # Build a data frame associated with the model
25 data = model.createData()
26 
27 # Sample a random joint configuration, joint velocities and accelerations
28 q = pin.randomConfiguration(model) # in rad for the UR5
29 v = np.random.rand(model.nv, 1) # in rad/s for the UR5
30 a = np.random.rand(model.nv, 1) # in rad/s² for the UR5
31 
32 # Computes the inverse dynamics (RNEA) for all the joints of the robot
33 tau = pin.rnea(model, data, q, v, a)
34 
35 # Print out to the vector of joint torques (in N.m)
36 print("Joint torques: " + str(tau))
pinocchio::randomConfiguration
void randomConfiguration(const LieGroupGenericTpl< LieGroupCollection > &lg, const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const Eigen::MatrixBase< ConfigOut_t > &qout)
pinocchio::rnea
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & rnea(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &a, const container::aligned_vector< ForceDerived > &fext)
The Recursive Newton-Euler algorithm. It computes the inverse dynamics, aka the joint torques accordi...


pinocchio
Author(s):
autogenerated on Wed May 28 2025 02:41:18