Table of Contents

Overview
#

ROS uses a master-slave architecture where one machine runs the ROS Master (roscore) and other machines connect to it. This guide covers setting up communication between a PC and Raspberry Pi.

Network Architecture
#

        WiFi Router
        ↙        ↘
   Desktop PC    Raspberry Pi
  (ROS Master)    (Robot)
  192.168.0.3    192.168.0.4

Prerequisites
#

  • Both devices connected to same WiFi network
  • Ubuntu/ROS installed on both machines
  • SSH access to Raspberry Pi

Raspberry Pi Setup
#

Check Network Configuration
#

ifconfig

Note the IP address (e.g., 192.168.0.4).

SSH into Raspberry Pi
#

From PC:

ssh pi@192.168.0.4

Or for Ubuntu:

ssh ubuntu@192.168.0.4

Time Synchronization
#

Important for ROS communication:

sudo apt-get install ntpdate
sudo ntpdate ntp.ubuntu.com

Configure ROS Environment
#

Edit bashrc:

nano ~/.bashrc

Add at the end:

export ROS_MASTER_URI=http://192.168.0.3:11311
export ROS_HOSTNAME=192.168.0.4

Apply changes:

source ~/.bashrc

PC (Master) Setup
#

Configure ROS Environment
#

Edit bashrc:

nano ~/.bashrc

Add:

export ROS_MASTER_URI=http://192.168.0.3:11311
export ROS_HOSTNAME=192.168.0.3

Apply changes:

source ~/.bashrc

Environment Variables Explained
#

VariablePurposeValue
ROS_MASTER_URILocation of ROS MasterMaster’s IP:11311
ROS_HOSTNAMEThis machine’s IPOwn IP address

Common Mistake
#

# WRONG - hostname doesn't match machine
export ROS_HOSTNAME=192.168.0.3  # On Pi with IP .4

Each machine’s ROS_HOSTNAME must be its own IP!

Testing Connection
#

On PC (Master)
#

Start ROS Master:

roscore

On Raspberry Pi
#

List topics to verify connection:

rostopic list

Should show at least:

/rosout
/rosout_agg

Publish Test
#

On Pi:

rostopic pub /test std_msgs/String "Hello from Pi"

On PC:

rostopic echo /test

Should see: data: "Hello from Pi"

Troubleshooting
#

“Unable to contact my own server”
#

Unable to contact my own server at [http://192.168.0.4:42767/]

Solution: Check ROS_HOSTNAME is set correctly on each machine.

“Cannot reach master”
#

Solutions:

  1. Verify roscore is running on master
  2. Check firewall settings
  3. Ping between machines
  4. Verify same network

Ping Test
#

# From PC
ping 192.168.0.4

# From Pi
ping 192.168.0.3

Firewall
#

If using UFW:

sudo ufw allow 11311
sudo ufw allow 11311/tcp

Permanent Configuration
#

Bashrc vs Environment
#

For permanent setup, bashrc is recommended:

# ~/.bashrc additions
source /opt/ros/noetic/setup.bash
export ROS_MASTER_URI=http://192.168.0.3:11311
export ROS_HOSTNAME=192.168.0.4  # Change per machine
export TURTLEBOT3_MODEL=burger

Dynamic IP Handling
#

If IPs change (DHCP), update bashrc or use:

export ROS_HOSTNAME=$(hostname -I | awk '{print $1}')