ROS network setup between multiple devices and router using DHCP over ethernet cable - brennanyama/RobotOperatingSystem GitHub Wiki

ROS network setup between multiple devices and router using DHCP over ethernet cable

In this walkthrough, we will setup a ROS network between computers connected to a router assigning IPv4 addressing via DHCP over ethernet cable. In this walkthough we discussed how to setup a network using a direction connection between devices by manually setting the IPv4 address on each computer. One advantage of using a router over a direct connection or ethernet switch is the router is able to automatically assign IPv4 addresses to each device intelligently, so the manual configuration of each computer is not necessary.

1. Hardware setup

In this walkthough we have two Ubuntu computers running ROS. The specific ROS distribution does not matter since differing ROS distributions have no problem communicating with each other over a network. We will call the computer we want to use as the ROS Master computer A, and the second computer is called computer B.

Connect computer A and computer B to any LAN port on the back of the router using ethernet cables as shown in this image.

2. Network setup and SSH validation

2.1. Software installation

Install openssh on both computers:

sudo apt-get install openssh-server

Install net_tools on both computers:

sudo apt install net-tools

2.2. Find your MAC address

Find the MAC address of your computer by running:

ifconfig

Typically the first device listed will be associated with your hardware MAC address. This is usually called eth0 or enp1s0, but can be called something else. The MAC address will be of the form xx:xx:xx:xx:xx:xx (each 'x' could be a letter or a number). Make note of the MAC address for both computers.

2.3. Set both computers to DHCP mode

First, ensure that both computer A and computer B are set to DHCP mode; DHCP allows the router to set the IPv4 address of the computer. Computers are typically in DHCP mode by default, but if you have ever set the IPv4 address of your computer manually, then you will need to revert this setting back.

To do this on Ubuntu, navigate to your Ubuntu network settings, click on your wired connection, and open detailed settings of your wired connection.

Click on the `IPv4` tab, the window should look similar to this.
Inside the `IPv4` tab, look for "IPv4 Method", check the box for "Automatic (DHCP)". It should look similar to this.

Click "Apply" or "Save" as appropriate. Ensure that the wired network is enabled. Do this for both computer A and computer B.

2.4. Login and configure router

This step will look very different depending on the router brand and model; in this walkthrough, we use the NETGEAR R6230 router. To log into the router, open an internet browser on any computer and type in the IP address of the router. If the router has never been configured, then the default address http://192.168.1.1. If the router IP address has already been configured, then it will be http://{$ROUTERIPV4ADDRESS}.

The router will then ask you for your username and password. If this is the initial configuration of the router, then you should use the default login credentials given on the user manual of the router. If you changed the username and/or password at any point, enter those.

This is a list of the settings that we will configure in the following steps:

  • Router password (optional, but highly recommended)
  • Router name (optional)
  • Router IP Address (optional, but highly recommended)
  • Add computer DHCP addresses (mandatory)
  • Router Wi-Fi settings (optional)

2.4.1. Change router password (optional, but highly recommended)

Most routers will prompt you to change the login password when you login for the first time. Note that the router password is not the same thing as the Wi-Fi password (the router username and password allows you to login to the router to change its internal settings whereas the Wi-Fi password lets you connect to the router network via Wi-Fi). Change the password to something secure. We recommend printing the username and the password on a label and physically sticking it to the router so the login credentials are never lost.

2.4.2. Change router name (optional)

This step is not mandatory, but it is nice for good book keeping. As your fleet of robot systems grows, you will have a growing list of routers and network devices--giving each one a unique name will help you keep things organized. We recommend printing the unique router name on a label and physically sticking it to the router so you can identify it without needing to power it on and connect to it.

To change your router name on the Netgar R6230, navigate to the "LAN Setup" page and look for the "Device Name" field. It will look like this.

2.4.3. Change router IP address (optional, but highly recommended)

This step is strongly recommended, as keeping the default 192.168.1.1 IP address will get confusing in systems with multiple routers. You can pick any IP address you want; for our robot systems we use 10.10.10.x since it is easy to remember and makes it obvious that this is not intended to be an internet device. We will set this router to 10.10.10.1. We recommend printing the IP address of the router on a label and physically sticking it to the router so you can identify the IP without needing to power it on and connect to it.

To change your router IP address on the Netgar R6230, navigate to the "LAN Setup" page, look for "LAN TCP/IP Setup", and then "IP Address". It will look like this.

Ensure that the router has ample time to process this setting change after clicking "Apply" (this can take a couple of minutes). You will need to reboot the wired connection on your computer after making this change.

2.4.4. Add computer DHCP addresses to router (mandatory)

This is the step where we configure the router to assign specific IP addresses to computers based on their MAC address. This is particularly important for the ROS Master computer, which must always have the same IP address so the other ROS nodes in the network know where the master is located. Other computers/nodes in the network do not necessarily need a specific IP for the ROS network to operate, but it is convenient for debugging issues in the network and good book keeping.

To modify your DHCP address range on the Netgar R6230, navigate to the "LAN Setup" page, look for "User Router as DHCP Server", and then "Starting IP Address" and "Ending IP Address". It will look like this.

Note how the DHCP range is limited between xx.xx.xx.2 to xx.xx.xx.254 for this router (in many network configurations, the router takes the xx.xx.xx.1 slot).

To add a new device with a set IP address on the Netgar R6230, navigate to the "LAN Setup" page, look for "Address Reservation", and then click "Add". This will take you to the "Address Reservation" page where you can add the desired IP address and the MAC address of the computer/device you would like networked. It will look like this.

Note how the router will give you the device name and MAC address of any devices that are currently connected. If the device is not connected, you can get it by running ifconfig on Ubuntu (see section 2.2). Add the desired IP address of the device alongside the MAC address in their respective field. You can also add a custom device name (if you want something different than the default name). Click "Add" when complete.

In our case, we added our ROS Master computer to IP address 10.10.10.10 and the second computer to IP address 10.10.10.11. When you're back on the LAN Setup page, click "Apply" to apply your new settings. Reboot the router as well as the wired LAN connection on all wired computer. Then check that their IP address are appropriately assigned (using ifconfig).

2.4.5. Change router Wi-Fi settings (optional)

If you do not plan on using Wi-Fi, we recommend that you disable the Wi-Fi system of the router, as this could cause interference with other wireless systems onboard your robot. The method to disable Wi-Fi on each router is slighty different, but should be found under Wireless Settings.

The Netgear R6230 router tested in this walkthough has a hardware button on the back of the router to disable Wi-Fi.

2.5. Validate communication between computers using ping and ssh

Computer A is now set to address 10.10.10.10 and computer B is now set to address 10.10.10.11. First, let's test that computer A can ping itself. On computer A enter:

ping 10.10.10.10

This should print successive successful ping messages. This tells us that computer A can correctly communicate with itself at its own IP of 10.10.10.10. Now test that that computer A (IPv4: 10.10.10.10) can ping computer B (IPv4: 10.10.10.11) using:

ping 10.10.10.11

This should also print successive successful ping messages. This tells us that computer A can communicate with computer B over the router. Repeat this process on computer B in reverse to validate bi-directional communication.

Next, test that we can open an SSH session from computer A to computer B. On computer A, enter:

ssh 10.10.10.11

This will attempt to open a SSH connection from computer A (10.10.10.10) to computer B (10.10.10.11). The first time you open an SSH connection between two machines, SSH may ask you if you are sure you want to open the connection; type yes to continue. If the connection succeeds, terminal will prompt you to enter the password for computer B. Doing so should open a SSH connection between the two machines.

You should also repeat this process on computer B (this time using ssh 10.10.10.10).

3.0 ROS Network setup

To summarize, up to this point we have:

  • connected computer A and computer B to a router in DHCP mode at IP address 10.10.10.1
  • configured the DHCP settings of the router to always set computer A to IP address 10.10.10.10 and computer B to IP address 10.10.10.11
  • validated that computer A can ping computer B (and vice versa)
  • validated that computer A can open a SSH connection to computer B (and vice versa)

More details regarding the ROS network requirements and parameters are explained in our first walkthrough for ROS network setup between two devices via ethernet cable, and the ROS Network Setup Tutorial.

To configure computer A and computer B for the ROS network, we want to set ROS_MASTER_URI of both computer A and computer B to the network address of computer A, and we want to set ROS_HOSTNAME to each computers respective IPv4 address (10.10.10.10 for computer A and 10.10.10.11 for computer B).

On computer A, start a new terminal instance and type:

source /opt/ros/{$ROSDISTRO}/setup.bash
export ROS_MASTER_URI=http://10.10.10.10:11311
export ROS_HOSTNAME=10.10.10.10

Replacing {$ROSDISTRO} on the first line with the ROS distribution installed on computer A. These terminal lines must be set for each new terminal instance. Advanced users will recognize that these lines can be added to your ~/.bashrc file for convenience.

On computer B, start a new terminal instance and type:

source /opt/ros/{$ROSDISTRO}/setup.bash
export ROS_MASTER_URI=http://10.10.10.10:11311
export ROS_HOSTNAME=10.10.10.11

Again, replacing {$ROSDISTRO} on the first line with the ROS distribution installed on computer B. Note that ROS_MASTER_URI remains the same, as that contains the address of the ROS master computer; however, the ROS_HOSTNAME is different, as this should contain the IP address of the current computer. These lines can be added to your ~/.bashrc file for convenience.

On computer A, go back to your sourced terminal instance and launch a minimal instance of ROS using roscore. Check that everything is running properly using rostopic list. You should see the output:

/rosout
/rosout_agg

Create a new topic called \chatter and publish the string message "Hello world!" to it.

rostopic pub /chatter std_msgs/String "Hello world!"

This will publish and latch a String message "Hello World" to a new topic called /chatter. Publishing and latching is important because latching keeps the last topic in memory for any subscribers that may come later (simply publishing will pushing the message and remove it from memory). You can check that this new topic exists using rostopic list.

On computer B, go back to your sourced terminal instance view all topics using rostopic list. This should output:

/chatter
/rosout
/rosout_agg

Note the new topic /chatter that we just created on computer A. To echo the topic enter:

rostopic echo /chatter

This should output:

data: "Hello World!"
---

You have now successfully published a message on computer A, which you then echoed back on computer B! Feel free to continue playing with creating different ROS topics and publishing different messages to them. Anything that can be viewed on computer A should also be viewable on computer B.

⚠️ **GitHub.com Fallback** ⚠️