Thursday, 19 November 2020

ROS and Raspberry-Pi (MASTER- SLAVE Configuration)

I assume that you already installed ROS in Raspberry Pi and in your PC. I also assume that you already succeed in publishing data and subscribing the same. Well done...

If you haven't done these task I recommend you to visit my blog (.........................)


So hey there This is Navid, in this blog you will be learning how to transfer data from one system to other with ROS. 

Basically, ROS nodes communicate with each other with ROS Master, So we need a Ros Master Running in any one of your devices, this device acts as Master and other acts as Slave. Pretty simple The one which running roscore is a Master and other one is Slave. 

In my case, Raspberry Pi will be Master and My PC will be Slave, let's do this

First, open Raspberry Pi terminal and start ROS master by running roscore (Figure.1)

Raspi Ternimal (roscore)


Now, we have master running on Raspberry Pi but other devices unaware of master existence. So in order to communicate with Master, we need to take care of some ROS configuration.  

First, we export Ros Master address in all devices (including ROS Master) , Open New ternimal and execute the following command 

                    export ROS_MASTER_URI=http://IP Adress of MASTER:11311

In my case the IP address of the raspberry pi 

(To find your Ip address you can execute ifconfig in new terminal) 

                    export ROS_MASTER_URI=http://192.168.43.142:11311

Now open a terminal in PC and execute the same line in my case the below line.

                    export ROS_MASTER_URI=http://192.168.43.142:11311

So at this stage, our devices know that there is a master node running in Raspberry Pi but they communicate with each other only through ROS IP address, So declare ROS_IP address in all devices.

    In Raspberry pi  export ROS_IP=IP Adress of Raspberry pi 

         in my case,

                        export ROS_IP=192.168.43.142

    In PC export ROS_IP=IP Adress of PC

      in my case,

                    export ROS_IP=192.168.43.99 (my PC IP Adress )


Have a look, commands executed in Raspberry Pi and PC

In Raspberry Pi 


In PC


if you followed all steps correctly you can share messages between both devices as shown in below video 




You can connect as many devices as a slave to the Master.

Stay tune for new blogs related to ROS....



Navid

Author & Editor

Robot enthuasist (M.tech in Robotics) .

3 comments: