# KDL parser: URDF parsing issue

Hey,

This question seems a bit obvious/easy but I am not able to get the KDL parser working with URDF file for making a KDL tree. I am following this tutorial, section 2.1 - KDL parser: From a file. I am not able to pass the correct filename in the function kdl_parser::treeFromFile("filename", tree). I tried with the model urdf name, the relative path to that file, the absolute path; all of them gives the same error while running - Error document empty. Can anyone specify how to pass the URDF file to the function?

ROS: Melodic

Edit:
As mentioned by @pmuthu2s in the comment, I added below line in the launch file.

<param name="robot_description" textfile="$(find exercise2)/model/robots/sim.urdf"/>  Also the code for parsing looks like this: KDL::Tree lumi_tree; std::string lumi_robot; node.param("robot_description", lumi_robot, std::string()); if (!kdl_parser::treeFromFile(lumi_robot, lumi_tree)){ ROS_ERROR("Failed to construct kdl tree"); return false; }  Still getting the same error. Probably I am doing something wrong here. Anyone know how to fix this? Regards, Anand edit retag close merge delete ## Comments Hey, Maybe check this out Error document empty ( 2020-01-31 02:37:01 -0600 )edit Added some more details in the question. Still the same error. ( 2020-01-31 04:04:42 -0600 )edit Have you checked whether lumi_robot actually contains anything? And does cat$(rospack find exercise2)/model/robots/sim.urdf show the expected content?

( 2020-01-31 04:30:50 -0600 )edit

@gvdhoorn - I can see the urdf with that cat command. But the problem here is lumi_robot does not have any value. Thanks for pointing out that. The launch file just launches the robot and starts rviz. I run the executable separately. Is that the reason why it cannot get the URDF from rosparams? I am able to see the URDF with rosparam get /robot_description. I am getting the URDF as std::string lumi_robot; node.param("robot_description", lumi_robot, std::string());

( 2020-01-31 05:14:58 -0600 )edit

I changed the it to /robot_description as node.param("/robot_description", lumi_robot, std::string());. Now lumi_robot as the content of sim.urdf. Still I am geting Error document empty.

( 2020-01-31 05:39:21 -0600 )edit

Sort by » oldest newest most voted

As mentioned in the question, I was trying to get the KDL tree of the robot by loading the URDF using treeFromFile() function with taking the URDF from the params server. I changed it to treeFromString() as the URDF is stored as a string after getting it from the params server. Below is the modified code.

KDL::Tree lumi_tree;
std::string lumi_robot;
node.param("/robot_description", lumi_robot, std::string());
if (!kdl_parser::treeFromString(lumi_robot, lumi_tree)){
ROS_ERROR("Failed to construct kdl tree");
return false;
}


Now the KDL tree is formed and is used for further calculations.

Thanks @pmuthu2s and @gvdhoorn for their inputs.

more

No problem

( 2020-02-03 10:45:38 -0600 )edit