Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Introduction to Robotics & ROS

Robotics is a branch of engineering that integrates mechanical, electrical, and software systems to create intelligent machines capable of perceiving, reasoning, and acting in the physical world. From self-driving cars to robotic arms in manufacturing, robotics has transformed industries by automating tasks that are repetitive, dangerous, or beyond human capability.


1. The History Behind ROS

The Early Days of Robotics Software

Before ROS, every robotics project required developers to:
Build custom software for each robot.
✅ Write low-level code for sensor communication, motion control, and path planning.
Reinvent the wheel every time for common functionalities like SLAM (Simultaneous Localization and Mapping) and navigation.

The Problem:

🚧 No common framework to integrate different hardware and software.
🚧 Difficult collaboration—robotics labs were isolated, and there was no standard platform.
🚧 Expensive development cycles—teams built everything from scratch.

Birth of ROS

In 2007, Willow Garage developed ROS (Robot Operating System) to solve these problems.
🌍 Goal: Create a modular, reusable, and standardized software framework for all robots.
🚀 Impact: By 2012, ROS became the de facto standard in robotics research.


2. ROS 1 vs. ROS 2

ROS 1 was revolutionary but had limitations:
No real-time support—critical for robots like autonomous cars.
Weak security—no built-in encryption or authentication.
Centralized communication—relies on a ROS Master, creating a single point of failure.
Limited multi-robot support—not designed for distributed systems.

ROS 2: The Next Generation

ROS 2 (released in 2017) addressed these issues with:
Real-time capability—critical for industrial robotics.
Decentralized architecture—eliminates the ROS Master.
Secure communication—encryption and authentication supported.
Native multi-robot support—ideal for swarm robotics and industrial applications.

Comparison Table

Feature ROS 1 ROS 2 micro-ROS
Real-time support ❌ No ✅ Yes ✅ Yes
Communication Middleware Custom TCP DDS (Real-time) DDS (Embedded)
Multi-Robot Support ❌ Limited ✅ Built-in ✅ Built-in
Security ❌ None ✅ Encryption ✅ Lightweight
Embedded Device Support ❌ No ✅ Partial ✅ Full

3. micro-ROS

🚀 What is micro-ROS?
micro-ROS is a lightweight version of ROS 2 for microcontrollers (MCUs) used in small embedded robots.

📌 Why is it needed?
Most robots have low-power devices (e.g., sensors, actuators, microcontrollers). ROS 2 is too heavy for these devices. micro-ROS extends ROS 2 features to embedded systems, allowing:
Real-time execution
Low-power consumption
Seamless integration with ROS 2 systems

Example Use Cases:
🏎️ Self-driving cars (real-time processing of sensors)
🤖 Industrial automation (small embedded controllers)
📡 Drones and UAVs (flight control & navigation)


4. ROS 2 Architecture: The Core Components

Nodes

  • A node is an independent process performing a task.
  • Example: A camera node captures images, while a processing node detects objects.

Topics (Publisher-Subscriber Model)

  • Nodes communicate using topics.
  • A Publisher sends messages.
  • A Subscriber receives messages.

Services (Request-Response Model)

  • Used for one-time interactions.
  • Example: A robot requests sensor calibration.

Actions (Long-Running Tasks)

  • Used for tasks that take time (e.g., robot navigation).

TF (Transform Library)

  • Handles robot positioning and frame transformations.

5. ROS 2 Cheat Sheet

📦 Package Management

ros2 pkg create <package_name> --build-type ament_python  # Create a new package (Python)
ros2 pkg create <package_name> --build-type ament_cmake   # Create a new package (C++)
ros2 pkg list                                             # List all installed packages

🔧 Building and Sourcing

colcon build --packages-select <package_name>  # Build a specific package
colcon build                                   # Build all packages
source install/setup.bash                      # Source the workspace

📡 Topics

ros2 topic list                                      # List all active topics
ros2 topic echo /<topic_name>                        # Print messages from a topic
ros2 topic pub /<topic_name> std_msgs/msg/String "data: 'Hello ROS2'"  # Publish a message
ros2 interface show std_msgs/msg/String              # Show message structure

⚡ Services

ros2 service list                                    # List all active services
ros2 service call /<service_name> std_srvs/srv/Empty # Call a service
ros2 interface show std_srvs/srv/Empty               # Show service structure

🎯 Actions

ros2 action list                                    # List all available actions
ros2 action send_goal /<action_name> <action_type>  # Send an action goal
ros2 interface show <action_type>                   # Show action structure

🏗️ Launching

ros2 launch <package_name> <launch_file.py>  # Launch a file

6. Colcon Workspace

colcon_ws/                       # Root workspace
├── src/                          # Source directory (contains packages)
│   ├── my_package/               # Example ROS2 package
│   │   ├── my_package/           # Python module directory
│   │   │   ├── __init__.py       
│   │   │   ├── my_node.py        # ROS2 node
│   │   ├── launch/               # Launch files
│   │   │   ├── my_launch.py
│   │   ├── setup.py              # Python package setup
│   │   ├── package.xml           # Package metadata
│   │   ├── resource/             # Marker files
│   │   ├── test/                 # Test scripts
├── build/                        # Build files (auto-generated)
├── install/                      # Installed packages (auto-generated)
├── log/                          # Logs directory

7. ROS 2 Publisher-Subscriber Example

Step 1: Create a Publisher (talker.py)

import rclpy
from std_msgs.msg import String

def main(args=None):
	rclpy.init(args=args)
	node = rclpy.create_node('publisher')
	publisher = node.create_publisher(String, 'topic', 10)
	msg = String()
	i = 0
	
	def timer_callback():
		nonlocal i
		msg.data = 'Hello World: {0}'.format(i)
		i += 1
		node.get_logger().info('Publishing: "{0}"'.format(msg.data))
		publisher.publish(msg)
	
	timer = node.create_timer(1.0, timer_callback)
	rclpy.spin(node)
	node.destroy_timer(timer)
	node.destroy_node()
	rclpy.shutdown()

Step 2: Create a Subscriber (listener.py)

import rclpy
from std_msgs.msg import String

node = None

def chatter_callback(msg):
	global node
	node.get_logger().info('I heard: "{0}"'.format(msg.data))
	
def main(args=None):	
	global node
	rclpy.init(args=args)
	node = rclpy.create_node('subscriber')
	node.create_subscription(String, 'topic', chatter_callback, 10)
	
	while rclpy.ok():
		rclpy.spin_once(node)
	node.destroy_node()
	rclpy.shutdown()

Step 3: Run the Demo

📡 Run the Publisher:

ros2 run my_package talker

🎯 Run the Subscriber:

ros2 run my_package listener

8. ROS 2 Simulation Tools

Gazebo

  • 3D simulation of robots in realistic environments.
  • Physics engine for gravity, collisions, and dynamics.

RViz

  • Visualizes sensor data (laser scans, cameras, maps).
  • Shows robot state, transformations (TF), and navigation goals.

rqt

  • Provides plugins for plotting data, viewing node graphs, monitoring topics, and managing parameters.
  • Useful for real-time debugging without writing additional code.

9. Resources

Official Documentation

Learning Resources

Development Tools

Useful GitHub Repositories

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors