Programming with Robot Operating System in Pi – Part 3 [QUICK GUIDE]

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.

Banggood links

Orange Pi Zero

https://www.banggood.com/Orange-Pi-Zero-Expansion-Board-Interface-Board-Development-Board-p-1115982.html?p=W214159476515201703B

Orange Pi Zero Interfaceboard

https://www.banggood.com/Orange-Pi-Zero-H2-Quad-Core-Open-source-512MB-Development-Board-p-1110210.html?p=W214159476515201703B

SD Card

https://www.banggood.com/8GB-MicroSD-TF-Memory-Card-For-RC-Quadcopter-Camera-p-68888.html?p=W214159476515201703B

USB TTL

https://www.banggood.com/USB-To-TTL-Debug-Serial-Port-Cable-For-Raspberry-Pi-3B-2B-COM-Port-p-1055396.html?p=W214159476515201703B

Amazon links

 

IP Address of the Devices: 

rosremote1

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 &

rosremote2

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.

Leave a Reply

Your email address will not be published. Required fields are marked *