Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

How to create models for simulations

emcauliffe edited this page Jan 29, 2023 · 1 revision

Background

Gazebo simulator uses URDF format for the models. URDF is an XML format for representing a robot model. Some of the common components described in the XML files are joints, links, visual & collision components. Learn more from here. In the repo, you may notice some .xacro files. These are basically URDF files with some extra functionality gained by using a macro language called xacro.

Here is an example code that defines the chassis link from xacro file that was originally used for the rover:

<!-- Define the chassis link -->
<link name='chassis'>

	<!-- Add a collision component for the chassis, in this case its just a box. You can also use meshes as collision components -->
	<collision name='collision'>
	  <!-- Origin is the coordinates and orientation-->
	  <origin rpy="0 0 1.5707" xyz="-0.4 0 -0.1"/> 
	  <geometry>
		<box size="0.7 1.0 0.3"/>
	  </geometry>
	</collision>
	
	<!-- Add a visual component for the chassis. Note how a stl file is refered. This is the mesh you export from SolidWorks  -->
	<visual name='chassis_visual'>
	  <origin rpy="0 0 0" xyz="0 0 -0.04"/>
	  <geometry>
		<mesh filename="package://simulation/robot/chassis_with_wheels.stl"/>
	  </geometry>
	</visual>
	
	<!-- Inertial component is necessary to have proper physics for the object  -->
	<inertial>
	  <mass value="20.0"/>
	  <origin xyz="0 0 -0.1" rpy=" 0 0 1.5707"/>
	  <inertia
		  ixx="1.0" ixy="0" ixz="0"
		  iyy="1.0" iyz="0"
		  izz="0.5"
	  />
	</inertial>
</link>

Then you can have joints such as this one between the chassis and the wheel:

<joint type="continuous" name="left_wheel_hinge">
	<origin xyz="0.045 0.49 -0.41" rpy="0 1.5707 1.5707"/>
	<child link="left_wheel"/>
	<parent link="chassis"/>
	<axis xyz="0 0 1" rpy="0 0 0"/>
	<limit effort="100" velocity="100"/>
	<joint_properties damping="0.0" friction="0.0"/>
</joint>

More information on what properties to use for joints can be found here

SolidWorks to URDF plugin video

You can also watch this video which shows on how to use the plugin if you don't want to read this.

SolidWorks to URDF plugin

Although you can manually create each links and joints, using the SW2URDF plugin does all that for that using the properties you describe in SW. First make sure you have SW and the plugin is installed from here.

You can then access the exported from the tools tab > Export as URDF>

1. Add the links

When you open the exporter tool, you can see links on the sidebar. Give your link a name, such as chassis or front_right_wheel. Select all the components that should be part of your link in the assembly view(blue means its selected). For example if my link is the chassis, I would select all the components that should be part of the chassis link, this will be considered as one object. You can select screws, spacers, bolts, etc to be part of the link you are working with. The example below the chassis being selected as a link. Name the joints accordingly too, joints name can usually be the component being joined and a suffix of joint at the end for example front_right_suspension_joint. The other properties can be left as default.

Then you can add child links to the link. The hierarchy is based of how you want the connections to be. For example, the right wheel will be the child of the right suspension, and the right suspension will be the child of the chassis. For example, this is the current hierarchy for the rover:

2. Align the references points properly

Once you are done adding all the links, click preview and export which will then create the URDF references(this may take a while). Close the popup window as we are not describing the joints yet. This is because the URDF references points the plugin creates are not at the proper location we want them to be. We should first align these points properly to be on the joints, then we can export it again.

3. Choosing the joints

Open the popup window for the joints by clicking preview and export again. Make sure you understand the different types of joints from here. The important properties are the axis the joint acts against, limits, effort and velocity. Fill those in accordingly, you can play around with these values later after you test the model in RVIZ.

4. Inspecting the URDF model in RVIZ

Once you are done exporting the URDF folder, copy it to linux or wherever you run ROS from. The exported package already has a launch file for RVIZ display and for Gazebo. For starters, we should just inspect the model in the RVIZ and check if the joints are working properly. Launch display.launch from the package using:

roslaunch Package_Name display.launch

If you have problems with ROS not finding the launch file, make sure you run a catkin_make or catkin_build Package_Name so that the launch files are able to be found. Re-open your terminal to uses updated catkin workspace too.

Once RVIZ has been launched, you will notice it is currently not displaying any topics, you have to add a new topic which is called Robot Model which should then display the model. Make sure the correct frame is selected in the model.

You can then play around with the joint values using the other popup window.

5. Opening the model in Gazebo

You can use the the other launch file in the package to run the Gazebo simulation. The command is:

roslaunch Package_Name gazebo.launch

Of course, this is not that useful as there is not other control software trying to interact with the model. To enble that, you need to use Gazebo plugins and your own controller.