EP2 - Setting Up Your Network for ROS
Video: https://youtu.be/NW97xLF7CYQ
#Robotics #Hardware #ROS #Linux #NetworksRead more here
Table of Contents:
Introduction: Setting Up Networking for ROS
One of the great things about ROS is that it makes networking super easy.
Today, we’re going to cover what you need to do to get your network set up for ROS.
In this series, we’ve been discussing the essential steps to get started with building robots using ROS.
Last time, we installed our computers,
and now we’re going to set up the network.
Why Networking is Important for Robots
When building a robot, networking is essential for tasks such as remote control, enabling robots to work together, or splitting computations across different devices.
However, writing network code can be difficult.
Fortunately, ROS simplifies this process. All we need to do is ensure that our devices are on the same network.
What We’ll Cover in This Video
In this video, we’ll look at:
- Different network structures
- How to configure your network using Netplan
- Setting up remote access
- ROS-specific networking settings
There’s a lot to cover, so let’s get started!
Key Network Requirements
When structuring your network, there are three key things it needs to do:
- Fast, reliable connections between devices to send ROS messages.
- Internet access to install ROS packages.
- Control over the network to set up things like static IP addresses.
Network Structure Options
Option 1: Using an Existing Network
The simplest structure is to use your home, school, or workplace network. For many people, this will be good enough.
However, consider potential issues:
- Limited control over the network, which may cause IP conflicts or poor reception.
- Fixed location, making it difficult to move the setup for tests or demos.
- ROS conflicts if others are using ROS on the same network.
If these issues seem likely, consider the next option.
Option 2: Ad-Hoc or Access Point Network
In this setup, one device (typically the base station) broadcasts its own Wi-Fi network,
and other devices (like the robot) connect to it.
To access the internet, a second network interface (such as Ethernet or another Wi-Fi card) is used to share the connection.
This method offers flexibility, but can be tricky to configure, requiring an Ethernet connection or a second Wi-Fi card.
Option 3: Dedicated Network with a Travel Router
I suggest option number three, a dedicated network.
Having a dedicated router gives us a solid network for all our devices to connect to that we have complete control over, the only problem is that this brand new network won't have an internet connection....
Thankfully there's a handy piece of equipment out there to solve this problem and that's called a [[travel router]].
A [[travel router]] creates a private network for your devices and can connect to the internet via Ethernet, Wi-Fi, or USB tethering. It shares that connection to its own network.
This setup provides complete control over your network while offering internet access when needed. I highly recommend it for how much it simplifies things.
Configuring Your Network with Netplan
Now that we’ve picked a network structure, it’s time to configure it on our devices.
While you might be tempted to use the built-in network manager, I recommend using Netplan, a built-in tool for managing network settings via a config file. This makes it easy to edit, back up, or share network settings between computers.
Note: [[Netplan]] doesn't actually handle any of the networking itself, all it does is provide a way to read a config file and translate that into a form that your operating system knows how to use.
So I'm going to walk us through how I set up these two machines using Netplan.
Steps to Set Up Netplan
-
Determine Network Settings: Decide on your own the network interface name, IP addresses, subnet, gateway, DNS, and Wi-Fi login information.
-
Find Network Interface Name: Open a terminal and run
ip addr
to identify your Ethernet (starts with "e") and Wi-Fi (starts with "w") interfaces.
You’ll need to configure the remaining settings on your own.
For example,
- I’ve already determined the IP address of the router, which will serve as my gateway and name server.
- I’ve also selected static IP addresses for devices outside the router's DHCP range,
- and I have the Wi-Fi login information, which is currently set to the default (though you may want to change it).
Now that we’ve decided on the necessary settings, we can move forward with writing the configuration file
- Create a Configuration File: Netplan looks for config files in
/etc/netplan
. There is already and empty file there,
You can create a new file with this name,
it requires root access, so we can create the file like this: sudo pluma /etc/netplan/02-my-network-config.yaml
- Write Configuration: Enter your settings, including IP addresses and network information. Be mindful of indentation since YAML files are sensitive to formatting.
These are the contents of the file:
- Apply Settings: Run
sudo netplan generate
andsudo netplan apply
to activate your network settings.
Verify that the Network works,
Note: one little thing to be aware of if you're using wi-fi you might have to delete the old network manually. To do this you'll have to go up to the start menu and go to advanced network configuration,
Setting Up Remote Access with SSH
Once your network is set up, the next step is to configure remote access, particularly for devices like the Pi that won’t always have a screen and keyboard attached.
SSH (Secure Shell) allows you to open a terminal remotely on another machine over the network.
SSH also enables additional features like file:
- transfers using SCP,
- running graphical applications remotely with X forwarding,
- and integrating with VS Code’s Remote Development extension.
- Install SSH: On each machine, run:
sudo apt install openssh-server
- Test SSH: From the dev machine, run:
ssh pi-username@pi-address
ROS-Specific Networking Settings
In ROS1, multiple machines communicating over the network required setting an environment variable. Thankfully, ROS2 simplifies this—everything works out of the box. The only time you need to change the settings is when you have multiple ROS networks on the same LAN (e.g., in a classroom). If that applies to you, check out the links in the description for more details.
Conclusion: Network is Ready, Let’s Install ROS
Now that our network is fully set up, we’re ready to install ROS.
See you next time!
Z) 🗃️ Glossary
File | Definition |
---|