ROS across machines
So far we have seen how to install the ros on your Pi running debian based operating system and we saw the basic concepts of data distribution of the ROS we also saw nodes, topics and communication between nodes and some commands to play with ros. So far we are running all these commands on a single machine which is cool but the real advantage of the ROS is that you can run each node in a different machine in a different language. All you need to mention is the IP Address where the ROS Master is running. Sounds interesting right, lets get started with it.
Hardware required (Affiliate links):
The links mentioned below are my affiliate links. If you buy using the links, it supports my work.
Orange Pi Zero
Orange Pi Zero Interfaceboard
IP Address of the Devices:
This is the IP Address I used for the laptop and Pi so you need to make sure you know then and ping each other and test if the communication is working. Now the ROS Master i.e roscore will be running in Pi and the publisher will also be running in Pi.
code@orangepizero:~$ roscore &
Now lets start running the the publisher command in Pi
export ROS_MASTER_URI=http://192.168.2.100:11311 export ROS_IP=192.168.2.100 rostopic pub my_topic std_msgs/String "hello there"
In the above command I have set Pi’s IP as ROS_MASTER_URI since the ROS Master (roscore) is running in PI, if you are running it on different machine then mention that. The port number is 11311 and is default for roscore and running you run it on the foreground you will notice it getting printed.
The next line is ROS_IP which was required because command was throwing error without it.
export ROS_MASTER_URI=http://192.168.2.100:11311 export ROS_IP=192.168.2.100 code@code:~$ rostopic list /my_topic /rosout /rosout_agg code@code:~$ rostopic echo /my_topic data: hello there ---
In the above command I set the ROS_MASTER_URI and ROS_IP pointing to Pi and to test if it works fine I typed rostopic list which list all the topics available on the ROS Master running in Pi. Then I subscribed to the topic available there.