[ROS Projects] – My Robotic Manipulator #6 – STL Mesh file for URDF Link

[ROS-Projects]---My-Robotic-Manipulator-#6---STL-Mesh-file-for-URDF-Link

Written by Marco Arruda

06/07/2018

 

In this video we are going to set a .STL mesh file to one of the links of our robot using its URDF code. From the URDF model used in the previous videos, we are going to define a new XML MACRO to use mesh files for a given link. Up to the end of the video, we will be able to see the mesh in RViz and Gazebo simulator.


Repositories:

Robot description: https://bitbucket.org/theconstructcore/my-robotic-manipulator/src


URDF Course: https://goo.gl/PNEgCX


Robot Ignite Academy: https://goo.gl/1bg1UV

ROS Development Studio: https://goo.gl/wL5Mxz

Step 1. Meshes

Create e folder called meshes under the mrm_description directory and drag the .stl file you want into it.

Step 2. Modify the .xarco file

For easier test and debug, let’s comment out the other links in the mrm.xarco file.

  <!--
              
  <m_joint name="${link_01_name}__${link_02_name}" type="revolute"
           axis_xyz="0 1 0"
           origin_rpy="0 0 0" origin_xyz="0 0 0.4"
           parent="link_01" child="link_02"
           limit_e="1000" limit_l="0" limit_u="0.5" limit_v="0.5" />
           
  <m_link_cylinder name="${link_02_name}"
              origin_rpy="0 0 0" origin_xyz="0 0 0.4"
              mass="57.906"
              ixx="12.679" ixy="0" ixz="0"
              iyy="12.679" iyz="0"
              izz="0.651"
              radius="0.15" length="0.8" />
              
  <m_joint name="${link_02_name}__${link_03_name}" type="revolute"
           axis_xyz="0 1 0"
           origin_rpy="0 0 0" origin_xyz="0 0 0.8"
           parent="link_02" child="link_03"
           limit_e="1000" limit_l="0" limit_u="0.75" limit_v="0.5" />
           
  <m_link_cylinder name="${link_03_name}"
              origin_rpy="0 0 0" origin_xyz="0 0 0.4"
              mass="57.906"
              ixx="12.679" ixy="0" ixz="0"
              iyy="12.679" iyz="0"
              izz="0.651"
              radius="0.15" length="0.8" />
              
  <m_joint name="${link_03_name}__${link_04_name}" type="revolute"
           axis_xyz="0 1 0"
           origin_rpy="0 0 0" origin_xyz="0 0 0.8"
           parent="link_03" child="link_04"
           limit_e="1000" limit_l="0" limit_u="0.75" limit_v="0.5" />
           
  <m_link_cylinder name="${link_04_name}"
              origin_rpy="0 0 0" origin_xyz="0 0 0.4"
              mass="57.906"
              ixx="12.679" ixy="0" ixz="0"
              iyy="12.679" iyz="0"
              izz="0.651"
              radius="0.15" length="0.8" />
              
  <m_joint name="${link_04_name}__${link_05_name}" type="revolute"
           axis_xyz="0 0 1"
           origin_rpy="0 0 0" origin_xyz="0 0 0.8"
           parent="link_04" child="link_05"
           limit_e="1000" limit_l="-3.14" limit_u="3.14" limit_v="0.5" />
           
  <m_link_cylinder name="${link_05_name}"
              origin_rpy="0 0 0" origin_xyz="0 0 0.125"
              mass="18.056"
              ixx="0.479" ixy="0" ixz="0"
              iyy="0.479" iyz="0"
              izz="0.204"
              radius="0.15" length="0.25" />
  -->

Then we define a new mesh called m_link_mesh in the links_joints.xarco with the following content

  <xacro:macro name="m_link_mesh" params="name origin_xyz origin_rpy meshfile meshscale mass ixx ixy ixz iyy iyz izz">
    <link name="${name}">
      <inertial>
        <mass value="${mass}" />
        <origin rpy="${origin_rpy}" xyz="${origin_xyz}" />
        <inertia ixx="${ixx}" ixy="${ixy}" ixz="${ixz}" iyy="${iyy}" iyz="${iyz}" izz="${izz}" />
      </inertial>
      <collision>
        <origin rpy="${origin_rpy}" xyz="${origin_xyz}" />
        <geometry>
          <mesh filename="${meshfile}" scale="${meshscale}"/>
        </geometry>
      </collision>
      <visual>
        <origin rpy="${origin_rpy}" xyz="${origin_xyz}" />
        <geometry>
          <mesh filename="${meshfile}" scale="${meshscale}"/>
        </geometry>
        <material name="light_black"/>
      </visual>
    </link>
  </xacro:macro>

Please notice that in the params, we added two new property called meshfile and meshscale.

Since we are now using the mesh instead of a cylinder, let’s go back to the mrm.xarco and change it.

  <m_link_mesh name="${link_01_name}"
              origin_rpy="0 0 0" origin_xyz="0 0 0.2"
              mass="157.633"
              ixx="13.235" ixy="0" ixz="0"
              iyy="13.235" iyz="0"
              izz="9.655"
              meshfile="package://mrm_description/meshes/Link1-v2.stl"
              meshscale="0.001 0.001 0.001" />

Please make sure the meshscale is correct for your .stl file. In the simulation, the scale is in m. We change the meshscale to 0.001 because the stl file is done on the scale of mm.

Step 2. Modify the launch file

Since we only use one joint, we’ll only need the controller for one joint. Let’s change this part in the /launch/spawn.launch

        <!-- Controllers -->
        <node name="controller_spawner" pkg="controller_manager" type="spawner"
            respawn="false" output="screen" ns="/mrm"
            args="--namespace=/mrm
            joint_state_controller
            joint1_position_controller
            --timeout 60">
        </node>

Step 3. Launch the description in RViz and Gazebo

You can launch the RViz with the following command. After launching, please go to tools->graphical tool. You will see the RViz is open.

roslaunch mrm_description rviz.launch

After launching, we noticed that the link is not in the correct position, let’s go back to the mrm.xarco file and give it a proper offset.

  <m_link_mesh name="${link_01_name}"
              origin_rpy="0 0 0" origin_xyz="0 0 -0.1"
              mass="157.633"
              ixx="13.235" ixy="0" ixz="0"
              iyy="13.235" iyz="0"
              izz="9.655"
              meshfile="package://mrm_description/meshes/Link1-v2.stl"
              meshscale="0.001 0.001 0.001" />

You can also spawn the robot in gazebo, please go to Simulations->Empty to open a simulation the run the following command to spawn the robot

roslaunch mrm_description spawn.launch

 

 

Edit by: Tony Huang

Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This