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

How do you use externally defined materials in a URDF.Xacro file?

asked 2015-04-26 17:33:43 -0600

Cerin gravatar image

How do you apply a material definition located in an external udrf.xacro file?

I have a materials.urdf.xacro file like:

<?xml version="1.0"?>
  <material name="black">
    <color rgba="0.0 0.0 0.0 1.0"/>

  <material name="blue">
    <color rgba="0.0 0.0 0.8 1.0"/>

  <material name="green">
    <color rgba="0.0 0.8 0.0 1.0"/>

  <material name="gray">
    <color rgba="0.7 0.7 0.7 1.0"/>

  <material name="darkgray">
    <color rgba="0.3 0.3 0.3 1.0"/>

  <material name="red">
    <color rgba="0.8 0.0 0.0 1.0"/>

  <material name="white">
    <color rgba="1.0 1.0 1.0 1.0"/>

  <material name="yellow">
    <color rgba="0.8 0.8 0.0 1.0"/>

and I'm trying to include and use these materials like:

<?xml version="1.0"?>
<robot name="myrobot"
    <xacro:include filename="$(find myrobot_description)/urdf/materials.urdf.xacro" />
    <link name="torso">
                <box size="1 1 1" />
            <material name="red"/>
        <xacro:default_inertial mass="1"/>

However, when I run:

roslaunch urdf_tutorial xacrodisplay.launch model:='$(find myrobot_description)/urdf/myrobot.urdf.xacro'

Rviz renders the box as white and not red. Why is that?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-04-26 18:30:53 -0600

130s gravatar image

updated 2015-04-26 18:39:26 -0600

From the tutorial you see:

If a TF frame does not exist for a given URDF link, then it will be placed at the origin in white.

In your case, changing link name from "torso" to "base_link" should do the work.

UPDATE: @DLu is right. Although torso might not be available in the fixed frame pulldown menu, you can manually type in torso.

edit flag offensive delete link more


Unfortunately, that tutorial never explains what a "TF frame" is, so that note doesn't help.

Cerin gravatar image Cerin  ( 2015-04-26 21:32:35 -0600 )edit

Although I don't understand why, this fixes it. I wish there was a more intuitive solution though.

Cerin gravatar image Cerin  ( 2015-04-26 21:44:09 -0600 )edit

Might be a good call: URDF tutorial requires you to have finished TF tutorials. I opened a ticket.

130s gravatar image 130s  ( 2015-04-27 02:51:45 -0600 )edit

answered 2015-04-26 18:24:56 -0600

DLu gravatar image

Set the base frame of rviz to be torso

edit flag offensive delete link more


I don't understand. What code would I change to do that? Or are you suggesting I'll have to manually set some GUI widget every time I load a model?

Cerin gravatar image Cerin  ( 2015-04-26 21:33:46 -0600 )edit

Question Tools

1 follower


Asked: 2015-04-26 17:33:43 -0600

Seen: 5,239 times

Last updated: Apr 26 '15