1
$\begingroup$

I have a chassis link that has casters. I would like the casters to be grey and the box to be blue. The ROS link doc mentions <material> and <color> tags as being needed for color.

  <link name='chassis'>
    <pose>0 0 0.1 0 0 0</pose>

    <inertial>
      <mass value="15.0"/>
      <origin xyz="0.0 0 0" rpy=" 0 0 0"/>
      <inertia
          ixx="0.1" ixy="0" ixz="0"
          iyy="0.1" iyz="0"
          izz="0.1"
      />
    </inertial>

    <collision name='chassis_collision'>
      <origin xyz="0 0 0" rpy=" 0 0 0"/>
      <geometry>
        <box size=".4 .2 .1"/>
      </geometry>
    </collision>

    <visual name='chassis_visual'>
      <origin xyz="0 0 0" rpy=" 0 0 0"/>
      <geometry>
        <box size=".4 .2 .1"/>
      </geometry>
      <material name="blue">
        <color rgba= "0 0 1 1"/>
      </material>
    </visual>


    <collision name='back_caster_collision'>
      <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.0499"/>
      </geometry>
    </collision>

    <visual name='back_caster_visual'>
      <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.05"/>
      </geometry>
      <material name="grey">
        <color rgba="0.75 0.75 0.75 1"/>
      </material>
    </visual>

    <collision name='front_caster_collision'>
      <origin xyz="0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.0499"/>
      </geometry>
    </collision>

    <visual name='front_caster_visual'>
      <origin xyz="0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.05"/>
      </geometry>
      <material name="grey">
        <color rgba="0.75 0.75 0.75 1"/>
      </material>
    </visual>

  </link>

However, when I roslaunch my_robot world.launch the bot is the same color, gray. It is only when I add the following that the color changes to blue. What is the purpose of the <color> tag then?

  <gazebo reference="chassis">
    <material>Gazebo/Blue</material>
  </gazebo>
$\endgroup$
3
$\begingroup$

It's a limitation in Gazebo's ability to convert URDF to SDF, Gazebo's native object description format. Frustratingly, RViz works the other way around: it correctly parses URDF colors, but not the SDF fragments inserted by the gazebo tag.

One tip though, instead of inlining your material definitions inside links, it's better to define them once at the beginning and just refer to them throughout the rest of the file. It's more concise and if you ever want to change a material's definition, you have just one place to change. For example:

<robot name="robot" xmlns:xacro="http://ros.org/wiki/xacro">
  <material name="blue">
    <color rgba= "0 0 1 1"/>
  </material>
  <material name="grey">
    <color rgba="0.75 0.75 0.75 1"/>
  </material>

  <!-- ... -->

  <link name='chassis'>
    <pose>0 0 0.1 0 0 0</pose>

    <inertial>
      <mass value="15.0"/>
      <origin xyz="0.0 0 0" rpy=" 0 0 0"/>
      <inertia
          ixx="0.1" ixy="0" ixz="0"
          iyy="0.1" iyz="0"
          izz="0.1"
      />
    </inertial>

    <collision name='chassis_collision'>
      <origin xyz="0 0 0" rpy=" 0 0 0"/>
      <geometry>
        <box size=".4 .2 .1"/>
      </geometry>
    </collision>

    <visual name='chassis_visual'>
      <origin xyz="0 0 0" rpy=" 0 0 0"/>
      <geometry>
        <box size=".4 .2 .1"/>
      </geometry>
      <material name="blue"/>
    </visual>


    <collision name='back_caster_collision'>
      <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.0499"/>
      </geometry>
    </collision>

    <visual name='back_caster_visual'>
      <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.05"/>
      </geometry>
      <material name="grey"/>
    </visual>

    <collision name='front_caster_collision'>
      <origin xyz="0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.0499"/>
      </geometry>
    </collision>

    <visual name='front_caster_visual'>
      <origin xyz="0.15 0 -0.05" rpy=" 0 0 0"/>
      <geometry>
        <sphere radius="0.05"/>
      </geometry>
      <material name="grey"/>
    </visual>
  </link>

  <!-- ... -->

</robot>
| improve this answer | |
$\endgroup$
  • $\begingroup$ Chuck's suggestion was that I was defining the different visual components in one link and should have separated them. Although his suggested changes to visualization in debugging showed that his hunch wasn't working for colors, though it made a lot of sense, I was wondering about the collision portion of the link. Is only the last collision child, included in calculations (overwriting the others) given that I have more than one in the link? $\endgroup$ – heretoinfinity Apr 17 at 13:54
  • 2
    $\begingroup$ According to the URDF reference on link that you shared, "multiple instances of <collision> tags can exist for the same link. The union of the geometry they define forms the collision representation of the link." So all collision tags are going to be included. $\endgroup$ – xperroni Apr 17 at 14:13
1
$\begingroup$

I've never used ROS or Gazebo before, but it looks like all of your components are defined as being part of the same link, so Gazebo may be applying the last-specified color to all components because, as the documentation is written,

The link element describes a rigid body with an inertia, visual features, and collision properties.

Describes A rigid body. If you wanted to troubleshoot this, I would try changing the last color from grey to something completely different, like magenta, and see if that causes everything in the link to change to that color.

I would also try splitting the individual components out into their own links; if it's only using the last-specified color then it may also only be using the last-specified collider.

| improve this answer | |
$\endgroup$
  • $\begingroup$ This was a very good suggestion but it didn't work unfortunately. I learned something new in debugging hence the +1. I didn't separate the links but I changed all color tags to <color rgba="0 0 0.75 1"/> and commented out the <gazebo> ones. It didn't work unfortunately as everything was grey, which I think is the default color if none is specified. $\endgroup$ – heretoinfinity Apr 17 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.