Launching the Complete Robot Simulation in ROS 2

Up to this point, we have built and tested individual parts of our robot: the URDF description, Gazebo simulation, controllers, and even integration with MoveIt and a remote Alexa interface.

Now it’s time to bring everything together into a single launch file that runs the complete robot simulation with all components working in harmony.

This is a crucial step before deploying the system onto the physical robot, as it allows us to validate the entire software pipeline in a safe and controlled environment.

1. Creating the Bringup Package

First, we create a new ROS 2 package called arduinobot_bringup. This package will serve as the central place to manage launch files for bringing up the robot.

 

Full Command

				
					ros2 pkg create arduinobot_bringup

				
			

Let’s break down the code

  • ros2 pkg create → Command to generate a new ROS 2 package.

  • arduinobot_bringup → The name of the package. By convention, a *_bringup package contains launch files and scripts that “bring up” the robot system (start all its components together).

2. Writing the Launch File

Now we create the main launch file: simulated_robot.launch.py. This file will start Gazebo, the controllers, MoveIt, and the remote interface.

Full Code: simulated_robot.launch.py

				
					from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
import os

from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    # Get paths to other packages
    gazebo_pkg = get_package_share_directory('arduinobot_gazebo')
    controller_pkg = get_package_share_directory('arduinobot_controller')
    moveit_pkg = get_package_share_directory('arduinobot_moveit')
    interface_pkg = get_package_share_directory('arduinobot_remote_interface')

    # Include their launch files
    gazebo_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(gazebo_pkg, 'launch', 'gazebo.launch.py'))
    )

    controller_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(controller_pkg, 'launch', 'controller.launch.py'))
    )

    moveit_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(moveit_pkg, 'launch', 'moveit.launch.py'))
    )

    interface_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(interface_pkg, 'launch', 'interface.launch.py'))
    )

    return LaunchDescription([
        gazebo_launch,
        controller_launch,
        moveit_launch,
        interface_launch
    ])

				
			

Let’s break down the code

				
					from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
import os
from ament_index_python.packages import get_package_share_directory

				
			
  • LaunchDescription → Defines the set of processes to start.

  • IncludeLaunchDescription → Lets us include other launch files.

  • PythonLaunchDescriptionSource → Allows referencing launch files written in Python.

  • get_package_share_directory → Finds the path to installed packages.

 

Getting Package Paths

				
					gazebo_pkg = get_package_share_directory('arduinobot_gazebo')
controller_pkg = get_package_share_directory('arduinobot_controller')
moveit_pkg = get_package_share_directory('arduinobot_moveit')
interface_pkg = get_package_share_directory('arduinobot_remote_interface')

				
			

Here we locate the package directories for Gazebo, controller, MoveIt, and the remote interface.

 

Including Launch Files

				
					gazebo_launch = IncludeLaunchDescription(
    PythonLaunchDescriptionSource(
        os.path.join(gazebo_pkg, 'launch', 'gazebo.launch.py'))
)

				
			

We repeat this for each package (controller, moveit, interface). Each line tells ROS 2 to include another launch file.

 

Final Launch Description

				
					return LaunchDescription([
    gazebo_launch,
    controller_launch,
    moveit_launch,
    interface_launch
])

				
			

This returns a list of launch actions that ROS 2 executes. Running this file launches all components together.

 

3. Installing the Launch Directory

To ensure the launch file is installed with the package, we need to update the CMakeLists.txt.

 

Full Code Addition

				
					install(
  DIRECTORY launch
  DESTINATION share/${PROJECT_NAME}/
)

				
			

Let’s break down the code

  • install() → Command in CMake to install files into the workspace.

  • DIRECTORY launch → Installs everything in the launch directory.

  • DESTINATION share/${PROJECT_NAME}/ → Puts the files in the package’s share directory so they can be found at runtime.

 

4. Running the Full Simulation

Now we are ready to run the complete system.

 

Step 1 — Build the Workspace

				
					colcon build

				
			

Step 2 — Source the Workspace

				
					. install/setup.bash

				
			

Step 3 — Launch the Simulation

				
					ros2 launch arduinobot_bringup simulated_robot.launch.py

				
			

When you run this, Gazebo starts, controllers are loaded, MoveIt is initialized, and the remote interface is ready.

 

5. Connecting with Alexa via Ngrok

To test voice commands remotely, we need to expose the robot’s web service through ngrok.

Steps:

  1. Start ngrok:

				
					ngrok http 5000


				
			
  1.  
  2. Copy the new Forwarding URL.
  3. Paste it into your Alexa Developer Console under the endpoint configuration.

  4. Speak a command to Alexa (e.g., “Move the robot arm forward”) and watch it execute in the simulation.

 

6. Conclusion

We now have a fully integrated robot simulation in ROS 2, complete with Gazebo, controllers, MoveIt, and a remote Alexa interface.

This simulation acts as a sandbox where you can safely test interactions and debug issues before deploying on the physical robot.

The next step is to bring this exact setup to the real robot — and that’s when your robot truly comes alive.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_US