[ad_1]
By Marco Arruda
That is the first 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 bundle + launch file to begin the simulation!
You’ll study:
Launch a simulation utilizing ROS2
Compile ROS2 packages
Create launch information with ROS2
1 – Begin the atmosphere
On this collection we’re utilizing ROS2 cunning, go to this web page, create a brand new rosject choosing ROS2 Cunning distro and and run it.
2 – Clone and compile the simulation
Step one is to clone the dolly robotic bundle. 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.bashcd ~/ros2_wscolcon construct –symlink-install –packages-ignore dolly_ignition
Discover we’re ignoring the ignition associated bundle, that’s as a result of we are going to work solely with gazebo simulator.
3 – Create a brand new bundle 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/srcros2 pkg create my_package –build-type ament_cmake –dependencies rclcpp
After that, it’s essential 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/launchtouch ~/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_directoryfrom launch import LaunchDescriptionfrom launch.actions import DeclareLaunchArgumentfrom launch.actions import IncludeLaunchDescriptionfrom 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 accommodates nodes or different launch information.
On this case, we’ve simply included one other launch file gazebo.launch.py and altered one among its arguments, the one which stands for the world identify: world.
The robotic, in that case, is included on the earth file, so there isn’t any 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 atmosphere:set up(DIRECTORYlaunchDESTINATION share/${PROJECT_NAME}/)
ament_package()
4 – Compile and launch the simulation
Use the command under to compile solely the created bundle:cd ~/ros2_ws/colcon construct –symlink-install –packages-select my_packagesource ~/ros2_ws/set up/setup.bashros2 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 operating executables inside a customized launch file
Associated programs & further hyperlinks:
Ricardo Téllez
is Co-founder and CTO of The Assemble
[ad_2]