0
$\begingroup$

Rosanswers logo

Here is my xacro file:

<?xml version="1.0" ?>

<robot name="$(arg roboname)" xmlns:xacro="http://www.ros.org/wiki/xacro">

  <xacro:property name="PI" value="3.1415926835897931"/> 

<link name="base_link">
     <collision>
         <origin xyz="0 0 1" rpy="0 0 ${-PI/2}"/>
           <geometry>
            <box size="2.62 1.3 1.4478"/>
        </geometry>
      </collision>
    <gravity>0</gravity>
     <visual>
        <origin xyz="0 0 1" rpy="0 0 ${-PI/2}"/>
        <geometry>
            <box size="2.62 1.3 1.4478"/>
        </geometry>
         <material name="Yellow"/>
     </visual>

</link>

<joint name="inertial_joint" type="fixed">
      <parent link="base_link"/>
      <child link="main_mass"/>
      <origin xyz="0 0 0" rpy="0 0 0"/>
</joint>

<link name="main_mass" type="fixed">
    <!-- <parent link="inertial_joint"/> -->
     <gravity>0</gravity>
     <inertial>
        <origin xyz="0 0 1.0639" rpy="0 0 0"/>
        <mass value="1"/>
        <inertia
          ixx="1"  ixy="0.000000" ixz="0"
          iyy="0" iyz="0.000000"
          izz="0"/>
      </inertial>
</link>

</robot>

I want box to be of yellow color but I can't see in Yellow color in gazebo. How should I fix it?


Originally posted by cybodroid on ROS Answers with karma: 234 on 2016-06-24

Post score: 2

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Assuming you are at least on ROS Indigo with Gazebo 2.x.

The colors in ROS URDF and Gazebo SDF are not of the same flavour. Citing from URDF in Gazebo tutorial:

A standard URDF can specify colors using a tag such as in the RRBot:

<material name="orange"/>

With the color orange defined separately such as in the file materials.xacro:

<material name="orange">
  <color rgba="${255/255} ${108/255} ${10/255} 1.0"/>
</material>

Unfortunately, this method of specifying link colors does not work in Gazebo as it adopts OGRE's material scripts for coloring and texturing links. Instead, a Gazebo material tag must be specified for each link, such as:

<gazebo reference="link1">
  <material>Gazebo/Orange</material>
</gazebo>

These <gazebo reference=...> tags allow to embed native SDF commands for model links into URDF.

So, you should include in your URDF something like:

<gazebo reference="base_link">
  <material>Gazebo/Yellow</material>
</gazebo>

It is a good idea to keep color statements both for URDF and SDF if you are going to visualize the model both in RViz and Gazebo.

If you are only interested in Gazebo without ROS integration, then you may prefer to use SDF to describe your robot.

Please refer to the tutorial.


Originally posted by Boris with karma: 3060 on 2016-06-24

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by cybodroid on 2016-06-27:
Thanks for your explanation. It worked.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.