Ask Your Question
0

Colors not working in Rviz and Gazebo

asked 2020-03-25 10:08:52 -0500

olga_pi gravatar image

updated 2020-03-26 05:36:29 -0500

Hi! I'm using melodic and Gazebo-9. Following a Gazebo tutorial I have 3 files: 1. my_robot.xacro (URDF model of my robot) 2. my_robot.gazebo 3. materials.xacro (where the colors are defined)

In my urdf-file I have

<?xml version="1.0"?>
<robot name="weld_robot" xmlns:xacro="https://www.ros.org/wiki/xacro" >

  <xacro:include filename="$(find robot)/urdf/my_robot.gazebo" />

  <xacro:include filename="$(find robot)/urdf/materials.xacro" />
...
  <link name="link_1">
    <visual>
        <geometry>
            <cylinder length="0.1" radius="1"/>
        </geometry>
    </visual>
    <collision>
        <geometry>
            <cylinder length="0.1" radius="1"/>
        </geometry>
    </collision>
    <inertial>
        <mass value="1"/>
        <inertia ixx="0.25" ixy="0.0" ixz="0.0" 
                     iyy="0.25" iyz="0.0" 
                     izz="0.5"/>
    </inertial>
  </link>
...
</robot>

In my my_robot.gazebo I have:

<?xml version="1.0"?>
<robot>
...  
  <!-- Link_1 -->
  <gazebo reference="link_1">
    <visual>
        <material>Gazebo/Orange</material>
       </visual>
...
  </gazebo>

And here is my launch file for rviz, which I took from the tutorial:

<launch>

  <arg name="model" default="$(find robot)/urdf/my_robot.xacro"/>
  <arg name="gui" default="true" />
  <arg name="rvizconfig" default="$(find robot)/rviz/urdf.rviz" />

  <param name="robot_description" command="$(find xacro)/xacro.py $(arg model)"/>
  <param name="use_gui" value="$(arg gui)"/>

  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find robot)/rviz/urdf.rviz" />

</launch>

My problem is that the colors are not displayed neither in rviz nor in Gazebo. I've tried different approaches, suggested in the forum, but the problem still exists. In Gazebo the model is completely white, and the model in rviz has the colors which I defined previously in the my_robot.urdf file (now my_robot.xacro) before I created different files for materials and my_robot.gazebo and when <material> tag was still in my_robot.urdf file.

Any help would be appreciated!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-03-26 05:16:23 -0500

Joe28965 gravatar image

updated 2020-03-26 09:39:12 -0500

In your first file, you do not have any colour added to your link_1 in flexweld.gazebo you have added a gazebo reference. Rviz does not use gazebo references to get the colour, so rviz doesn't know a colour exists. this can be fixed by changing link_1 to this:

  <link name="link_1">
    <visual>
      <geometry>
        <cylinder length="0.1" radius="1"/>
      </geometry>
      <material name="orange"/>
  </visual>

Assuming of course in materials.xacro you have added this:

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

That should resolve your rviz issue. Your gazebo issue seems to be related to the reason that you have not included flexweld.gazebo anywhere in your files, as far as I can see. Have you included it using:

<xacro:include filename="$(find robot)/urdf/flexweld.gazebo" />

as you have done your other files?

EDIT based on comment: Okay, flexweld.gazebo is actually called my_robot.gazebo in that case you have included it. I took a quick look to how exactly I implemented the colour in my URDF file and I noticed I've implemented it like this:

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

without the <visual> tags in the reference. Just out of curiosity, is that the issue? Is it fixed if you remove the tag from just the <gazebo reference> portion, like I've done here?

edit flag offensive delete link more

Comments

Hi! Thank you very much for your help. I added the material tag to my urdf-file and the colors in rviz are shown now in a proper way. According to the problem with gazebo... I'm very sorry, I've made a mistake: the right name for a gazebo-file is my_robot.gazebo, not flexweld.gazebo. And it's included the way you suggested. I've edited my post and now the names for all files are right.

olga_pi gravatar image olga_pi  ( 2020-03-26 05:37:19 -0500 )edit

ah, okay, edited my answer to maybe find the source of your error

Joe28965 gravatar image Joe28965  ( 2020-03-26 05:46:12 -0500 )edit

Did you mean I should remove <visual> tag? If so, I've removed it, but nothing has changed.

olga_pi gravatar image olga_pi  ( 2020-03-26 09:03:05 -0500 )edit

excuse me, yes, remove the <visual> tag, edited my answer to reflect that. I'm not entirely sure why it's not working. What happens if you add the gazebo reference directly to my_robot.xacro, instead of in a separate file?

Joe28965 gravatar image Joe28965  ( 2020-03-26 09:48:32 -0500 )edit

Unfortunately it still doesn't work. But thank you for the idea.

olga_pi gravatar image olga_pi  ( 2020-03-26 10:19:41 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-03-25 10:08:52 -0500

Seen: 31 times

Last updated: Mar 26