You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/04.pro/boards/portenta-x8/tutorials/16.getting-started-with-ros2/content.md
+35-31Lines changed: 35 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
---
2
-
title: '16. Getting Started with ROS2 and Turtlesim on Portenta X8'
2
+
title: '16. Getting Started with ROS 2 and Turtlesim on Portenta X8'
3
3
difficulty: intermediate
4
-
description: "Learn how to set up and run ROS2 with turtlesim visualization on Portenta X8 using an external display via USB-C® to HDMI."
4
+
description: "Learn how to set up and run ROS 2 with turtlesim visualization on Portenta X8 using an external display via USB-C® to HDMI."
5
5
tags:
6
-
- ROS2
6
+
- ROS 2
7
7
- Docker
8
8
- Linux
9
9
- Wayland
@@ -15,18 +15,18 @@ hardware:
15
15
16
16
## Overview
17
17
18
-
In this tutorial, you will learn to set up and run **ROS2 (Robot Operating System 2)** with the **`turtlesim`** visualization tool on the Portenta X8. You will learn to display the graphical output on an external monitor connected via a USB-C® dongle with HDMI output.
18
+
In this tutorial, you will learn to set up and run **ROS 2 (Robot Operating System 2)** with the **`turtlesim`** visualization tool on the Portenta X8. You will learn to display the graphical output on an external monitor connected via a USB-C® dongle with HDMI output.
19
19
20
-

20
+

21
21
22
-
We will explore two approaches: running ROS2 directly through commands and deploying it in a containerized environment using Docker. The **`turtlesim`** application is an excellent introduction to ROS2, providing a simple way to understand ROS2 concepts like nodes, topics and services through an interactive turtle graphics simulation.
22
+
We will explore two approaches: running ROS 2 directly through commands and deploying it in a containerized environment using Docker. The **`turtlesim`** application is an excellent introduction to ROS 2, providing a simple way to understand ROS 2 concepts like nodes, topics and services through an interactive turtle graphics simulation.
23
23
24
24
## Goals
25
25
26
26
- Learn how to connect and configure an external display with the Portenta X8
27
27
- Understand the Wayland display server configuration on the Portenta X8
28
-
- Run ROS2 and turtlesim using direct commands
29
-
- Deploy ROS2 and turtlesim in a Docker container
28
+
- Run ROS 2 and turtlesim using direct commands
29
+
- Deploy ROS 2 and turtlesim in a Docker container
30
30
31
31
## Hardware and Software Requirements
32
32
@@ -58,7 +58,7 @@ To check your Portenta X8 Linux version and update if necessary, refer to the [P
58
58
59
59
### Video Output Setup
60
60
61
-
To display ROS2`turtlesim` on an external monitor, you will need a USB-C® hub with video output capabilities. The Portenta X8 serves as the host device, is connected to the hub, and provides the necessary ports for display connectivity and optional peripherals.
61
+
To display ROS 2`turtlesim` on an external monitor, you will need a USB-C® hub with video output capabilities. The Portenta X8 serves as the host device, is connected to the hub, and provides the necessary ports for display connectivity and optional peripherals.
62
62
63
63
Connect the Portenta X8 to the USB-C® hub's host port, then connect your HDMI cable to your external display. The hub's power supply can be connected to your computer or a dedicated power adapter. You can connect a USB mouse and keyboard to the hub's additional ports for interactive system control. This is optional for the `turtlesim` example.
64
64
@@ -72,7 +72,7 @@ When you first connect the Portenta X8 to your display, you will see the default
72
72
73
73

74
74
75
-
The Portenta X8 uses **Weston** as its **Wayland** compositor, which automatically detects and configures external displays. You can interact with the interface directly if you have connected a mouse or keyboard to your USB hub. However, we will mostly work through terminal commands and use Docker configuration files for the present ROS2`turtlesim` tutorial.
75
+
The Portenta X8 uses **Weston** as its **Wayland** compositor, which automatically detects and configures external displays. You can interact with the interface directly if you have connected a mouse or keyboard to your USB hub. However, we will mostly work through terminal commands and use Docker configuration files for the present ROS 2`turtlesim` tutorial.
76
76
77
77
### Adjusting Display Resolution (Optional)
78
78
@@ -82,11 +82,11 @@ For example, to configure a display for `1600 x 758` resolution at `60 Hz`, you
82
82
83
83
***For detailed instructions on connecting to your Portenta X8 via ADB, refer to the [Working with Linux section](https://docs.arduino.cc/tutorials/portenta-x8/user-manual#working-with-linux) of the user manual. Additional information about display configuration and WebGL capabilities can be found in the [Display Output tutorial](https://docs.arduino.cc/tutorials/portenta-x8/display-output-webgl/).***
84
84
85
-
Once your display is properly connected and configured, you are ready to proceed with running ROS2 and visualizing the `turtlesim` application on your external monitor.
85
+
Once your display is properly connected and configured, you are ready to proceed with running ROS 2 and visualizing the `turtlesim` application on your external monitor.
86
86
87
87
## What Is ROS
88
88
89
-
**ROS (Robot Operating System)** is an open-source middleware framework that enables robotic and embedded systems to exchange data through standardized **nodes**, **topics**, **services** and **actions**. It provides reusable libraries and tools, such as visualization, package management and message passing, so developers can focus on application logic instead of low-level infrastructure.
89
+
**ROS (Robot Operating System)** is an open-source middleware framework that enables robotic and embedded systems to exchange data through standardized **nodes**, **topics**, **services** and **actions**. ROS is a trademark of Open Source Robotics Foundation. It provides reusable libraries and tools, such as visualization, package management and message passing, so developers can focus on application logic instead of low-level infrastructure.
90
90
91
91
### What Is ROS 2
92
92
@@ -100,7 +100,7 @@ Once your display is properly connected and configured, you are ready to proceed
100
100
101
101
Throughout this tutorial, we use [**ROS 2 Jazzy**](https://docs.ros.org/en/jazzy/index.html) on the Portenta X8, allowing you to leverage these newer capabilities while still relying on familiar ROS concepts.
102
102
103
-

103
+

104
104
105
105
## Wayland Display Configuration
106
106
@@ -141,11 +141,11 @@ This command would return something as follows:
To run ROS2 and `turtlesim` directly on the Portenta X8, we will use Docker containers to ensure a consistent environment. This approach lets us quickly test ROS2 functionality without creating a permanent installation.
148
+
To run ROS 2 and `turtlesim` directly on the Portenta X8, we will use Docker containers to ensure a consistent environment. This approach lets us quickly test ROS 2 functionality without creating a permanent installation.
149
149
150
150
First, we need to configure the environment variables that will allow our Docker container to communicate with the Wayland display server. The `Wayland` protocol requires specific environment variables to establish the connection between the containerized application and the display server running on the host system:
These variables tell applications where to find the `Wayland` socket (`wayland-1`), specify the runtime directory where `Wayland` stores its communication files (`/run/user/63`) and tell Qt-based applications like `turtlesim` to use `Wayland` as their display platform.
165
165
166
-
With the environment configured, we can now launch a ROS2 Docker container. The following command creates an interactive container with all the necessary permissions and volume mounts to access the display:
166
+
With the environment configured, we can now launch a ROS 2 Docker container. The following command creates an interactive container with all the necessary permissions and volume mounts to access the display:
167
167
168
168
```bash
169
169
docker run -it --rm \
@@ -184,17 +184,17 @@ This command uses flags like `--privileged` that grant the container elevated pe
184
184
185
185
### Installing and Running Turtlesim
186
186
187
-
You will see a bash prompt once you are inside the Docker container. The container has ROS2 pre-installed, but we need to set up the ROS2 environment and install the turtlesim package.
187
+
You will see a bash prompt once you are inside the Docker container. The container has ROS 2 pre-installed, but we need to set up the ROS 2 environment and install the turtlesim package.
188
188
189
-
Start by sourcing the ROS2 setup script, which configures all the necessary ROS2 environment variables and paths:
189
+
Start by sourcing the ROS 2 setup script, which configures all the necessary ROS 2 environment variables and paths:
190
190
191
191
```bash
192
192
source /opt/ros/jazzy/setup.bash
193
193
```
194
194
195
-
This command initializes the ROS2 workspace, making all ROS2 commands and tools available in your current shell session. Without this step, ROS2 commands won't be recognized.
195
+
This command initializes the ROS 2 workspace, making all ROS 2 commands and tools available in your current shell session. Without this step, ROS 2 commands won't be recognized.
196
196
197
-
Next, install the `turtlesim` package, which is not included in the base ROS2 image. Update the package list and install `turtlesim`:
197
+
Next, install the `turtlesim` package, which is not included in the base ROS 2 image. Update the package list and install `turtlesim`:
@@ -249,15 +249,15 @@ Open a new terminal on your Portenta X8 and access the running Docker container
249
249
docker exec -it ros2_wayland_test bash
250
250
```
251
251
252
-
This command opens a new bash session inside the running container named `ros2_wayland_test`. You will need to source the ROS2 environment again in this new session:
252
+
This command opens a new bash session inside the running container named `ros2_wayland_test`. You will need to source the ROS 2 environment again in this new session:
253
253
254
254
```bash
255
255
source /opt/ros/jazzy/setup.bash
256
256
```
257
257
258
258

259
259
260
-
Now, you can control the turtle using ROS2 topics. The `turtlesim` node subscribes to velocity commands on the `/turtle1/cmd_vel` topic. You have different options for controlling the turtle's movement.
260
+
Now, you can control the turtle using ROS 2 topics. The `turtlesim` node subscribes to velocity commands on the `/turtle1/cmd_vel` topic. You have different options for controlling the turtle's movement.
261
261
262
262
For continuous circular movement, publish velocity commands that combine linear and angular velocities:
263
263
@@ -288,15 +288,15 @@ The `draw_square` node will reset the turtle to its starting position and then c
288
288
289
289
### Overview of the Dockerized Approach
290
290
291
-
While running ROS2 directly through Docker commands is useful for testing and development, a dockerized deployment using Docker Compose can provide integration for persistent applications. This method automates the entire setup process, ensures consistent behavior across restarts, and makes managing the ROS2`turtlesim` application as a service easy.
291
+
While running ROS 2 directly through Docker commands is useful for testing and development, a dockerized deployment using Docker Compose can provide integration for persistent applications. This method automates the entire setup process, ensures consistent behavior across restarts, and makes managing the ROS 2`turtlesim` application as a service easy.
292
292
293
293
The dockerized approach includes all dependencies, configurations and startup procedures in a self-contained environment. This is particularly useful when you want the `turtlesim` example to start automatically on boot or recover from unexpected shutdowns.
294
294
295
295
### Creating the Docker Environment
296
296
297
297
[Here](assets/ros2_turtleNative.zip), you can download the files for dockerized deployment.
298
298
299
-
Within this directory, you will have three essential files that define your dockerized ROS2 application:
299
+
Within this directory, you will have three essential files that define your dockerized ROS 2 application:
300
300
301
301
- Docker Compose configuration
302
302
- Dockerfile
@@ -329,7 +329,7 @@ services:
329
329
330
330
This configuration tells Docker Compose to build a custom image using the Dockerfile in the current directory. It sets up the same privileged access and environment variables we used in the direct method but adds a restart policy (`unless-stopped`) that ensures the container automatically restarts if the system reboots or if the container exits unexpectedly.
331
331
332
-
Next, create the `Dockerfile` that defines how to build your custom ROS2 image with `turtlesim` pre-installed:
332
+
Next, create the `Dockerfile` that defines how to build your custom ROS 2 image with `turtlesim` pre-installed:
This Dockerfile starts from the official ROS2 Jazzy base image for ARM64 architecture, installs the turtlesim package and Python tools, and configures the environment. The key point here is that it copies and sets up a custom startup script as the container's entry point, which handles all initialization and coordination of multiple ROS2 processes.
364
+
This Dockerfile starts from the official ROS 2 Jazzy base image for ARM64 architecture, installs the turtlesim package and Python tools, and configures the environment. The key point here is that it copies and sets up a custom startup script as the container's entry point, which handles all initialization and coordination of multiple ROS 2 processes.
365
365
366
366
The `start_turtlesim.sh` is the main script. This file handles the startup of `turtlesim` with defined movement patterns:
367
367
368
368
```bash
369
369
#!/bin/bash
370
370
set -e
371
371
372
-
# Source ROS2 environment
372
+
# Source ROS 2 environment
373
373
source /opt/ros/jazzy/setup.bash
374
374
375
375
# Set Wayland environment variables
@@ -448,7 +448,7 @@ Here are the Docker configuration and setup files for the turtlesim example, rea
448
448
449
449
### Running the Dockerized Setup
450
450
451
-
With all files in place, you are now ready to build and launch your dockerized ROS2 turtlesim application. The Docker Compose command handles the build and deployment process:
451
+
With all files in place, you are now ready to build and launch your dockerized ROS 2 turtlesim application. The Docker Compose command handles the build and deployment process:
452
452
453
453
```bash
454
454
docker compose up --build
@@ -531,7 +531,7 @@ The turtle will now trace a tighter spiral–square pattern and stay comfortably
531
531
532
532
### Managing the Dockerized Application
533
533
534
-
Docker Compose provides useful commands for managing your deployed application. Understanding these commands helps you maintain and troubleshoot your ROS2 deployment effectively.
534
+
Docker Compose provides useful commands for managing your deployed application. Understanding these commands helps you maintain and troubleshoot your ROS 2 deployment effectively.
535
535
536
536
To monitor the application's output in real time, use the logs command with the following flag:
537
537
@@ -605,16 +605,20 @@ If the container cannot connect to the Wayland display:
605
605
606
606
## Conclusion
607
607
608
-
In this tutorial, you have learned how to set up and run ROS2 with turtlesim visualization on the Portenta X8 using an external display. You have implemented direct command execution and containerized deployment methods, providing flexibility for different use cases.
608
+
In this tutorial, you have learned how to set up and run ROS 2 with turtlesim visualization on the Portenta X8 using an external display. You have implemented direct command execution and containerized deployment methods, providing flexibility for different use cases.
609
609
610
610
The direct method offers quick testing and development capabilities, while the Dockerized approach provides an automated method ideal for controlled deployments.
611
611
612
612
### Next Steps
613
613
614
-
Now that you have ROS2 running on your Portenta X8, you can try different ROS2 packages, create custom nodes, integrate sensor data from the Portenta X8's built-in capabilities with carriers, develop robotics applications using the ROS2 framework, or create custom Docker images with your ROS2 applications.
614
+
Now that you have ROS 2 running on your Portenta X8, you can try different ROS 2 packages, create custom nodes, integrate sensor data from the Portenta X8's built-in capabilities with carriers, develop robotics applications using the ROS 2 framework, or create custom Docker images with your ROS 2 applications.
615
615
616
616
For more information about Portenta X8 capabilities, check out the [Portenta X8 User Manual](https://docs.arduino.cc/tutorials/portenta-x8/user-manual).
617
617
618
+
## Acknowledgments
619
+
620
+
ROS is a trademark of Open Source Robotics Foundation. This tutorial is provided for educational purposes to help users learn ROS 2 on Arduino hardware. This content does not imply endorsement, partnership or affiliation between Arduino and Open Source Robotics Foundation.
621
+
618
622
## Support
619
623
620
624
If you encounter any issues or have questions while working with the Portenta X8, we provide various support resources to help you find answers and solutions.
0 commit comments