| Directory: | ./ |
|---|---|
| File: | examples/overview-urdf.cpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 14 | 14 | 100.0% |
| Branches: | 30 | 66 | 45.5% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "pinocchio/parsers/urdf.hpp" | ||
| 2 | |||
| 3 | #include "pinocchio/algorithm/joint-configuration.hpp" | ||
| 4 | #include "pinocchio/algorithm/kinematics.hpp" | ||
| 5 | |||
| 6 | #include <iostream> | ||
| 7 | |||
| 8 | // PINOCCHIO_MODEL_DIR is defined by the CMake but you can define your own directory here. | ||
| 9 | #ifndef PINOCCHIO_MODEL_DIR | ||
| 10 | #define PINOCCHIO_MODEL_DIR "path_to_the_model_dir" | ||
| 11 | #endif | ||
| 12 | |||
| 13 | 1 | int main(int argc, char ** argv) | |
| 14 | { | ||
| 15 | using namespace pinocchio; | ||
| 16 | |||
| 17 | // You should change here to set up your own URDF file or just pass it as an argument of this | ||
| 18 | // example. | ||
| 19 | const std::string urdf_filename = | ||
| 20 | (argc <= 1) ? PINOCCHIO_MODEL_DIR | ||
| 21 |
2/8✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
2 | + std::string("/example-robot-data/robots/ur_description/urdf/ur5_robot.urdf") |
| 22 |
4/12✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
2 | : argv[1]; |
| 23 | |||
| 24 | // Load the urdf model | ||
| 25 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Model model; |
| 26 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pinocchio::urdf::buildModel(urdf_filename, model); |
| 27 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | std::cout << "model name: " << model.name << std::endl; |
| 28 | |||
| 29 | // Create data required by the algorithms | ||
| 30 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Data data(model); |
| 31 | |||
| 32 | // Sample a random configuration | ||
| 33 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Eigen::VectorXd q = randomConfiguration(model); |
| 34 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
1 | std::cout << "q: " << q.transpose() << std::endl; |
| 35 | |||
| 36 | // Perform the forward kinematics over the kinematic tree | ||
| 37 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | forwardKinematics(model, data, q); |
| 38 | |||
| 39 | // Print out the placement of each joint of the kinematic tree | ||
| 40 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (JointIndex joint_id = 0; joint_id < (JointIndex)model.njoints; ++joint_id) |
| 41 |
5/10✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 7 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 7 times.
✗ Branch 16 not taken.
|
7 | std::cout << std::setw(24) << std::left << model.names[joint_id] << ": " << std::fixed |
| 42 |
5/10✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 7 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 7 times.
✗ Branch 16 not taken.
|
7 | << std::setprecision(2) << data.oMi[joint_id].translation().transpose() << std::endl; |
| 43 | 1 | } | |
| 44 |