Exploring ROS2 with wheeled robotic – #1 – Launch ROS2 Simulation

0
42


By Marco Arruda

That is the primary chapter of the sequence “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 start out the simulation!

You’ll study:

  • The way to Launch a simulation utilizing ROS2
  • The way to Compile ROS2 packages
  • The way to Create launch information with ROS2

1 – Begin the setting

On this sequence 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 /choose/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’ll work solely with gazebo simulator.

3 – Create a brand new package deal and launch file

In an effort to launch the simulation, we’ll 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 comprise launch information and the brand new launch file as properly:

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 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 comprises nodes or different launch information.

On this case, we now have simply included one other launch file gazebo.launch.py and altered one among its arguments, the one which stands for the world title: world.

The robotic, in that case, is included on the earth file, so there is no such thing as a have to 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 setting:


set up(DIRECTORY
	launch
	DESTINATION share/${PROJECT_NAME}/
)
ament_package()

4 – Compile and launch the simulation

Use the command beneath 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 information or working executables inside a customized launch file

Associated programs & further hyperlinks:


The Constructsim Weblog