0

I am using ROS2/Gazebo project. In Gazebo, I have a cube, and I want to have an aruco marker on it. Two questions:

  1. How to only show an image (png) on one side of a cube? Currently, it shows on all six sides.
  2. How to make the image smaller than the side of a cube? I used the code (below), but it tiles small images, instead of showing just one, centred.

Comment to code: I used both codes in sdf model files themselves, and in a separate .material file (see below). No success in both case.

Thank you.

Code:

Material file:

material aruco_marker_42
{
  technique
  {
    pass
    {
      texture_unit
      {
        texture aruco_marker_42.png
        scale 0.5 0.5
        u_repeat 1
        v_repeat 1
        //filter trilinear
        //max_anisotropy 8
        padding 0.2
        repeat_u false
        repeat_v false     
        //wrap clamp
        //wrap_s clamp
        //wrap_t clamp
        
        filtering anisotropic
        max_anisotropy 8
        //scale 1 1
        // set wrap to "clamp" to prevent tiling
        wrap s_clamp t_clamp        
      }
    }
  }
}

Model file (pasted as part of world file, contains pretty much everything I tried):

<model name='charger'>
    <static>true</static>
    <link name='charger_link'>
        <collision name='charger_collision'>
            <geometry>
                <box>
                    <size>1 1 1</size>
                </box>
            </geometry>
        </collision>
        <visual name='charger_visual'>
            <geometry>
                <box>
                    <size>1 1 1</size>
                    <!-- size>2 2 1</size -->
                </box>
            </geometry>
            <material>
                <script>
                  <uri>model://aruco_markers/materials/scripts</uri>
                  <uri>model://aruco_markers/textures/aruco_marker_42.png</uri>
                  <name>aruco_marker_42</name>

                  <!-- texture_coordinates>
                    <u_scale>0.1</u_scale>
                    <v_scale>0.1</v_scale>
                    <padding>0.4</padding>
                    <use_interpolation>false</use_interpolation>
                  </texture_coordinates -->
                </script>
                <texture>
                  <!-- diffuse>my_texture</diffuse -->
                  <!-- padding>0.5</padding>
                  <!-- scale>0.5 0.5</scale>
                  <u_scale>0.5</u_scale>
                  <v_scale>0.5</v_scale -->
                  <!-- scale>0.5 0.5</scale -->

                  <scale>1 1</scale>
                  <u_scale>0.5</u_scale>
                  <v_scale>0.5</v_scale>
                  <repeat>0 0</repeat>
                  <wrap_s>clamp</wrap_s>
                  <wrap_t>clamp</wrap_t>     
                  
                  <use_texture_coords>false</use_texture_coords>
                  <scale>0.5 0.5</scale>
                  <u_scale>0.5</u_scale>
                  <v_scale>0.5</v_scale>                               
                  
                </texture>    
            </material>
        </visual>
    </link>
    <pose>0 7.7 0.5 0 0 0</pose>
</model> 
Steve Brown
  • 369
  • 1
  • 3
  • 12

2 Answers2

1

The workaround I used in a project is to define a very thin cube onto which I applied the QR code as texture. To justify the dirty trick I imagined it as a sheet of paper printed and attached on the box. This workaround can solve both your problems actually.

Another method is to create a COLLADA (.dae) model of the box with the proper texture applied only on one side. Here you can see how it is done in an example.

Alesof
  • 321
  • 2
  • 8
  • I still do not see how to fix a problem with images tiling on a cube. Or should I embed cube with image into another, with larger size? That will work, but is not nice... – Steve Brown Apr 11 '23 at 19:59
  • Yes, using two cubes is the easy way but not a clean solution. Creating the collada mesh and applying it to the cube is the clean but longer solution. – Alesof Apr 12 '23 at 06:48
  • I am going to ask something funny, I guess, but... According to ChatGpt :) there are all those tags (see my code above), like "padding" and so on. None of them worked for me, but maybe I am just doing it wrong? I do not want to get into collada, at least not fot this project... At least, is there a place where I can see all those tags explained? I found nothing in Google... – Steve Brown Apr 12 '23 at 11:19
  • The sdf format has an [official page](http://sdformat.org/spec) in which are described all the tags. Don’t know if chatgpt agrees :) – Alesof Apr 14 '23 at 20:20
0

Not exactly a pretty solution, but definitely works: we merge two shapes, one with marker, and one larger, without one:

<model name='charger'>
    <!-- default_parameters>
        <sdf_param> tag_scaling_factor_x 0.4 </sdf_param>
    </default_parameters -->
    <static>true</static>
    <link name='charger_body_link'>
        <collision name='charger_body_collision'>
            <geometry>
                <box>
                    <size>0.5 0.5 1</size>
                </box>
            </geometry>
        </collision>
        <visual name='charger_body_visual'>
            <geometry>
                <box>
                    <size>0.5 0.5 1</size>
                </box>
            </geometry>
        </visual>
    </link>    
    <link name='aruco_marker_link'>
        <collision name='aruco_marker_collision'>
            <geometry>
                <box>
                    <size>0.1 0.01 0.1</size>
                </box>
            </geometry>
        </collision>
        <visual name='charger_visual'>
            <geometry>
                <box>
                    <size>0.2 0.01 0.2</size>
                    <!-- size>${tag_scaling_factor_x} 0.01 ${tag_scaling_factor_z}</size -->
                </box>
            </geometry>
            <material>
                <script>
                  <uri>model://aruco_markers/materials/scripts</uri>
                  <uri>model://aruco_markers/textures/aruco_marker_42.png</uri>
                  <name>aruco_marker_42</name>
                </script>
              </material>
              <pose>0 -0.25 0.15 0 0 0</pose>
        </visual>
    </link>
    <pose>0 7.7 0.5 0 0 0</pose>
</model> 
Steve Brown
  • 369
  • 1
  • 3
  • 12