Robotics StackExchange | Archived questions

How to use custom OGRE materials in URDF in ROS Indigo that displays in Gazebo?

Hi everyone

I want to create a custom OGRE material file, store it in my ROS Indigo package, and have my robot's visual in Gazebo use these materials.

I don't want to use SDF (I know how to; in fact, I learned SDF before URDF).

Here's what I tried and the results I got:

  1. Using Gazebo's built in materials work.

    <gazebo reference="…">
        <material>Gazebo/Yellow</material>
    </gazebo>
    
  2. Adding materials to Gazebo's built in materials file at /usr/share/gazebo-2.2/media/materials/scripts/gazebo.material also works.

  3. This didn't work. It's for ROS Fuerte and Gazebo 1, so I had to make some changes:

    1. roscreate-pkg gazebo_tutorials std_msgs rospy roscpp gazebo failed because ERROR: dependency [gazebo] cannot be found. I installed through apt-get every package that had gazebo in the name, but that didn't fix it. So, instead, I replaced gazebo by all packages returned by rospack list that started with gazebo. Only after the package was created that I realized it was the command to generate the old package format. This and this pages confirm that rospack find gazebo used to work in the past and doesn't anymore. So I created a new package and replaced the <depend> tags by <build_depend>, <buildtool_depend> and <run_depend>.
    2. I tried with <gazebo gazebo_media_path="${prefix}" /> but, when launching the package, Warning [Visual.cc:819] Unable to get Material[…] for Geometry[…. Object will appear white. Then I replaced ${prefix} by the full path to where my ….material file was located; same result.
  4. The first snippet from the answer to this question results in Warning [Visual.cc:819] Unable to get Material[script] for Geometry[…. Object will appear white. Note it says script instead of the material name. I tried several variations for <uri>'s argument.

  5. This confirmed a suspicion that the ….material file must be inside a Media folder, so I'm testing with and without it.

  6. This led me

    1. here, but adding the <env> tag to the launch file also didn't work. Because find gazebo doesn't work anymore, I'm using "$GAZEBO_RESOURCE_PATH:$(find …)". I'm not certain if it makes sense.
    2. and here. There's two ….material files and one ….urdf file that uses one of those materials, but this file isn't used anywhere. Also, the syntax is strange. It says <material>b21.material</material>, which is the name of the file, but the materials defined there are named b21_base_dark and b21_base_blue. These names aren't used anywhere. I also tried to place my ….material file in the full Media/materials/scripts path as is used by this package. manifest.xml only confirms to me that "${prefix}" is correct, but I don't know what's the impact of not having the gazebo package anymore.
  7. I don't mind using a colored Collada file if it worked. I applied random face colors with MeshLab. Mesh is still white. In RViz, it's a darker gray. Adding an <ambient> tag as per here makes no difference.

  8. I tried ryan.delgizzi's answer below. The link appears as Orange instead of the expected olive green.

Please walk me through the steps necessary to make this work.

I've created a test package that incorporates all of these attempts.

Thanks in advance.

Update: I found out it works on Lunar while preparing the package above.

I still want to make it work in Indigo.

  1. Does not require <export> or other tags on package.xml.
  2. Requires the following on the ….launch file, if the ….material file is in the package root folder. Otherwise, complete the path to the ….material file.

    <env
        name="GAZEBO_RESOURCE_PATH"
        value="$GAZEBO_RESOURCE_PATH:$(find …)"
    />
    
  3. Requires the following on the ….urdf files:

    <gazebo reference="…">
        <material>…/…</material>
    </gazebo>
    

Update: I added the tests that I made before preparing this package. I also fixed package.xml because I created the package in Lunar while it was meant to be for Indigo. And I also took a screenshot of what shows up in Gazebo in this most recent version. Yellow is a built in Gazebo color. Orange is the color I added to Gazebo's built in colors. Azure is the color I'm trying to apply to links. The last link (from item #8 of the first post) was added later and is not present in the image.

Gazebo interface with test result

Asked by GuiRitter on 2017-11-10 05:55:43 UTC

Comments

It works on Lunar. I've updated the first post. I still want to make it work in Indigo.

Asked by GuiRitter on 2017-11-11 14:26:02 UTC

I've created a test package and updated the first post.

Asked by GuiRitter on 2017-11-11 15:08:33 UTC

I've added tests, a fix and an image of what I'm getting now, and updated the first post.

Asked by GuiRitter on 2017-11-17 08:38:18 UTC

Answers

Thanks for a well documented question. I was trying to accomplish the same thing. After seeing your post, I decided to try a different approach. I came up with something that was good enough for me. Instead of going through and generating a material through OGRE and Gazebo, I built the colors in sdf using xacro. Based on your example repository and because you are posting in the ROS forums, I presume you are trying to apply these colors to a urdf file which gets loaded into gazebo.

My solution is to use an xacro marco to define a color using sdf xml.

<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">
  <xacro:macro name="material_olive_green">
  <visual>
    <material>
      <ambient>0.3137254 0.3254902 0.2352941 1</ambient>
      <diffuse>0.3137254 0.3254902 0.2352941 1</diffuse>
      <specular>0.1 0.1 0.1 1</specular>
      <emissive>0 0 0 0</emissive>
    </material>
  </visual>
</xacro:macro>
</robot>

Then I call the macro as part of my gazebo element in my robot file.

<gazebo reference="${prefix}base_link">
  <xacro:material_olive_green />
  <turnGravityOff>true</turnGravityOff>
</gazebo>

Hopefully this is useful to somebody.

Asked by ryan.delgizzi on 2018-12-14 11:20:42 UTC

Comments

Thanks for the answer! However, your solution didn't work for me. The link is colored Orange like others. Please check the test package where I applied your solution on link #21.

Asked by GuiRitter on 2019-08-29 21:26:10 UTC