What is ROS?
ROS (Robot Operating System) is not an operating system in the traditional sense — it is a flexible framework for writing robot software. It provides tools, libraries and conventions for building complex robot behavior across a wide variety of robotic platforms.
Why ROS?
- Modular architecture — Nodes communicate via topics and services
- Hardware abstraction — Same code runs on different robot platforms
- Simulation support — Gazebo integration for testing without hardware
- Large ecosystem — Thousands of packages available
Installing ROS on Raspberry Pi 4B
ROS2 Humble is recommended for Raspberry Pi 4B running Ubuntu Server 22.04.
Step 1 — Set up locale
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
Step 2 — Add ROS2 repository
sudo apt install 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 \
$(. /etc/os-release && echo $UBUNTU_CODENAME) main" | \
sudo tee /etc/apt/sources.list.d/ros2.list
Step 3 — Install ROS2
sudo apt update
sudo apt install ros-humble-desktop
Step 4 — Source the setup file
source /opt/ros/humble/setup.bash
# Add to .bashrc so it loads every terminal
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
Core ROS2 Concepts
Nodes
A node is a process that performs a specific task. Nodes communicate with each other using topics, services and actions.
Topics — Publisher Example
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class Talker(Node):
def __init__(self):
super().__init__('talker')
self.pub = self.create_publisher(String, 'chatter', 10)
self.timer = self.create_timer(0.5, self.callback)
def callback(self):
msg = String()
msg.data = 'SYSTEM ONLINE'
self.pub.publish(msg)
def main():
rclpy.init()
rclpy.spin(Talker())
rclpy.shutdown()
Topics — Subscriber Example
class Listener(Node):
def __init__(self):
super().__init__('listener')
self.sub = self.create_subscription(
String, 'chatter', self.callback, 10)
def callback(self, msg):
self.get_logger().info(f'Received: {msg.data}')
Installing on Linux PC
On a full Ubuntu 22.04 desktop you can install ROS2 Humble with the same steps. The desktop install includes Gazebo simulation and RViz visualization tools.
Test your installation
# Terminal 1 — run a demo talker
ros2 run demo_nodes_cpp talker
# Terminal 2 — run a demo listener
ros2 run demo_nodes_py listener
Conclusion
ROS bridges the gap between software and hardware in robotics. Once you master nodes, topics and services, you can build anything from a simple sensor reader to a fully autonomous robot platform.