Skip to content
ImagineWorld

ROS 2 and Deep Reinforcement Learning

node_idnode-book_mastering-ros-2-for-robotics-programming_chapter-15-ros-2-and-deep-reinforcement-learning
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num15
chapter_titleROS 2 and Deep Reinforcement Learning
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 15 — ROS 2 and Deep Reinforcement Learning

Section titled “Chapter 15 — ROS 2 and Deep Reinforcement Learning”

In the previous chapter, we discussed LLM and building AI agents. This chapter will discuss the interfacing of reinforcement learning algorithms for robots using ROS 2, specifically deep reinforcement learning. We will discuss how to train, test, and deploy Deep Reinforcement Learning (DRL) algorithms and libraries and interface to robots using ROS 2. The primary focus of the chapter will be introducing NVIDIA Isaac Lab, an open-source, unified framework for robot learning that helps developers train, test, and deploy robot learning policies. By combining the NVIDIA Isaac Sim simulator and Isaac Lab, developers can train various robots like robotic arms, wheeled robots, legged robots, and humanoids.

We will discuss the training and testing of robotic arms, legged robots, and humanoid robots using Isaac Sim and Isaac Lab and interfacing to hardware using ROS 2.

In this chapter, we’re going to cover the following main topics:

  • Dive into deep reinforcement learning
  • Setting up Isaac Lab in Ubuntu 24.04
  • Training and testing robots using Isaac Lab
  • Deploying a trained RL model to a real robot

To follow this chapter, you should install Ubuntu 24.04 LTS with ROS 2 Jazzy desktop. It can be in Docker, WSL 2, or on a real machine. Your PC will need a decent NVIDIA RTX GPU with >8GB of VRAM. The reference materials for this chapter can be found in the Chapter15 folder of the following GitHub repository: https://github.com/PacktPublishing/Mastering-ROS-2-for-Robotics-Programming/tree/main/Chapter15.

We humans learn through trial and error to take better actions based on the rewards and punishments we receive. Over time, we optimize our actions by maximizing the rewards and minimizing punishment. This process is called Reinforcement Learning (RL). This technique is used in various domains like robotics and AI, where agents learn to make decisions by interacting with the environment and receiving feedback.

In this section, we will discuss important concepts in RL and DRL. This will give you a quick guide before we jump into the application side of things. If you are new to RL, this section will be very useful to you. So, let’s begin by discussing RL and DRL.

Reinforcement learning is a type of machine learning in which the agent learns from interacting with the environment. An agent performs actions and receives rewards or penalties. Based on the rewards and penalties, the agent adjusts its behavior to maximize its rewards. Figure 15.1 shows a block diagram of an RL agent interacting with the environment.

Figure 15.1: Block diagram of RL agent

Figure 15.1: Block diagram of RL agent

Here are some important terminologies we have to understand from the RL block diagram:

  • Agent: This entity can learn and make decisions by interacting with the environment. A policy determines the behavior of the agent. The policy maps from the current observation of the agent to the action output. The policy can function with tunable parameters or a deep neural network [1].
  • Environment: This is the external world with which the agent interacts.
  • Action (a): This is the decision made by the agent to influence the environment.
  • State (s): This is the representation of the environment at a specific time.
  • Reward (r): This is the value received from the environment after an action. It is used to evaluate the action’s success.

The goal of the RL agent is to maximize positive rewards over time by learning the optimal policy. The learned policy will have an accurate mapping from state to actions.

In the next section, we will see the difference between classic and deep reinforcement learning.

Based on the complexity of the agent, the input space and action spaces of the agent may have to use different types of policies. For simple RL applications with limited action space and state, we can use methods like the Q-learning algorithm [2]. This algorithm is not a neural network-based model but a simple function suitable for small state and action spaces. These traditional RL policies may fail if the application is complex.

This is where we use DRL. DRL is an advanced form of reinforcement learning that combines traditional RL concepts with deep learning. Classical RL methods rely on tables or simple functions; DRL uses Deep Neural Networks (DNNs) to approximate complex functions like value functions, policies, or models of the environment. This makes DRL particularly powerful for tasks with high-dimensional input, such as raw images, LiDAR data, or other rich sensor modalities.

If the RL application needs complex and high-dimensional input spaces like images or sensor data, we may have to use DQNs (Deep Q-Networks) [3]. A DQN uses a neural network to approximate the Q-function, which allows the RL agent to scale problems where classical RL algorithms fail. The DQN scales the RL to handle large state spaces like pixels in the images. An RL agent playing video games is an example application of a DQN.

Figure 15.2 shows a block diagram of DRL, which uses a DNN instead of Q-learning in the agent. The state and action space of the DRL agent are complex and high-dimensional. The DNN has parameters (denoted as θ) and defines a policy π (s, a), which tells the agent what action to take in states.

Figure 15.2: Block diagram of DRL agent

Figure 15.2: Block diagram of DRL agent

In the next section, we will explore the different applications of DRL and a list of popular classic and DRL algorithms.

DRL can be extensively applied in robotics. One of the trending areas of robotics is humanoid robots. Many humanoid robot applications can be done using DRL, such as walking, running, jumping, and even backflipping.

Here is a curated list of applications of DRL in robotics:

  • Legged robots: DRL trains the legged robot to walk, run, climb stairs, and balance on any terrain. Training helps the robot adapt to uneven terrain and recover from failure.
  • Humanoids: Humanoids are very complex robots with many joints and degrees of freedom, which makes them difficult to control using classic rule-based methods such as finite state machines or PID controllers. They are a special form of a legged robot. Using DRL, they can learn to walk, run, and jump, adapting to new terrains and recovering from failure. They can also manipulate and grasp different objects using vision.
  • Robotic manipulation: As we saw with humanoids, using independent robotic arms, tasks like pick-and-place, the assembly of parts, and the handling of different tools can be accomplished using DRL. For example, a robotic arm with a gripper grasps a Rubik’s cube and learns how to solve it.
  • Autonomous navigation: Using DRL, we can train mobile robots to perform obstacle avoidance, path planning, and exploration autonomously.

In the next section, we will look at some of the popular DRL algorithms that are used in the above application.

In this section, we will look at different classifications of DRL algorithms. We will go through each method and example.

The algorithms estimate a value from actions or states to help the agent’s decision-making process. The agent chooses different actions based on the value assigned to the state or the actions. These values are updated to improve the agent’s decision-making.

An example of a value-based method is DQN. It combines Q-learning with a deep neural network. It estimates the Q-values (action-value function) for each state-action pair and chooses the action that maximizes the Q-value.

A policy is a mapping from the agent’s state to its action. Policy-based methods try to optimize the policy rather than estimate the value function. These methods are gradient-based methods to update the policy.

An example of a policy-based method is PPO (Proximal Policy Optimization). PPO is a policy gradient method that teaches the policy function. It is simple, effective, and stable and works well in environments with both discrete and continuous action spaces.

These methods combine value-based and policy-based approaches. They use two main networks: one is called the actor, which determines the best action to take, and the other is called the critic, which determines how good the selected action is by estimating the value of the state or the state-action pair. In short, the actor uses the feedback from the critic to improve the policy over time, allowing efficient learning.

A couple of examples of these methods are the DDPG (Deep Deterministic Policy Gradient) [4] and the TD3 (Twin Delayed Deep Deterministic Policy Gradient) [5].

DDPG is an action-critic method intended for continuous action spaces. The actor network suggests an action, and the critic network evaluates the action by computing Q-values.

TD3 is an improvement on the DDPG that reduces the overestimation bias in the value function and stabilizes training. TD3 is more stable and performs better in complex continuous control tasks.

In the next section, we will see how we can set up an RL framework in Ubuntu 24.04 LTS for training, testing, and deployment.

Setting up Isaac Lab and Isaac Sim in Ubuntu 24.04

Section titled “Setting up Isaac Lab and Isaac Sim in Ubuntu 24.04”

In this section, we will discuss installing RL frameworks like NVIDIA Isaac Lab and Isaac Sim in Ubuntu 24.04 using Docker. Before setting this up, let’s look at the basics of these two frameworks.

Isaac Sim and Isaac Lab are interconnected software developed by NVIDIA for robot simulation and robot learning.

Isaac Sim [6] is a high-fidelity simulator compared to Gazebo, which we saw in an earlier chapter. It is built on the NVIDIA Omniverse platform [7], and it provides photorealistic rendering and precise physics simulations. The simulator supports many robots, such as robotic arms and wheeled, legged, and humanoid robots. It also supports many sensors, like LIDAR, depth cameras, etc.

Figure 15.3 shows the Isaac Sim UI with multiple robots in the simulation.

Figure 15.3: NVIDIA Isaac Sim

Figure 15.3: NVIDIA Isaac Sim

The simulator also supports various robotics applications, such as SLAM (Simultaneous Localization and Mapping), motion planning, and hardware-in-loop testing. It is integrated into ROS 1 and ROS 2, and we can easily integrate it with Nav 2 or MoveIt2, as we have done with Gazebo Sim.

Isaac Lab [8] is a GPU-accelerated, open-source modular framework for robot learning built on top of Isaac Sim. This framework simplifies the development of robot learning applications, such as reinforcement learning and imitation learning, by providing an integrated environment, eliminating the need to implement algorithms from scratch.

Figure 15.4 shows an Isaac Lab training environment in Isaac Sim.

Figure 15.4: Sample NVIDIA Isaac Lab humanoid training environment in Isaac Sim

Figure 15.4: Sample NVIDIA Isaac Lab humanoid training environment in Isaac Sim

The framework provides rich APIs and examples to design and test customized robot learning environments and algorithms using Isaac Sim’s capabilities. Isaac Lab also includes example robot learning environments for training and testing different learning algorithms. It interfaces standard learning libraries and offers better data collection and training tools. Isaac Lab offers features to train multiple instances of robots in the same environment in parallel with the help of a GPU. This will drastically reduce the training time. Isaac Sim and Isaac Lab provide a foundational simulation environment, APIs, and tools for advanced robotics learning and research.

Figure 15.5 shows the block diagram of Isaac Lab. You can see Isaac Lab is built on top of NVIDIA Isaac Sim.

Figure 15.5: Block diagram of Isaac Lab (source: https://isaac-sim.github.io)

Figure 15.5: Block diagram of Isaac Lab (source: https://isaac-sim.github.io)

Isaac Sim is built on the Omniverse platform. Isaac Lab has many submodules for performing different learning algorithms, such as reinforcement learning and imitation learning. Modules like sensors, actuators, controllers, and the environment help the developer to create the robot’s learning environment.

In the next section, we will see how to set up software in Ubuntu 24.04 LTS using Docker.

Installing Isaac Sim and Isaac Lab in Ubuntu 24.04

Section titled “Installing Isaac Sim and Isaac Lab in Ubuntu 24.04”

To set up Isaac Sim and Isaac Lab in Ubuntu 24.04, your PC/laptop should meet the technical requirements mentioned in the chapter. An NVIDIA RTX 40xx with >8 GB VRAM is recommended for good performance. It will also work with 6 GB VRAM. This software will only work if the developer has an RTX NVIDIA graphics card or higher in the system.

After meeting the system specification, make sure you have installed the NVIDIA driver and confirm it is properly working.

Setting up Docker and the NVIDIA Container Toolkit

Section titled “Setting up Docker and the NVIDIA Container Toolkit”

Once the system specification is checked, the next step is to install Docker with the NVIDIA Container Toolkit. Ignore this step if you have already installed Docker and the NVIDIA Container Toolkit in your system. Otherwise, go to the Chapter15/docker_setup_scripts folder, and you will find an installation script called setup_docker_ubuntu.sh. Run the script and it will automatically install Docker and the NVIDIA Container Toolkit. Make sure there is internet connectivity in your system.

Here is the command to execute the script:

./setup_docker_ubuntu.sh

After installing Docker and the NVIDIA Container Toolkit, let’s set up Isaac Sim and Isaac Lab.

The first step is to clone the Isaac Lab repository. This repository has the Dockerfiles and scripts to build the Docker image and start/stop the Docker container.

Here is the command to clone the Isaac Lab repository in the home folder:

cd $HOME
git clone https://github.com/isaac-sim/IsaacLab.git

After cloning the repository, switch to the IsaacLab folder:

cd IsaacLab

Execute the following command to start building the Isaac Lab image:

./docker/container.py start ros2

There are two options for creating the image: 'base' and 'ros2'. Since the base doesn’t have ros2 installed in the image, we have to use ros2 while building the image and starting the container.

The container.py is the Python script that helps build the image and start the container. This command can take around 5 to 10 minutes to finish based on your internet speed. When you start the script, it will ask whether you want to enable X11 forwarding. As, without this, we will not be able to visualize any GUI applications running inside the container on our host system, we will have to enable this by pressing ‘1’.”. If you can’t enter this, you can change the value in the file docker/.container.cfg. Change X11_FORWARDING_ENABLED to 1.

After building the Docker image, the script will start the container. If we execute the command again, the time taken to start the container will be shorter because the Docker image has already been built. When you reboot your PC or laptop, you have to execute the above command once. You only need to do this once after each reboot.

After completing this command, you can access the terminal session of the running container by using the following command:

./docker/container.py enter ros2

We can use the above command to start any number of terminals. Here is the command to stop the container. It is not required most of the time, but you can use it if you manually stop the container and start it again:

./docker/container.py stop ros2

You can find the detailed Docker setup instructions for Isaac Lab and Isaac Sim at this link [9].

After setting up Isaac Lab and Sim in Docker, we will see how to train, test, and deploy RL models using these.

Training and testing robots using Isaac Lab

Section titled “Training and testing robots using Isaac Lab”

In this section, we will briefly discuss the learning process with Isaac Sim and Isaac Lab.

Figure 15.6 shows the architecture of the model’s training and deployment and highlights its major building blocks.

Figure 15.6: Isaac Lab architecture (source: https://isaac-sim.github.io/)

Figure 15.6: Isaac Lab architecture (source: https://isaac-sim.github.io/)

Here are the major components of training and testing using Isaac Lab and Isaac Sim:

  • Asset Input: Isaac Sim and Isaac Lab use Universal Scene Description (USD) [10] as a file format for representing 3D robots and environments. In ROS 2, we used URDF/xacro for the robot model. Isaac Sim offers conversion tools to USD from URDF, MJCF, XML, etc. Importing robot and environment assets into Isaac Lab is the first step in the workflow.
  • Creating Configuration: After creating the assets as input, we have to create 2 configuration classes in Python:
    • Asset Configuration: In this class, we can define all the properties of each asset. A list of examples of asset configuration can be found in the IsaacLab/source/isaaclab_assets/isaaclab_assets/robots folder.
      • Scene Configuration: After completing the asset configuration, the next step is to put the individual assets together in the scene. The scene configuration is a Python class that initializes all the assets in the scene needed for the learning task and visualization. An example script can be found in IsaacLab/source/isaaclab_tasks/isaaclab_tasks/manager_based/manipulation/reach/reach_env_cfg.py.
  • Robot Learning Task Design: After creating the configuration class, we have to define the robot learning task. We have to define the RL task that the agent is going to do. There are two ways to design the environment for the robot learning task:
    • Manager-based: This method uses modular components (managers) to handle various aspects of the environment, such as observation and action. In this method, we have to write different configuration classes for an RL task, such as Observation Config (define the agent’s observation for the task), Action Config (define the agent’s action type), Reward Config (define the reward function for the task), and Termination Config (define the conditions for termination).
      • Direct: In this approach, there is a unified class to manage observation, actions, and rewards directly. Examples of learning tasks can be found in the IsaacLab/source/isaaclab_tasks/isaaclab_tasks folder.
  • Register with Gymnasium: After the robot task design, we can register the learning environment with the Gymnasium [11] registry. Gymnasium is a standard library for working with RL with a large collection of reference environments. Once our environment is registered with a unique name, we can access and reuse it with different RL algorithms and experiments.
  • Environment Wrapping: We may have to reuse the existing environment and change its behavior without modifying the actual environment itself. When interfacing multiple RL libraries, the data type needed by each library differs. To do this, Isaac Lab provides a wrapper API that can modify the behavior. This is an important feature of Isaac Lab because we can create a variation of an environment without touching the actual environment.
  • Run Training: Now, the final step is running the training. Isaac Lab is integrated with multiple RL libraries, like RSL-RL [12] and SKRL [13]. All these RL integration libraries use GPU-based training. Isaac Lab provides scripts to run training using different libraries. It also facilitates single-GPU and multi-GPU training. We can also configure the training using cloud infrastructure.
  • Run Testing: After training, we can evaluate the trained model within a simulated environment to benchmark its performance before deploying it to the actual robot.

The complete reference for training and testing using Isaac Lab is mentioned at the link [14].

In the next section, we will work with some sample RL training environments that are available in Isaac Lab.

Training and testing an existing RL environment in Isaac Lab

Section titled “Training and testing an existing RL environment in Isaac Lab”

In this section, we will learn how to train and test an RL task using demo scripts provided by Isaac Lab. Before starting the training, we will check the list of RL environments shipped by Isaac Lab using the following command.

In the Isaac Lab Docker container terminal, we can enter the following command to list out the existing environments:

./isaaclab.sh -p scripts/environments/list_envs.py

This command will show the registered RL environments that are available in Isaac Lab. You will find different variations of the same environment in the list. We can refer to this list to find the environment we want and do the training and testing. You can find the details of these environments at the following link [15]. If you want to check the robot assets in Isaac Lab, you can go to the IsaacLab/source/isaaclab_assets/isaaclab_assets/ folder and find the robot and sensor folders. We can add robots and sensors to the same folder in the same format. After adding a new asset, make sure you have updated the init.py file to include the new robot or sensor. To check the source code of the available training task, you can check the IsaacLab/source/isaaclab_tasks/isaaclab_tasks folder. Inside the folder, you can find the task design folders, such as the direct and manager folders. Inside each folder, you can find different categories of robot learning tasks.

Let’s start with the training of the sample RL environment.

In this section, we will see how to train a UR-10 robot to move the end-effector to a different target pose. Basically, this RL task tries to train the RL model to learn the IK (Inverse Kinematics) solution for this robot.

We use the RSL-RL library to train the robot, so the first step is to install the rsl-rl Python module inside the container. It may not be installed by default.

You can use the following command to install the latest version:

./isaaclab.sh -i rsl_rl

The isaaclab.sh is the main script provided by Isaac Lab to install modules and run scripts for training and testing the RL environment. By executing the following command, we will get the full command-line arguments of this script:

./isaaclab.sh -h

After installing the rsl_rl library, we can start using the training script.

Isaac Lab has a demo training script for rsl_rl. We can use the script train.py, which is placed in the script/reinforcement_learning/rsl_rl folder. This script can start training based on the configuration if we mention the environment name as an argument. The following command can be used to train multiple environments using the rsl_rl module:

./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/train.py --task Isaac-Reach-UR10-v0 --headless

In the above command, we use the rsl_rl library in Isaac Lab for training the robot task. The rsl_rl library has the PPO algorithm as the default for RL training. If you check the command, we enabled headless mode in training, meaning the visualization will be disabled, and Isaac Sim will not show the visualization of the training. The headless mode can save on the computation and memory that Isaac Sim consumes. It is better to do training by disabling the visualization of Isaac Sim. If you remove the headless, you can see the training in Isaac Sim. The typical time to complete this training is around 5 to 10 minutes if you have a modern NVIDIA RTX graphics card.

Figure 15.7 shows a screenshot of the terminal during training.

Figure 15.7: Training of Isaac Lab-based environment

Figure 15.7: Training of Isaac Lab-based environment

Here are the essential values we have to understand from the training logs:

  • Learning Iteration: This refers to a cycle in the process of training an agent. It represents an update to the agent’s knowledge based on its interaction with the environment. We can configure the maximum value of learning iteration. For some tasks, the agent can learn with a smaller number of iterations, but it depends on many parameters of the learning task.
  • Computation: This indicates the number of steps processed per second, including data collection and learning phases.
  • Mean Reward: This is the average reward obtained by the agent in the current iteration. A negative reward means the agent is still learning and has not yet optimized behaviors.
  • ETA: The estimated time of arrival is the remaining time to complete the whole training based on the current progress.

After completing the training, you can find the trained model in the /workspace/isaaclab/logs folder, which is inside the container. Based on the library we have trained on, you can find the folder name as the library name, and inside that folder, you can find sub-folders of the training files. The main files you can find in these folders are the PyTorch models (.pt) files. You will see different .pt files during different iterations. We can use these models for testing and deployment, which is discussed in the next section.

In this section, we will see how to test or validate the trained RL model. The following command can be used to test the UR-10 robot with the pre-trained model:

./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/play.py --task Isaac-Reach-UR10-v0 --num_envs 32 --use_pretrained_checkpoint

The play.py script is a demo script from Isaac Lab to load and test the model with Isaac Sim. The num_envs indicates the test will run on 32 parallel environments. The pretrained_ checkpoint flag loads the final trained model from the logs folder. If we want to load a model specifically, we can use the following command:

./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/play.py --task Isaac-Reach-UR10-v0 --num_envs 32 --load_run run_folder_name --checkpoint model.pt

In this command, we are specifying the model.pt, which is the model to load for testing. Make sure you have copied the right model to the default path of the container before executing this command. You can change the name of the model in the command as well. Figure 15.8 shows the testing of the UR-10 reaching task. You can find 32 environments of the same arm doing the testing in parallel.

Figure 15.8: Testing UR-10 Isaac Lab environment

Figure 15.8: Testing UR-10 Isaac Lab environment

In the reaching task, the robot end-effector will move to the random goal position commander from Isaac Lab. The goal position will change once the robot reaches that position.

Next, let’s look at another demo of the navigation of a legged robot called ANYmal using Isaac Lab.

Training and testing ANYmal robot navigation

Section titled “Training and testing ANYmal robot navigation”

In this section, we will explore the ANYmal robot’s navigation being trained and tested. The command to train on the task is given below. The task here is for the ANYmal robot to try to navigate to a random goal position in the environment.

./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/train.py --task Isaac-Navigation-Flat-Anymal-C-v0 --headless

The training time depends on the complexity of the RL environment and the graphics card we are using. For example, to complete the above training on a modern RTX 4060 GPU with 8 GB of VRAM, it will take around 45 min to 1 hr. After training, you can use the following command to test it. We will use pre-trained checkpoints to test the model:

./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/play.py --task Isaac-Navigation-Flat-Anymal-C-v0 --num_envs 32 --use_pretrained_checkpoint

Figure 15.9 shows the testing visualization of the ANYmal robot in Isaac Sim. There are two green arrows per robot. The arrow in the robot shows its pose, and the arrow outside each robot shows its goal position.

Figure 15.9: Testing AnyMal Isaac Lab environment

Figure 15.9: Testing AnyMal Isaac Lab environment

When we start testing, 32 robot environments will be spawned in Isaac Sim and start working. Each robot tries to reach the goal position, which will randomly change to a new position once the robot reaches it.

Let’s now see another demo of training and testing a humanoid robot using Isaac Lab.

Training and testing of an H1 robot for a locomotion task

Section titled “Training and testing of an H1 robot for a locomotion task”

In this section, we will see how to train a humanoid robot called an H1 robot from Unitree [16]. The following task will teach the robot to walk on rough terrain by giving a velocity command.

Here is the command to train the humanoid robot:

./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/train.py --task Isaac-Velocity-Rough-H1-v0 –headless

It will take more than 1 hour of training if you are using any RTX 40xx graphics card.

After training, we can start testing the trained model using the following command:

./isaaclab.sh -p scripts/reinforcement_learning/rsl_rl/play.py --task Isaac-Velocity-Rough-H1-v0 --num_envs 32 --use_pretrained_checkpoint

Here is the screenshot of Isaac Sim showing the humanoid robot moving in rough terrain:

Figure 15.10: Testing H1-robot in Isaac Lab environment

Figure 15.10: Testing H1-robot in Isaac Lab environment

Here is the reference link for training and testing different RL environments in Isaac Lab [17].

Deploying a trained RL model to a real robot

Section titled “Deploying a trained RL model to a real robot”

After training and testing the robot in simulation, the final task is to deploy the trained model in the actual robot. There are different ways to do this. One of the sample references from the Isaac Lab website is shown in Figure 15.11. The robot should have a powerful computer, like an NVIDIA Jetson board, to interface sensors and run the model on it.

Figure 15.11: Reference diagram of interfacing an RL model to a real robot (source: https://isaac-sim.github.io/)

Figure 15.11: Reference diagram of interfacing an RL model to a real robot (source: https://isaac-sim.github.io/)

The important section of code we have to configure is a state estimator. This is the block delivering the list of observations used for training. Instead of using simulated sensor observations, we are providing real robot observations here. We can use ROS 2 drivers or Isaac ROS packages to get observations from robot sensors. Once the observations are extracted, they will pass into the model inference runtime, which generates the action. The commanded action will be the new set point for the action controller. The action controller output will be scaled, and then it will be used to control the robot to get the next state of the robot. This loop will continue until the task is done.

Note

The sim-to-real transfer is not easy to implement because of the limitation of collecting real-world data. Mostly, a simulation environment is used to gather data and train RL agents. The performance can degrade when we transfer to a real robot with real-world data. Multiple research efforts are happening to reduce the sim-to-real transfer gap. Here is a reference to a research paper showing different approaches to sim-to-real transfer [20].

In the next section, we will see a real example of the hardware interfacing of an RL model trained in Isaac Lab.

Deploying an RL model in the Spot robot from Boston Dynamics

Section titled “Deploying an RL model in the Spot robot from Boston Dynamics”

In this section, we will see a sample project that trains, tests, and deploys an RL model in Boston Dynamics’ Spot robot. Figure 15.12 shows the training pipeline using Isaac Lab and Isaac Sim.

Figure 15.12: Training of Spot robot in simulation for locomotion (source: https://developer.nvidia.com/)

Figure 15.12: Training of Spot robot in simulation for locomotion (source: https://developer.nvidia.com/)

The task they are trying to do is robot locomotion. If we give the velocity command, the robot should move based on it.

After training on the locomotion task in Isaac Sim, Figure 15.13 shows the testing and deployment of the model on actual hardware.

Figure 15.13: Testing of the trained model on actual Spot robot (source: https://developer.nvidia.com/)

They used Jetson Orin as the computer and read the sensor state using their APIs. We can also use ROS 2 or Isaac ROS to get the robot’s sensor state. The command to the robot is the velocity command from the user using a joystick. The actions from the RL model are sent to the real robot using Boston Dynamics’ joint-level API. We can also use the ROS 2 controller to control the joint values for the robot.

Here is the GitHub repository for the Spot robot’s RL project [18]. A detailed explanation of this project can be found at this link [19].

Here is another sim-to-real project using a manipulator called Kinova Gen3. The training is done using Isaac Lab, and sim-to-real deployment using ROS 2 [21].

This chapter explored the integration of ROS 2 with DRL, focusing on NVIDIA Isaac Lab and Isaac Sim. It began by explaining reinforcement learning basics, where agents learn through interaction with environments to maximize rewards. The chapter then introduced Isaac Lab, a framework built on the Isaac Sim simulator for training robot policies. Key sections covered setting up Isaac Lab in Ubuntu 24.04 using Docker, the architecture of the training process, and practical examples of training different robots like the UR-10 robotic arm, AnyMal quadruped, and H1 humanoid robot. The training process involves configuring assets, designing learning tasks, registering with Gymnasium, and running training using GPU-accelerated algorithms.

Finally, the chapter discussed how to deploy trained models to real robots using ROS 2, with a case study of deploying a locomotion model to Boston Dynamics’ Spot robot. Throughout, the text emphasized the workflow from simulation training to real-world deployment of DRL models for robotic applications.

In this next chapter, we will discuss how to implement the ROS 2 visualization plugin for Rviz and the simulation plugins for Gazebo Sim.