[ad_1]
By Marco Arruda
That is the primary chapter of the collection “Exploring ROS2 with a wheeled robotic”. On this episode, we setup our first ROS2 simulation utilizing Gazebo 11. From cloning, compiling and making a package deal + launch file to begin the simulation!
You’ll be taught:
- The best way to Launch a simulation utilizing ROS2
- The best way to Compile ROS2 packages
- The best way to Create launch recordsdata with ROS2
1 – Begin the atmosphere
On this collection we’re utilizing ROS2 cunning, go to this web page, create a brand new rosject deciding on ROS2 Cunning distro and and run it.

2 – Clone and compile the simulation
Step one is to clone the dolly robotic package deal. Open an online shell and execute the next:
cd ~/ros2_ws/src/
git clone https://github.com/chapulina/dolly.git
Supply the ROS 2 set up folder and compile the workspace:
supply /decide/ros/cunning/setup.bash
cd ~/ros2_ws
colcon construct --symlink-install --packages-ignore dolly_ignition
Discover we’re ignoring the ignition associated package deal, that’s as a result of we are going to work solely with gazebo simulator.
3 – Create a brand new package deal and launch file
To be able to launch the simulation, we are going to create the launch file from the scratch. It goes like:
cd ~/ros2_ws/src
ros2 pkg create my_package --build-type ament_cmake --dependencies rclcpp
After that, you will need to have the brand new folder my_package in your workspace. Create a brand new folder to include launch recordsdata and the brand new launch file as nicely:
mkdir -p ~/ros2_ws/src/my_package/launch
contact ~/ros2_ws/src/my_package/launch/dolly.launch.py
Copy and paste the next to the brand new launch file:
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
def generate_launch_description():
pkg_gazebo_ros = get_package_share_directory('gazebo_ros')
pkg_dolly_gazebo = get_package_share_directory('dolly_gazebo')
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.be a part of(pkg_gazebo_ros, 'launch', 'gazebo.launch.py')
)
)
return LaunchDescription([
DeclareLaunchArgument(
'world',
default_value=[
os.path.join(pkg_dolly_gazebo, 'worlds', 'dolly_empty.world'), ''
],
description='SDF world file',
),
gazebo
])
Discover {that a} launch file returns a LaunchDescription that incorporates nodes or different launch recordsdata.
On this case, we have now simply included one other launch file gazebo.launch.py and adjusted considered one of its arguments, the one which stands for the world identify: world.
The robotic, in that case, is included on this planet file, so there isn’t any must have an additional spawn node, for instance.
And append to the tip of the file ~/ros2_ws/src/my_package/CMakeLists.txt the next instruction to put in the brand new launch file into the ROS 2 atmosphere:
set up(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)
ament_package()
4 – Compile and launch the simulation
Use the command under to compile solely the created package deal:
cd ~/ros2_ws/
colcon construct --symlink-install --packages-select my_package
supply ~/ros2_ws/set up/setup.bash
ros2 launch my_package dolly.launch.py

5 – Conclusion
That is how one can launch a simulation in ROS2. It is very important discover that:
- We’re utilizing a pre-made simulation: world + robotic
- That is how a launch file is created: A python script
- In ROS2, you continue to have the identical freedom of together with different recordsdata or working executables inside a customized launch file
Associated programs & additional hyperlinks:

The Constructsim Weblog
[ad_2]
