Skip to content

ROS Technical Notes

Quick Reference

  • One-sentence definition: ROS (Robot Operating System) is a flexible framework for building robot software, providing tools and libraries to manage communication and computation across modular components.
  • Key use cases: Controlling robots, simulating robotic behavior, and integrating sensors for tasks like navigation or object detection.
  • Prerequisites: Basic familiarity with Linux commands (e.g., using a terminal), Python or C++ knowledge helpful but not required, and a computer with Ubuntu.

Table of Contents

Introduction

  • What: ROS is not a true operating system but a middleware framework that helps developers create robot applications by managing communication between different parts of a system.
  • Why: It simplifies building complex robots by providing reusable code, tools for visualization, and a way to break tasks into manageable pieces, avoiding the need to start from scratch.
  • Where: Used in research (e.g., university labs), industry (e.g., self-driving cars), and hobby projects (e.g., DIY robot arms).

Core Concepts

Fundamental Understanding

  • Basic Principles:
  • ROS breaks a robot’s software into small, independent programs that work together.
  • It uses a communication system to share data, like sensor readings or commands, between these programs.
  • Everything runs on a Linux-based system, often Ubuntu, for flexibility and open-source support.
  • Key Components:
  • Nodes: Individual programs that perform specific tasks (e.g., reading a camera, controlling wheels).
  • Topics: Named channels where nodes send and receive data (e.g., “camera/image” for pictures).
  • Master: A central service (started with roscore) that helps nodes find each other.
  • Common Misconceptions:
  • “ROS is an OS like Windows”: It’s a framework that runs on Linux, not a standalone OS.
  • “It’s only for experts”: Beginners can start with simple tools and tutorials.

Visual Architecture

graph TD
    A[Master<br>roscore] --> B[Node: Camera<br>Publishes /image]
    A --> C[Node: Motor<br>Subscribes /cmd_vel]
    B --> D[Topic: /image]
    C --> E[Topic: /cmd_vel]
- System Overview: The Master connects nodes, which communicate by publishing or subscribing to topics.
- Component Relationships: Nodes send data via topics (publish/subscribe), and the Master ensures they can find each other.

Implementation Details

Basic Implementation [Beginner]

Language: Python (using ROS Noetic)

# Publisher node (talker.py) to send a message
#!/usr/bin/env python
import rospy
from std_msgs.msg import String

def talker():
    # Initialize node
    rospy.init_node('talker', anonymous=True)
    # Create publisher for topic 'chatter'
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rate = rospy.Rate(1)  # 1 Hz
    while not rospy.is_shutdown():
        msg = "Hello, ROS!"
        pub.publish(msg)
        rospy.loginfo(msg)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass
# Subscriber node (listener.py) to receive the message
#!/usr/bin/env python
import rospy
from std_msgs.msg import String

def callback(data):
    rospy.loginfo("I heard: %s", data.data)

def listener():
    # Initialize node
    rospy.init_node('listener', anonymous=True)
    # Subscribe to topic 'chatter'
    rospy.Subscriber('chatter', String, callback)
    # Keep node running
    rospy.spin()

if __name__ == '__main__':
    listener()
- Step-by-Step Setup:
1. Install ROS Noetic on Ubuntu 20.04: Follow http://wiki.ros.org/noetic/Installation/Ubuntu.
2. Create a workspace: mkdir -p ~/catkin_ws/src && cd ~/catkin_ws && catkin_make.
3. Create a package: cd src && catkin_create_pkg beginner_tutorials std_msgs rospy.
4. Save talker.py and listener.py in beginner_tutorials/scripts, make executable: chmod +x *.py.
5. Build: cd ~/catkin_ws && catkin_make.
6. Source: source devel/setup.bash.
7. Run Master: roscore.
8. Run talker in new terminal: rosrun beginner_tutorials talker.py.
9. Run listener in another: rosrun beginner_tutorials listener.py.
- Code Walkthrough:
- talker.py creates a node that publishes “Hello, ROS!” to the chatter topic every second.
- listener.py creates another's node that listens to chatter and prints the message.
- rospy is the Python ROS library; std_msgs.msg.String defines the message type.
- Common Pitfalls:
- Forgetting roscore—it must run first.
- Not sourcing the workspace: source devel/setup.bash after every build.
- Wrong file permissions: Ensure scripts are executable.

Real-World Applications

Industry Examples

  • Use Case: A warehouse robot navigating shelves.
  • Implementation Pattern: ROS nodes handle sensors (e.g., lidar) and motion planning, communicating via topics.
  • Success Metrics: Reliable navigation with minimal collisions.

Hands-On Project

  • Project Goals: Control a virtual turtle in TurtleSim to move in a square.
  • Implementation Steps:
  • Install TurtleSim: sudo apt install ros-noetic-turtlesim.
  • Run: rosrun turtlesim turtlesim_node.
  • Create a Python node to publish velocity commands to /turtle1/cmd_vel.
  • Test by watching the turtle draw a square.
  • Validation Methods: Confirm the turtle completes a square path visually.

Tools & Resources

Essential Tools

  • Development Environment: Ubuntu 20.04, VS Code, or terminal.
  • Key Frameworks: ROS Noetic, Python (rospy), catkin build system.
  • Testing Tools: rviz (visualization), rostopic (debug topics).

Learning Resources

  • Documentation: ROS Wiki (http://wiki.ros.org/ROS/Tutorials).
  • Tutorials: “ROS for Beginners” on The Construct (https://www.theconstruct.ai).
  • Community Resources: ROS Answers (https://answers.ros.org), r/ROS on Reddit.

References

  • ROS Wiki Tutorials: http://wiki.ros.org/ROS/Tutorials
  • “Programming Robots with ROS” (Quigley et al., 2015)
  • The Construct ROS Tutorials: https://www.theconstruct.ai

Appendix

  • Glossary:
  • Node: A program doing one job (e.g., reading a sensor).
  • Topic: A named channel for data (e.g., sensor readings).
  • Setup Guides:
  • Install Ubuntu 20.04: Download from ubuntu.com.
  • ROS Noetic Install: http://wiki.ros.org/noetic/Installation/Ubuntu.
  • Code Templates: See publisher/subscriber example above.