Robotic Arm Demo
Last updated
Last updated
In this tutorial, we will walk you through setting up a robot arm in Gazebo. First, we will download the SDF model file for the UR10 robot arm and convert it into a URDF file. Next, we will explain how to configure the ros2 control and Gazebo simulation for the robot model. Finally, we demonstrate launching the system and issuing a basic command to move the robotic arm.
Please note, this tutorial focuses on practical steps and does not cover the theoretical aspects of robotic arm control.
The first step is to download a robotic arm model. Many options are available online and in this tutorial, we will use the Universal Robotics UR10 robot arm. You can download the model file at this .
The model files assume all relevant files are store in the ur10
directory, therefore, it's important to ensure the content in the zip file extract to a ur10
directory. Moreover, the parent directory of the ur10
directory needs to be included in the Gazebo resource path. More specifically, suppose we extract the UR10 robot arm model files to ~/demo/models/
directory:
We need to ensure that the path ~/demo/models
is included in the Gazebo resource path, which can be configured with the environment variable IGN_GAZEBO_RESOURCE_PATH
in Gazebo Fortress.
We can now launch the system and verify the setup is correct. In this tutorial, both ROS2 components and Gazebo are launched using the launch file. This ensures a consistent experience with different components and minimize the separation between ROS2 and Gazebo. Through out the tutorial, we consider Gazebo a sub-system of the ROS2 ecosystem.
If you download the code attached to this tutorial, you can launch the system using the following command:
You can also create your own launch file. The objective is to launch the the Gazebo world with the downloaded robotic arm model. The code below demonstrates how to launch a Gazebo world with a specific world sdf file:
Make sure the world sdf file (in the above case, it's simple_world_with_ur10.sdf
) contains the robot model:
If everything works correctly, you should see Gazebo launched successfully and a robot arm lying on the ground:
If we don't care about simulation, we don't need to deal with the SDF file because URDF is the native format for describing robots in ROS2. However, if we want to integrate ROS2 with a simulator such as Gazebo, additional simulation-specific information is required and it's usually specified in the SDF file.
Both URDF and SDF are used to describe robots and they have overlaps. If we use two formats to describe the same robot, we need to ensure they are in-sync. For example, whenever we modify the geometry in one file, we need to make the same update in another file too.
It's important to notice that many components in the ROS2 and Gazebo ecosystem either require URDF file or is able to consume it. Therefore, a possible solution is to put geometry-related information in an URDF file, group the control-specific and simulation-specific information in a separate URDF file, and use xacro
to combine the two files. For example:
In this way, the robot model definition is separated from the control and simulation configurations and we only need to maintain a single source of the model. Another benefit is that it's easy to replace the control and simulation configurations.
One more technical detail. The robot arm will be subject to the force. If we don't fix the base to the ground, it will not behave as expected. To fix the base to the ground in Gazebo, we can add a dummy link and joint in the URDF file. For example:
In this tutorial, we want to demonstrate how to move a robotic arm. It has two aspects:
Use the ros2 control package to control the robot hardware
Because we don't have the real robot hardware, we will use Gazebo to simulate one.
As mentioned earlier, the configurations of ros2 control and the gazebo simulation are separate from the robot model. Below is a sample configuration file:
We also need to configure the controllers, which are specified in a parameter file. In our case, the parameter file is simple: we will use a position controller for all the joints.
We need to create the following tasks in the launch file:
Process the xacro file. Recall that the model definition and the ros2 control/simulation configurations are stored in two separate files. We need to merge them into one single file during the launch. This can be done using the xacro
library.
Create a robot state publisher. This is almost always needed in any ros2 application.
Load the position controller and the joint state broadcaster. These two components are part of the rso2 control package. They are required because they are specified in the parameter file.
Launch the Gazebo node. We can specify a world SDF file in this step.
Spawn the model. This is the step where we instantiate the robot arm model. When we spawn a model, we need to provide the world name, model name, and the model URDF file with the ros2 control and the simulation configuration. We can also specify the entity position.
Note that the sequence of the task execution is important. We spawn the model first, followed by activating the joint state broadcaster, and activate the position controller at last. The execution order can be enforced by using the RegisterEventHandler
utility function. For example, the code blow only execute load_joint_state_broadcaster
after the ignition_spawn_entity
process exits.
Once everything is up running. We can now send a request to the controller. The request takes an array as inputs as the controller controls multiple joints. To send a request, we publish a message to the /position_controller/commands
topic. For example:
©2023 - 2024 all rights reserved
Many tools exist to convert SDF files to URDF files. You can also check out the on how to perform the conversion manually. It's a good practice to always verify the generate files. Unfortunately, we cannot simply include the URDF model in the SDf world file. Instead, we can create a node that will run the create
executable in the ros_gz_sim
package. For example:
The configuration of ros2 control is standard. We specify the joint types, state interfaces, and command interfaces in the URDF file inside the ros2_control
element. The simulation part is handled by the package, which is responsible for simulating the movement of the joints. Moreover, it also provides the hardware interface used by the ros2 control.
The code can be downloaded at this .