inverse-dynamics.cpp
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.
6  * the vector of joint torques corresponding to a given motion.
7  */
8 
9 #include <iostream>
10 
14 
15 // PINOCCHIO_MODEL_DIR is defined by the CMake but you can define your own
16 // directory here.
17 #ifndef PINOCCHIO_MODEL_DIR
18  #define PINOCCHIO_MODEL_DIR "path_to_the_model_dir"
19 #endif
20 
21 int main(int argc, char ** argv)
22 {
23  using namespace pinocchio;
24 
25  // Change to your own URDF file here, or give a path as command-line argument
26  const std::string urdf_filename = (argc <= 1)
28  + std::string("/example-robot-data/robots/"
29  "ur_description/urdf/ur5_robot.urdf")
30  : argv[1];
31 
32  // Load the URDF model
33  Model model;
35 
36  // Build a data frame associated with the model
37  Data data(model);
38 
39  // Sample a random joint configuration, joint velocities and accelerations
40  Eigen::VectorXd q = randomConfiguration(model); // in rad for the UR5
41  Eigen::VectorXd v = Eigen::VectorXd::Zero(model.nv); // in rad/s for the UR5
42  Eigen::VectorXd a = Eigen::VectorXd::Zero(model.nv); // in rad/s² for the UR5
43 
44  // Computes the inverse dynamics (RNEA) for all the joints of the robot
45  Eigen::VectorXd tau = pinocchio::rnea(model, data, q, v, a);
46 
47  // Print out to the vector of joint torques (in N.m)
48  std::cout << "Joint torques: " << data.tau.transpose() << std::endl;
49  return 0;
50 }
append-urdf-model-with-another-model.urdf_filename
string urdf_filename
Definition: append-urdf-model-with-another-model.py:16
pinocchio::DataTpl
Definition: context/generic.hpp:25
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::randomConfiguration
void randomConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &lowerLimits, const Eigen::MatrixBase< ConfigVectorIn2 > &upperLimits, const Eigen::MatrixBase< ReturnType > &qout)
Generate a configuration vector uniformly sampled among provided limits.
Definition: joint-configuration.hpp:315
rnea.hpp
forward-dynamics-derivatives.tau
tau
Definition: forward-dynamics-derivatives.py:25
joint-configuration.hpp
urdf.hpp
pinocchio::urdf::buildModel
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, const std::string &rootJointName, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a URDF file with a particular joint as root of the model tree inside the model g...
main
int main(int argc, char **argv)
Definition: inverse-dynamics.cpp:21
PINOCCHIO_MODEL_DIR
#define PINOCCHIO_MODEL_DIR
Definition: inverse-dynamics.cpp:18
pinocchio::q
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
Definition: joint-configuration.hpp:1083
a
Vec3f a
pinocchio::v
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
Definition: joint-configuration.hpp:1084
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)
The Recursive Newton-Euler algorithm. It computes the inverse dynamics, aka the joint torques accordi...
pinocchio::ModelTpl
Definition: context/generic.hpp:20
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:29