Robotics - ROS2 Gazebo Differential Drive Onboard

ROS2, Gazebo

Posted by Rico's Nerd Cluster on November 5, 2024

Install Gazebo

1
sudo apt install ros-iron-gazebo-ros-pkgs ros-iron-gazebo-ros2-control

Add A Launchfile

File Directory:

1
2
├── launch
│   └── empty_world.launch.py
  • mkdir launch
  • setup.py Make sure to have:

    1
    2
    3
    4
    5
    6
    7
    
      data_files=[
          ('share/ament_index/resource_index/packages',
              ['resource/' + package_name]),
          ('share/' + package_name, ['package.xml']),
          # Include all files in the launch directory
          (os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')),
      ],
    
  • empty_world.launch.py
1
2
3
4
5
6
7
8
9
10
from launch import LaunchDescription
from launch.actions import ExecuteProcess

def generate_launch_description():
    return LaunchDescription([
        ExecuteProcess(
            cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_factory.so'],
            output='screen'
        )
    ])

Add An Arg In Launch File

1
2
3
4
5
6
7
8
9
10
11
def generate_launch_description():
    # Declare launch arguments
    no_rviz_arg = DeclareLaunchArgument(
        'no_rviz',
        default_value='false',
        description='Flag to disable RViz'
    )
    no_rviz = LaunchConfiguration('no_rviz')
    # register the arg and the node
    ld.add_action(no_rviz_arg)
    ld.add_action(rviz_node)