Robotics StackExchange | Archived questions

How to calculate Jacobian

Hello,

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: http://wiki.ros.org/pr2_mechanism/Tutorials/Coding%20a%20realtime%20Cartesian%20controller%20with%20KDL

And I'm having trouble getting the "chain" since because for some reason, I am not able to import the pr2mechanism_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

Asked by adussa3 on 2019-06-06 14:51:13 UTC

Comments

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

Asked by Geoff on 2019-06-06 19:03:55 UTC

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

Asked by jarvisschultz on 2019-06-07 08:04:19 UTC

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_model packages http://wiki.ros.org/kdl_parser/Tutorials/Start%20using%20the%20KDL%20parser

Asked by jarvisschultz on 2019-06-07 08:06:54 UTC

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

Asked by adussa3 on 2019-06-09 09:59:50 UTC

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.

Asked by jarvisschultz on 2019-06-10 09:12:52 UTC

Answers

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 xacro.py `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)){
    ROS_ERROR("Failed");
  }
  std::cout << "Worked!" << std::endl;

}

Asked by Magnus Caligo on 2023-04-14 22:21:26 UTC

Comments