-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9f9879
commit 56f7c85
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2023 Inria | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
|
||
""" | ||
In this short script, we show how to compute inverse dynamics (RNEA), i.e. the | ||
vector of joint torques corresponding to a given motion. | ||
""" | ||
|
||
from os.path import abspath, dirname, join | ||
|
||
import numpy as np | ||
import pinocchio as pin | ||
|
||
# Load the model from a URDF file | ||
# Change to your own URDF file here, or give a path as command-line argument | ||
pinocchio_model_dir = join(dirname(dirname(str(abspath(__file__)))), "models/") | ||
model_path = join(pinocchio_model_dir, "example-robot-data/robots") | ||
mesh_dir = pinocchio_model_dir | ||
urdf_filename = "ur5_robot.urdf" | ||
urdf_model_path = join(join(model_path, "ur_description/urdf/"), urdf_filename) | ||
model, _, _ = pin.buildModelsFromUrdf(urdf_model_path, package_dirs=mesh_dir) | ||
|
||
# Build a data frame associated with the model | ||
data = model.createData() | ||
|
||
# Sample a random joint configuration, joint velocities and accelerations | ||
q = pin.randomConfiguration(model) # in rad for the UR5 | ||
v = np.random.rand(model.nv, 1) # in rad/s for the UR5 | ||
a = np.random.rand(model.nv, 1) # in rad/s² for the UR5 | ||
|
||
# Computes the inverse dynamics (RNEA) for all the joints of the robot | ||
tau = pin.rnea(model, data, q, v, a) | ||
|
||
# Print out to the vector of joint torques (in N.m) | ||
print("Joint torques: " + str(tau)) |