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

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?

cheers

Peter

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

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.io.File;
import java.io.IOException;
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>();
                Joints_.clear();
                Links_.clear();


                boolean validating=true;

                DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();

                //factory.setValidating(validating);

                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();


                    tempjoint.setName(jointTags.item(i).getAttributes().getNamedItem("name").getNodeValue());
                    tempjoint.setType(jointTags.item(i).getAttributes().getNamedItem("type").getNodeValue());
                    tempjoint.setLowerLimit(Double.parseDouble(jointTags.item(i).getChildNodes().item(9).getAttributes().getNamedItem("lower").getNodeValue()));
                    tempjoint.setUpperLimit(Double.parseDouble(jointTags.item(i).getChildNodes().item(9).getAttributes().getNamedItem("upper").getNodeValue()));

                    Joints_.add(tempjoint);
                }

                for(int i =0; i<linkTags.getLength();i++)
                {
                    Link templink=new Link();
                    templink.setName(linkTags.item(i).getAttributes().getNamedItem("name").getNodeValue());

                    Links_.add(templink);
                }
    }

 }

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" >
    <visual>
        <geometry>
        <cylinder length="0.15" radius="0.1"/>
            </geometry>
        <origin rpy= "1.57 0 0" xyz="0 0 0"/>
        <material name="LightGreen">
        </material>
       </visual>
    <collision>
        <geometry>
            <cylinder length="0.15" radius="0.1"/>
                </geometry>
            <origin rpy= "1.57 0 0" xyz="0 0.10 0"/>
    </collision>
    <inertial>
            <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" />
    </inertial>
    </link>

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"/>
</joint>
edit flag offensive delete link more
1

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

Comments

I found a parsing mechanism in an Rviz for android here: http://www.willowgarage.com/blog/2012/09/24/rviz-android-0. 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

Stats

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

Seen: 586 times

Last updated: Mar 01 '13