ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to calculate Jacobian

asked 2019-06-06 14:51:50 -0500

adussa3 gravatar image


I am a working with a UR5 arm and I am trying to calculate the Jacobian from the joints of the arm.

I understand that the MoveIt framework provides a function to get the Jacobian; however, I need to figure out how to code it in C++ for the project.

I am following this tutorial:

And I'm having trouble getting the "chain_" since because for some reason, I am not able to import the pr2_mechanism_model packages.

I was wondering if someone could tell me how to define "chain_" and (if possible) tell me the steps to calculate the Jacobian.

Thank you in advance

edit retag flag offensive close merge delete


Post the errors you are having when you try to import the pr2_mechanism_model packages.

Geoff gravatar image Geoff  ( 2019-06-06 19:03:55 -0500 )edit

I'm guessing this tutorial is a much-more recent tutorial that includes a section on how to compute the Jacobian

jarvisschultz gravatar image jarvisschultz  ( 2019-06-07 08:04:19 -0500 )edit

So if you use the MoveIt! libraries, you could compute the Jacobian that way. If you want to avoid MoveIt! entirely, you could use something like kdl_parser to convert the URDF to a KDL "chain", and then use KDL to compute Jacobian. You certainly shouldn't need the pr2_mechanism_modelpackages

jarvisschultz gravatar image jarvisschultz  ( 2019-06-07 08:06:54 -0500 )edit

Hi everyone, thank you for your responses! I was able to figure it out!

adussa3 gravatar image adussa3  ( 2019-06-09 09:59:50 -0500 )edit

It would be great if you could write an answer describing how you solved your problem so that future readers can benefit from your experiences. Plus, this question could then be marked as answered.

jarvisschultz gravatar image jarvisschultz  ( 2019-06-10 09:12:52 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-04-14 22:22:32 -0500

Magnus Caligo gravatar image

I came about this question and found it useful, but no answers, so after figuring it out myself I decided I should help the next poor sucker to find themselves in this position too.

I followed the comments and installed kdl_parser. I followed the instructions to convert my .xacro into an _actual_ urdf file:

rosrun xacro `rospack find pr2_description`/robots/pr2.urdf.xacro > pr2.urdf

From there I installed orocos_kdl by following these instructions. I will admit that i'm fairly new to ROS/Catkin, so to figure out how to actually add these packages to my own wasn't very obvious. I modified the CMakeLists.txt and added the packages to the find_package portion of the CMake, as well as adding to the package.xml as the documentation instructs.

I was able to confirm I got everything working by building a simple executable to test to make sure that I was able to make a tree from my urdf file:

#include <kdl_parser/kdl_parser.hpp>
#include <kdl/tree.hpp>
#include <ros/console.h>
#include <iostream>

int main(){

  KDL::Tree my_tree;
  if(!kdl_parser::treeFromFile("src/robot_arm/src/urdf/robot_arm.urdf", my_tree)){
  std::cout << "Worked!" << std::endl;

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-06-06 14:51:13 -0500

Seen: 2,335 times

Last updated: Apr 14