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

how to add image to model.urdf.xacro

asked 2020-11-12 19:41:46 -0600

praskot gravatar image

updated 2020-11-12 19:42:14 -0600

I'm trying to add an arcuo-marker (*.png file) to a simple model (box) in urdf. I realize there are quite a few posts related to this but I couldn't make them work for me. Can anyone point me in the right direction? Thank you

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

    <xacro:property name="PI" value="3.1415926535897931"/>
    <xacro:property name="mass" value="1" />
    <xacro:property name="length" value="1." />
    <xacro:property name="width" value="0.5" />
    <xacro:property name="height" value="0.2" />

    <!-- Base Link -->
    <link name="box">
        <collision>
            <origin xyz="0 0 ${height/2}" rpy="0 0 0"/>
            <geometry>
                <box size="${length} ${width} ${height}"/>
            </geometry>
        </collision>
        <visual>
            <origin xyz="0 0 ${height/2}" rpy="0 0 0"/>
            <geometry>
                <box size="${length} ${width} ${height}"/>
            </geometry>
            <material name="red"/>
        </visual>
        <inertial>
            <origin xyz="0 0 ${height/2}" rpy="0 0 0"/>
            <mass value="${mass}"/>
            <inertia ixx="0.1" ixy="0.0" ixz="0.0" iyy="0.1" iyz="0.0" izz="0.4"/>
        </inertial>
    </link>
    <gazebo reference="box">
            <material>YourMaterialName</material>  <!-- how should i include an image here -->
    </gazebo>
</robot>
edit retag flag offensive close merge delete

Comments

please give the solutions you have tried.

shiraz_baig gravatar image shiraz_baig  ( 2020-11-12 20:31:18 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2020-11-13 05:23:00 -0600

Weasfas gravatar image

updated 2020-11-13 05:23:59 -0600

Hi @praskot,

although I am going to answer your question I would like to tell you that, in the future, you may want to ask this type of questions on Gazebo answers, since this is something direcly related with Gazebo you will be able to find better information and help there.

Already said that, in order to achieve what you want you have several possibilities:

In case you want to have only an independent texture which can be used in every simple model of gazebo you will need to generate your own material script, and here is how you do that:

If you have installed properly Gazebo, in the location /usr/share/gazebo-9/media/materials/textures you need to copy your image, lets say test.jpg. Then in the location /usr/share/gazebo-9/media/materials/scripts you will have to generate a new script (or you can edit the file gazebo.materials where all Gazebo default materials are stored). Let us say that you jut modify this file, well at the end of the file (or wherever you want) just copy the following script:

material testing/material
{
  receive_shadows on

  technique
  {
    pass
    {
      ambient 1 1 1 1.000000
      diffuse 1 1 1 1.000000
      specular 0.03 0.03 0.03 1.000000 
      emissive 0.900000 0.900000 0.900000 1.000000

      texture_unit
      {
        texture test.jpg
      }
    }
  }
}

Once this is done, it as simple as including the name as a default Gazebo material in your xacro. That is:

<gazebo reference="box">
  <material>testing/material</material>
</gazebo>

An you will have your image as texture.

But there is another possibility: You can generate a 3D model with any modeling program like Blender and then add a custom texture with a UV Map and finally, export this model as a COLLADA file. Then, when you include this 3D model in a gazebo world, the texture images (That must be located in the same root folder as the model) will be automatically parsed and included as a material.

And the last possibility: Is to have a custom Gazebo model. For this you will have to have the model files structured as follow:

my_model
|_ model.config
|_ model.sdf
|_ materials
  |_ script
      |_ testing.material (here you include the script)
  |_ textures
      |_ test.jpg

And then use it in the model.sdf as:

<material>
 <script>
  <uri>model://my_model/materials/scripts</uri>
  <uri>model://my_model/materials/textures</uri>
  <name>testing/material</name>
 </script>
</material>

Hope this helps you.

Regards.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-11-12 19:41:46 -0600

Seen: 1,712 times

Last updated: Nov 13 '20