Setup ROS multi-machines for Ned/Ned2

V.1.1

Setup ROS multi-machines for Ned

Difficulty: easy

Time: ~15 min

Note

This tutorial is working from:
The version v3.0.0 of the ned_ros_stack

If you are using a Niryo One, please refer to this tutorial.

This guide will show you how to control Ned/Ned2 from another system, for example, a native Ubuntu OS with ROS, or a Ubuntu virtual box.

You will be able to remotely use Ned/Ned2 Python ROS Wrapper or develop your own ROS packages on a different machine.

First of all, you will need to have ROS Melodic installed on your Ubuntu.

Before going any further, here are some useful readings:

Here, we’ll see how to work with multiple machines, with the Raspberry Pi 4 as the ROS Master. (This also applies to a Master running on any other computer, but for the clarity of this tutorial, we’ll say that the Master is a Raspberry Pi 4, and the other machine will be called “the remote machine”).

First steps

Connect to Ned/Ned2

First you need to connect to the Raspberry Pi 4 inside Ned/Ned2, via SSH. You can find more information in the Connect to Ned/Ned2 via SSH tutorial.

Know your IPs

You already know the Raspberry Pi 4 IP address on the network, because you are connected to it.

To know the private IP address on your computer, use:

ifconfig

Make sure you can successfully ping both machines between each other, using the following command:

ping <ip address>

If you need more information, refer to the Connect to Ned/Ned2 via SSH tutorial.

Modify the ROS environment variables on both machines

Here, the multi machines will work with Ned/Ned2 as the master.

On your computer:

By default, the environment variable “ROS_MASTER_URI” should be something like: http://localhost:11311. You can check the value by typing:

printenv | grep ROS_MASTER_URI

You can also check the value of all ROS related environment variables, with:

printenv | grep ROS

You need to change the value of ROS_MASTER_URI, and replace it by the Raspberry Pi IP. For example, if the Raspberry Pi 4 IP on the network is 192.168.1.179, then you need to do:

export ROS_MASTER_URI=http://192.168.1.179:11311

You also need to specify the value of ROS_IP, which is your current machine’s private IP. If your computer IP address is 192.168.1.84, then type:

export ROS_IP=192.168.1.84

On Ned/Ned2:

Let’s assume that your Raspberry Pi private IP address is 192.168.1.179, then specify again the ROS_MASTER_URI variable with:

export ROS_MASTER_URI=http://192.168.1.179:11311

And same for ROS_IP:

export ROS_IP=192.168.1.179

Note

Remember that each terminal using ROS need to know those variables. You can either export them every time you open a terminal, or set them directly in your .bashrc file, as explained below.

Optional: some improvements

If you often work from the same remote machine with the same Raspberry Pi 4 Master, you can directly set the environment variable in your bashrc. To open the bashrc file, type:

sudo nano ~/.bashrc

Simply write at the end of the file:

export ROS_MASTER_URI=http://<Master_IP_address>:11311
export ROS_IP=<Current_machine_IP_address>

And do it on every machines.

You can also set a hostname instead of an IP address, for that you will need to edit your /etc/hosts with:

sudo nano /etc/hosts

And add a new line, for example: “rpi_machine 192.168.1.179”, and then you can set the ROS_MASTER_URI with:

export ROS_MASTER_URI=http://rpi_machine:11311

Testing time

Make sure that ROS is running on the Raspberry Pi 4. You can simply connect to it with ssh, stop the current program on the Ned terminal with:

sudo service niryo_robot_ros stop

and then launch the complete Ned ROS stack from the Ned terminal, with:

roslaunch niryo_robot_bringup niryo_ned_robot.launch

If you are using Ned2, you’ll want to run:

roslaunch niryo_robot_bringup niryo_ned2_robot.launch

Then, on the remote machine (your computer), type:

rosnode list

If the configuration is correctly done, you should see the list of nodes currently running on the Master (Raspberry Pi 4). This means that the connection is successful.

Note

When executing the “rosnode list” command, if you get the error “ERROR: Unable to communicate with master!”, it means that you did something wrong in the setup, or your ROS installation is not properly configured. Make sure you correctly installed ROS, read the ROS wiki pages about Network and multiple machines, and try to follow the guide again.

Now, check that you can subscribe / publish from your computer on topics hosted by the Master. For instance, you can echo the state of the Learning Mode, with:

rostopic echo /niryo_robot/learning_mode/state

You should now see the Learning Mode state being published and updated when the Learning mode state changes.

Important

If you are not able to echo a topic from your computer, make sure you’ve followed every step. Check your environment variables values on both machines, and make sure to start the roscore after the environment variables setup.

You can now use the ROS communication tools, the Python ROS Wrapper, and access every topics directly from your remote machine!

Note

If you are facing issues for this tutorial, refer to the one provided by ROS here .