The ROS robot operating system Raspberry Pi combination has become one of the most popular platforms for robotics enthusiasts and researchers in India. Whether you are a student at IIT, a hobbyist building your first autonomous robot, or a startup prototyping a commercial product, ROS on Raspberry Pi offers a powerful yet affordable path into professional robotics development. This guide walks you through setting up ROS, understanding its core concepts, and building your first robot application.
Table of Contents
- What is ROS and Why Use It?
- Hardware Requirements for ROS on Raspberry Pi
- Installing ROS on Raspberry Pi
- ROS Core Concepts: Nodes, Topics & Messages
- Building Your First ROS Robot
- Integrating Sensors with ROS
- Frequently Asked Questions
What is ROS and Why Use It?
ROS (Robot Operating System) is not actually an operating system — it is a flexible middleware framework for writing robot software. Originally developed at Stanford University and maintained by Open Robotics, ROS provides a collection of tools, libraries, and conventions that simplify the complex task of creating robust robot behaviour across a wide variety of robot platforms.
For Indian makers, ROS offers several compelling advantages. It is completely free and open source. The ROS ecosystem includes thousands of pre-built packages for navigation, perception, manipulation, and simulation. Companies like ISRO, Tata Motors, and numerous IIT robotics labs use ROS in production. Learning ROS opens doors to internships and careers at top robotics companies.
ROS provides a publish-subscribe messaging architecture that allows different parts of your robot software to communicate without tight coupling. A camera node can publish images, a perception node can subscribe to those images and publish detected objects, and a navigation node can use those objects to plan paths — all running on different processes or even different computers.
Hardware Requirements for ROS on Raspberry Pi
ROS has specific hardware requirements that you need to plan for carefully, especially when working with the resource-constrained Raspberry Pi.
Recommended Raspberry Pi Models:
- Raspberry Pi 4B (4GB or 8GB RAM) — Strongly recommended for ROS2. Handles simultaneous navigation, perception, and communication without breaking a sweat.
- Raspberry Pi 4B (2GB RAM) — Adequate for ROS1 Noetic with basic sensors. May struggle with simultaneous camera processing and navigation.
- Raspberry Pi 3B+ — Can run ROS1 but performance will be limited. Consider offloading heavy computation to a laptop via rosbridge.
Additional Hardware Needed:
- MicroSD card 32GB minimum (Class 10 / A2 rating) — ROS installation takes approximately 2-4GB
- 5V 3A USB-C power supply (Pi 4) — Insufficient power causes random crashes during ROS operation
- Active cooling (heatsink + fan) — ROS tasks can sustain 100% CPU for extended periods
- Robot chassis with motors and wheels
- Motor driver board (L298N or TB6612FNG)
- Optional: LIDAR, camera, IMU, ultrasonic sensors
Installing ROS on Raspberry Pi
The recommended approach in 2026 is to install ROS2 Humble Hawksbill on Ubuntu 22.04 Server (64-bit) for Raspberry Pi 4. ROS1 Noetic reaches end-of-life in May 2025, making ROS2 the future-proof choice.
Step 1: Flash Ubuntu 22.04 to SD Card
# On your laptop, download Raspberry Pi Imager
# Select: Ubuntu Server 22.04.x LTS (64-bit)
# Flash to microSD card
# Boot and complete initial setup
Step 2: Install ROS2 Humble
# Set locale
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
# Add ROS2 apt repository
sudo apt install -y software-properties-common curl
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key
-o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg]
http://packages.ros.org/ros2/ubuntu jammy main" |
sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
# Install ROS2 Humble (base install for Pi, saves space)
sudo apt update && sudo apt install -y ros-humble-ros-base python3-colcon-common-extensions
# Source ROS2 in every terminal
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
Step 3: Test Your Installation
# Terminal 1: Run a talker
ros2 run demo_nodes_cpp talker
# Terminal 2: Run a listener
ros2 run demo_nodes_cpp listener
# You should see: [INFO] [talker]: Publishing: 'Hello World: 1'
Step 4: Install Robot-Specific Packages
# Navigation stack
sudo apt install -y ros-humble-navigation2 ros-humble-nav2-bringup
# Robot state publisher
sudo apt install -y ros-humble-robot-state-publisher
# Teleop for keyboard control
sudo apt install -y ros-humble-teleop-twist-keyboard
ROS Core Concepts: Nodes, Topics & Messages
Understanding the ROS communication model is essential before building any robot. ROS uses a graph-based architecture where computation happens in nodes that communicate via topics, services, and actions.
Nodes: A node is a single process that performs computation. Your robot might have a motor_controller node, a sensor_reader node, and a navigation node — all running simultaneously. Nodes are the basic unit of ROS computation.
Topics: Topics are named buses over which nodes exchange messages. A node can publish data to a topic or subscribe to receive data. Topics are asynchronous — the publisher does not wait for subscribers.
Messages: ROS defines standard message types for common data: sensor_msgs/LaserScan for LIDAR, sensor_msgs/Image for cameras, geometry_msgs/Twist for velocity commands, and many more. You can also define custom message types.
# List all active topics
ros2 topic list
# See what a topic is publishing
ros2 topic echo /cmd_vel
# Manually publish a velocity command (move forward at 0.2 m/s)
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist
"{linear: {x: 0.2, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"
Launch Files: In ROS2, launch files (Python-based) start multiple nodes simultaneously with configured parameters. A typical robot launch file starts the robot description, motor controller, sensor drivers, and navigation stack all at once.
# Example ROS2 launch file: my_robot_launch.py
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='my_robot',
executable='motor_controller',
name='motor_controller'
),
Node(
package='my_robot',
executable='sensor_publisher',
name='sensor_publisher'
),
])
Building Your First ROS Robot
Let us build a simple differential drive robot that you can control with a keyboard. This project uses a Raspberry Pi 4, a motor driver, and two DC motors.
Create a ROS2 Package
# Create workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
# Create package
ros2 pkg create --build-type ament_python my_robot
cd ~/ros2_ws
colcon build
source install/setup.bash
Motor Controller Node (Python)
#!/usr/bin/env python3
# my_robot/motor_controller.py
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import Twist
import RPi.GPIO as GPIO
class MotorController(Node):
def __init__(self):
super().__init__('motor_controller')
# L298N motor driver pins (BCM numbering)
self.LEFT_IN1, self.LEFT_IN2 = 17, 18
self.RIGHT_IN1, self.RIGHT_IN2 = 22, 23
self.LEFT_EN, self.RIGHT_EN = 12, 13
GPIO.setmode(GPIO.BCM)
for pin in [self.LEFT_IN1, self.LEFT_IN2,
self.RIGHT_IN1, self.RIGHT_IN2]:
GPIO.setup(pin, GPIO.OUT)
self.subscription = self.create_subscription(
Twist, '/cmd_vel', self.cmd_vel_callback, 10)
def cmd_vel_callback(self, msg):
linear = msg.linear.x
angular = msg.angular.z
left_speed = linear - angular
right_speed = linear + angular
self.set_motor(self.LEFT_IN1, self.LEFT_IN2, left_speed)
self.set_motor(self.RIGHT_IN1, self.RIGHT_IN2, right_speed)
def set_motor(self, in1, in2, speed):
if speed > 0:
GPIO.output(in1, GPIO.HIGH)
GPIO.output(in2, GPIO.LOW)
elif speed < 0:
GPIO.output(in1, GPIO.LOW)
GPIO.output(in2, GPIO.HIGH)
else:
GPIO.output(in1, GPIO.LOW)
GPIO.output(in2, GPIO.LOW)
def main():
rclpy.init()
node = MotorController()
rclpy.spin(node)
GPIO.cleanup()
rclpy.shutdown()
if __name__ == '__main__':
main()
Integrating Sensors with ROS
Sensors are what make robots intelligent. ROS provides standard drivers for most common sensors used in hobby and research robotics.
Ultrasonic Sensor (HC-SR04):
# Custom ROS2 node for HC-SR04
import RPi.GPIO as GPIO
from sensor_msgs.msg import Range
import time
# Publish Range message on /ultrasonic topic
range_msg = Range()
range_msg.header.frame_id = 'ultrasonic_link'
range_msg.radiation_type = Range.ULTRASOUND
range_msg.min_range = 0.02
range_msg.max_range = 4.0
range_msg.range = measured_distance # in metres
IMU (MPU6050): The MPU6050 provides 6-DOF motion data. Install the ros2-mpu6050-driver package or use the I2C interface directly. Publish to /imu/data using sensor_msgs/Imu message type.
LIDAR: The RPLidar A1 has excellent ROS2 support. Install with sudo apt install ros-humble-rplidar-ros and launch with the provided launch file. Data appears on the /scan topic as sensor_msgs/LaserScan.
Camera:
# Install camera driver
sudo apt install -y ros-humble-v4l2-camera
# Launch camera node
ros2 run v4l2_camera v4l2_camera_node --ros-args -p image_size:=[640,480]
Visualising with RViz2: Run RViz2 on your laptop and connect to the Raspberry Pi remotely to visualise sensor data, robot state, and navigation paths:
# Set ROS_DOMAIN_ID on both Pi and laptop (same network)
export ROS_DOMAIN_ID=42
# On laptop (Ubuntu), launch RViz2
ros2 run rviz2 rviz2
Frequently Asked Questions
Can I run ROS on Raspberry Pi Zero?
Technically yes, but it is not practical. The Pi Zero has only 512MB RAM and a single-core processor. Even basic ROS nodes will struggle. Use at minimum a Raspberry Pi 3A+ for simple ROS applications, and a Pi 4 for navigation or vision tasks.
What is the difference between ROS1 and ROS2?
ROS1 (Noetic is the last LTS) uses a centralised roscore master. ROS2 uses DDS (Data Distribution Service) for decentralised, real-time communication — no single point of failure. ROS2 also has better security, real-time support, and is the future of the ROS ecosystem. New projects should use ROS2.
How do I control a ROS robot over WiFi from my laptop?
In ROS2, set the same ROS_DOMAIN_ID on both devices connected to the same WiFi network. ROS2 uses DDS multicast discovery, so nodes on different machines automatically discover each other. No additional configuration needed for basic setups.
Can I use ROS with Arduino?
Yes! Use micro-ROS to run ROS2 directly on Arduino (with sufficient RAM) or use rosserial with ROS1. A common architecture is to use Arduino for real-time low-level control (motors, encoders) connected to Raspberry Pi (running ROS) via USB serial.
How much does it cost to build a basic ROS robot in India?
A basic ROS robot in India typically costs between ₹8,000-₹20,000 depending on components. Raspberry Pi 4B (2GB): ~₹5,000-6,000, robot chassis with motors: ~₹800-2,000, motor driver: ~₹200-500, sensors: ~₹500-2,000, power bank or LiPo: ~₹500-1,500.
Add comment