-
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
4512214
commit b9f9879
Showing
1 changed file
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <iostream> | ||
|
||
#include "pinocchio/algorithm/joint-configuration.hpp" | ||
#include "pinocchio/algorithm/rnea.hpp" | ||
#include "pinocchio/parsers/urdf.hpp" | ||
|
||
// PINOCCHIO_MODEL_DIR is defined by the CMake but you can define your own | ||
// directory here. | ||
#ifndef PINOCCHIO_MODEL_DIR | ||
#define PINOCCHIO_MODEL_DIR "path_to_the_model_dir" | ||
#endif | ||
|
||
int main(int argc, char** argv) { | ||
using namespace pinocchio; | ||
|
||
// Change to your own URDF file here, or pass it as a command-line argument | ||
const std::string urdf_filename = | ||
(argc <= 1) | ||
? PINOCCHIO_MODEL_DIR + std::string( | ||
"/example-robot-data/robots/" | ||
"ur_description/urdf/ur5_robot.urdf") | ||
: argv[1]; | ||
|
||
// Load the URDF model | ||
Model model; | ||
pinocchio::urdf::buildModel(urdf_filename, model); | ||
|
||
// Build a data frame associated with the model | ||
Data data(model); | ||
|
||
// Sample a random joint configuration, joint velocities and accelerations | ||
Eigen::VectorXd q = randomConfiguration(model); // in rad for the UR5 | ||
Eigen::VectorXd v = Eigen::VectorXd::Zero(model.nv); // in rad/s for the UR5 | ||
Eigen::VectorXd a = Eigen::VectorXd::Zero(model.nv); // in rad/s² for the UR5 | ||
|
||
// Computes the inverse dynamics (RNEA) for all the joints of the robot | ||
Eigen::VectorXd tau = pinocchio::rnea(model, data, q, v, a); | ||
|
||
// Print out to the vector of joint torques (in Nm) | ||
std::cout << "Joint torques: " << data.tau.transpose() << std::endl; | ||
return 0; | ||
} |