inverse-dynamics.py
Go to the documentation of this file.
1 # Copyright 2023 Inria
2 # SPDX-License-Identifier: BSD-2-Clause
3 
4 """
5 In this short script, we show how to compute inverse dynamics (RNEA), i.e. the
6 vector of joint torques corresponding to a given motion.
7 """
8 
9 from os.path import abspath, dirname, join
10 
11 import numpy as np
12 import pinocchio as pin
13 
14 # Load the model from a URDF file
15 # Change to your own URDF file here, or give a path as command-line argument
16 pinocchio_model_dir = join(dirname(dirname(str(abspath(__file__)))), "models/")
17 model_path = join(pinocchio_model_dir, "example-robot-data/robots")
18 mesh_dir = pinocchio_model_dir
19 urdf_filename = "ur5_robot.urdf"
20 urdf_model_path = join(join(model_path, "ur_description/urdf/"), urdf_filename)
21 model, _, _ = pin.buildModelsFromUrdf(urdf_model_path, package_dirs=mesh_dir)
22 
23 # Build a data frame associated with the model
24 data = model.createData()
25 
26 # Sample a random joint configuration, joint velocities and accelerations
27 q = pin.randomConfiguration(model) # in rad for the UR5
28 v = np.random.rand(model.nv, 1) # in rad/s for the UR5
29 a = np.random.rand(model.nv, 1) # in rad/s² for the UR5
30 
31 # Computes the inverse dynamics (RNEA) for all the joints of the robot
32 tau = pin.rnea(model, data, q, v, a)
33 
34 # Print out to the vector of joint torques (in N.m)
35 print("Joint torques: " + str(tau))
path


pinocchio
Author(s):
autogenerated on Tue Feb 13 2024 03:43:58