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.4Prerequisites#
- Both devices connected to same WiFi network
- Ubuntu/ROS installed on both machines
- SSH access to Raspberry Pi
Raspberry Pi Setup#
Check Network Configuration#
ifconfigNote the IP address (e.g., 192.168.0.4).
SSH into Raspberry Pi#
From PC:
ssh pi@192.168.0.4Or for Ubuntu:
ssh ubuntu@192.168.0.4Time Synchronization#
Important for ROS communication:
sudo apt-get install ntpdate
sudo ntpdate ntp.ubuntu.comConfigure ROS Environment#
Edit bashrc:
nano ~/.bashrcAdd at the end:
export ROS_MASTER_URI=http://192.168.0.3:11311
export ROS_HOSTNAME=192.168.0.4Apply changes:
source ~/.bashrcPC (Master) Setup#
Configure ROS Environment#
Edit bashrc:
nano ~/.bashrcAdd:
export ROS_MASTER_URI=http://192.168.0.3:11311
export ROS_HOSTNAME=192.168.0.3Apply changes:
source ~/.bashrcEnvironment Variables Explained#
| Variable | Purpose | Value |
|---|---|---|
| ROS_MASTER_URI | Location of ROS Master | Master’s IP:11311 |
| ROS_HOSTNAME | This machine’s IP | Own IP address |
Common Mistake#
# WRONG - hostname doesn't match machine
export ROS_HOSTNAME=192.168.0.3 # On Pi with IP .4Each machine’s ROS_HOSTNAME must be its own IP!
Testing Connection#
On PC (Master)#
Start ROS Master:
roscoreOn Raspberry Pi#
List topics to verify connection:
rostopic listShould show at least:
/rosout
/rosout_aggPublish Test#
On Pi:
rostopic pub /test std_msgs/String "Hello from Pi"On PC:
rostopic echo /testShould 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:
- Verify roscore is running on master
- Check firewall settings
- Ping between machines
- Verify same network
Ping Test#
# From PC
ping 192.168.0.4
# From Pi
ping 192.168.0.3Firewall#
If using UFW:
sudo ufw allow 11311
sudo ufw allow 11311/tcpPermanent 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=burgerDynamic IP Handling#
If IPs change (DHCP), update bashrc or use:
export ROS_HOSTNAME=$(hostname -I | awk '{print $1}')