Robotics Day 1: ROS2 Installation & First Node
Today I started my robotics journey with ROS2 — the framework that makes robots tick. Here's what clicked (and what confused me at first).
What Even Is ROS2?
ROS2 (Robot Operating System 2) is not an actual operating system. It's a middleware framework — a set of libraries and tools that help different parts of a robot talk to each other. Think of it as the nervous system for robot software.
The 4 Communication Primitives
ROS2 has four ways for components to communicate:
- Nodes — Independent processes that each do one job (read a camera, drive a motor, plan a path). If one crashes, the rest keep running.
- Topics — Async pub/sub channels. A camera node publishes images to
/camera/image, and any node that cares subscribes. Fire-and-forget. - Services — Synchronous request/reply. "What's the battery level?" → "87%." Use when you need a direct answer.
- Actions — Long-running tasks with progress feedback. "Navigate to point (3,5)" → "25% done… 50%… arrived!" Cancelable mid-execution.
The mental model that helped me: topics are bulletin boards, services are help desks, and actions are delivery tracking.
DDS: The "No Master" Secret
This was the part that initially confused me. In ROS1, there was a central process called roscore that every node had to register with — a phone directory. If roscore died, no new connections could form. Single point of failure.
ROS2 replaced that with DDS (Data Distribution Service), an industry-standard protocol used in military and aerospace systems. Instead of calling a receptionist, nodes shout on the network via multicast. Every node announces itself, and peers discover each other directly. No middleman.
Kill any node and the others keep running. Restart it, and it gets rediscovered automatically.
"But When I Stop My Python File, Everything Stops?"
This tripped me up. When you run one Python file with one node and hit Ctrl+C, yes — that node stops. But that's because you only had one node running in one process. The rclpy.init() and rclpy.shutdown() in main() are local to that single process.
In practice, you'd have 5, 10, or 30 nodes running in separate terminals or processes. Killing one has zero effect on the others. That's the decentralization.
ROS2 vs ROS1 — Why It Matters
The key upgrades: no central master (DDS instead of roscore), real-time support, built-in security, multi-robot support out of the box, and it actually runs on Windows and macOS — not just Linux.
ROS1 is end-of-life. All new robotics work uses ROS2.
My First Publisher Node
Built a minimal publisher that broadcasts "Hello ROS2!" every 0.5 seconds:
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(String, 'topic', 10)
self.timer = self.create_timer(0.5, self.timer_callback)
self.i = 0
def timer_callback(self):
msg = String()
msg.data = f'Hello ROS2! Count: {self.i}'
self.publisher_.publish(msg)
self.get_logger().info(f'Publishing: "{msg.data}"')
self.i += 1
def main(args=None):
rclpy.init(args=args)
node = MinimalPublisher()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
The key takeaway: rclpy.spin(node) is the event loop that keeps the node alive and fires the timer callback. Without it, nothing happens.
How Real Robots Distribute Nodes
One thing I learned — you don't necessarily need one Raspberry Pi per robot body part. A single computer can run dozens of nodes as separate processes. But you can spread nodes across multiple machines (a Jetson on the robot for sensors, a laptop off-board for heavy computation), and DDS connects them transparently over the network. Most real robots use a mix.
Honest Assessment
Wins: The pub/sub mental model clicked fast. Understanding why decentralization matters (no single point of failure) made the architecture feel intuitive rather than abstract.
Struggles: Initially thought "decentralized" meant something more exotic. Had to work through the confusion of "if I stop my script, everything stops" before realizing each node is its own independent process.
Next up: Day 2 — Subscribers and message types. Time to make nodes actually talk to each other.
Day 1 of Robotics. The robot doesn't move yet, but the foundation is set.
Follow along: @KarthNode | #KarthNode100Days