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

Parsing a urdf model in Rosjava

asked 2013-01-16 19:07:24 -0500

updated 2014-01-28 17:14:52 -0500

ngrennan gravatar image

Hi All,

is is possible to parse a urdf file in rosjava, to generate kinematic frames and transformation matricies? I've developed my own transformation matricies prior to working with ROS and I like the clear nature of urdf (and sdf) formats.

It would be really good to be able to generate a model in code so that android or java controllers could be developed. Has this already been done?



edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-03-01 14:54:42 -0500

updated 2013-03-01 17:22:43 -0500

As per above, I was able to parse urdf files into the java environment. I created a urdf class that contains the same methods and structures as the Cpp urdf class.

import java.util.ArrayList;
import java.util.List;
import org.xml.sax.*;

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import org.w3c.dom.*;

import android.util.Log;

import javax.xml.parsers.*;
public class ModelInterface 

    private List<Joint> Joints_;
    private List<Link> Links_;

    public List<Joint> getJoints()
        return Joints_;

    public List<Link> getLinks()
        return Links_;

    public void initXml(String filename) throws SAXException, IOException, ParserConfigurationException
        //This is the constructor of the object. Search for and load YAML file for robot parameters. This method uses the YAML beans to do so.
                Joints_= new ArrayList<Joint>();
                Links_= new ArrayList<Link>();

                boolean validating=true;

                DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();


                DocumentBuilder builder = factory.newDocumentBuilder();
                File tempfile = new File(filename);

                Document document = builder.parse(tempfile);

                NodeList jointTags = document.getElementsByTagName("joint");
                NodeList linkTags = document.getElementsByTagName("link");

                for(int i =0; i<jointTags.getLength();i++)
                    Joint tempjoint=new Joint();



                for(int i =0; i<linkTags.getLength();i++)
                    Link templink=new Link();



In the initXML (filename) the urdf file is parsed using a DOM reader. It required a little debugging to ensure that the correct elements were read into the correct spots. It also doesn't check the formatting of the urdf file (ie if you change the order of how a link's elements are written) but works off the order I had used. It only gets the link name, and the joint name, types and limits. Conceivably you could parse the entire file if you liked. For reference an example of my urdf order for a link is here:

   <link name = "Tool" >
        <cylinder length="0.15" radius="0.1"/>
        <origin rpy= "1.57 0 0" xyz="0 0 0"/>
        <material name="LightGreen">
            <cylinder length="0.15" radius="0.1"/>
            <origin rpy= "1.57 0 0" xyz="0 0.10 0"/>
            <mass value="13.414"/>
            <inertia ixx="0.34" ixy="0.000039" iyy="0.0649" ixz="-0.001386" iyz="-0.000114" izz="0.296312"/>
            <origin rpy="0 0 0" xyz="0.000 0.075 0.0" />

and joints:

<joint name="joint7" type="revolute">
   <parent link="Wrist_X"/>
   <child link="Tool"/>
   <origin xyz = "0 0.38575 0" rpy = "0 0 0"/>
   <axis xyz="0 1 0" />
   <limit effort="1000" lower="-2.36" upper="2.36" velocity="1.571"/>
edit flag offensive delete link more

answered 2013-02-19 10:53:28 -0500

damonkohler gravatar image

To my knowledge, there is no URDF support in Java.

edit flag offensive delete link more


I found a parsing mechanism in an Rviz for android here: As i really couldn't follow it, I wrote one using the android XML DOM readers and was able to extract the info from the urdf file. The urdf file had to be saved on the android device.

PeterMilani gravatar image PeterMilani  ( 2013-02-20 14:45:46 -0500 )edit

Question Tools


Asked: 2013-01-16 19:07:24 -0500

Seen: 585 times

Last updated: Mar 01 '13