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.
10 from pathlib
import Path
13 import pinocchio
as pin
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)
25 data = model.createData()
28 q = pin.randomConfiguration(model)
29 v = np.random.rand(model.nv, 1)
30 a = np.random.rand(model.nv, 1)
33 tau = pin.rnea(model, data, q, v, a)
36 print(
"Joint torques: " + str(tau))