0% found this document useful (0 votes)
7 views58 pages

Introduction to Robot Operating System (ROS)

The document provides an introduction to the Robot Operating System (ROS), covering its concepts, communication methods, and programming in Python. It highlights the advantages of using ROS, such as open-source access, software reuse, and a global community. Additionally, it includes installation instructions and details on creating a ROS workspace and packages.

Uploaded by

Mh Hm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views58 pages

Introduction to Robot Operating System (ROS)

The document provides an introduction to the Robot Operating System (ROS), covering its concepts, communication methods, and programming in Python. It highlights the advantages of using ROS, such as open-source access, software reuse, and a global community. Additionally, it includes installation instructions and details on creating a ROS workspace and packages.

Uploaded by

Mh Hm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Robot Operating System (ROS)

4TM00 – ROBOT MOTION PLANNING AND CONTROL

Ömür Arslan, Assistant Professor of Robotics

Department of Mechanical Engineering, Robotics


The Future is Robotics!

Sense Plan

Act

2 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Lecture Topics

• ROS Introduction
• ROS Concepts (Node, Interfaces)
• ROS Communication (Topics, Services, Actions)
• ROS Programming in Python
• Gazebo Simulator

3 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Part I - ROS Introduction

4 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


What is ROS?

5 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Meta-Operating System

6 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Interface between Hardware & Apps (Software)

7 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Distributed Computation

Sensor 1 Computer 1 Actuator 1

Sensor 2 Computer 2 Actuator 2

Sensor 3 Computer 3 Actuator 3

Sensor 4 Computer 4 Actuator 4

Sensor n Computer n Actuator n

8 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Why ROS? It's the fastest way to build a robot!
• Open Source – free and unfettered access to high-quality, fully featured robotics software
• Software Reuse – a growing collection of algorithms for common robot tasks
• Language/OS Independence – support for Python, C++, Lisp on Linux, Windows, OSX
• Distributed Computation – multiple processes running across several different computers
• Easy Prototyping – test ideas in a short time with minimal effort, shorten time to market
• Global Community – code sharing and global software collaboration for robotics

9 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS2 Hubble Installation

Documentation: [Link]
Installation: [Link]
Configuration: [Link]
Build Tool: [Link]
CORE Instructions: [Link]
Tutorials: [Link]

10 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS_DOMAIN_ID:
A unique integer ROS2 network identifier

ROS Environment Configuration


between 0 and 101 such that only ROS2
elements on the same domain can discover
and send messages to each other.
ROS_LOCALHOST_ONLY:
Limits ROS2 communication to localhost
$ gedit ~/.bashrc # Custom ROS settings
only if enabled.

# ROS2 Environment Settings


source /opt/ros/humble/[Link]
export ROS_DOMAIN_ID=0
export ROS_LOCALHOST_ONLY=0

# COLCON Settings
source /usr/share/colcon_cd/function/colcon_cd.sh
export _colcon_cd_root=/opt/ros/humble/
source /usr/share/colcon_argcomplete/hook/[Link]

$ printenv | grep ROS # Check ROS settings

11 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Tutorials: [Link]

ROS2 Humble Tutorials Guide

12 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Part II - ROS Concepts

13 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Nodes
ROS Nodes
• are the smallest executables that can exchange data with each
other via topics, services, actions, or parameters with compatible
Quality of Service settings.
• are recommended to have specific modular functionality that can
be easily reusable.

Node Discovery
• When a node is started, it informs other nodes on the same ROS
network (ROS_DOMAIN_ID)
• Nodes periodically broadcast their presence if they are online;
and inform others when they are going offline

[Link]
[Link]
[Link]
[Link]

14 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Nodes – Command-Line Tools
Commands
• ros2 pkg is a ROS tool for package-related operations
$ ros2 pkg create/executables/list/prefix/xml
$ ros2 pkg <command> --help
• ros2 run starts a package specific executable node
$ ros2 run <package> <node>
$ ros2 run --help
• ros2 node is a ROS tool for displaying node information
$ ros2 node info/list
$ ros2 node <command> --help
• Use Ctrl-C to terminate an active node

[Link]

15 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Nodes: ros2 run & ros2 node

16 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


$ sudo apt update
$ sudo apt install ros-humble-turtlesim

ROS Nodes: Example

17 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Interfaces
Interfaces
• are data types used for information exchange between nodes
Message
• are combinations of string, integer, float and Boolean variables Node A Communication Node B
• can have nested or array structure based on other messages

Types & Specifications


Message (.msg) Service (.srv) Action(.action)
fieldType1 fieldName1 requestType requestName requestType requestName
fieldType2 fieldName2 --- ---
fieldType3 fieldName3 responseType responseName responseType responseName
---
Commands feedbackType feedbackName
• ros2 interface is a tool for displaying information about ROS interfaces
$ ros2 interface list/package/packages/proto/show
$ ros2 interfaces --help

[Link]

18 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Interfaces: Example

19 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Part III – ROS Communication Types

20 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Type Description
Topic Continuous unidirectional data exchange
Service
ROS Communication
One-time request-response data exchange
One-time request-response data exchange
Action
with continuous feedback

Topic Action

Message Communication
(Topics, Services, Actions)

Service

21 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Topics
Topics
• Continuous unidirectional data communication.
• From publishers (data producers) to subscribers (data consumers)
• Anonymous messages – a subscriber does not know the publisher
(though this can be discovered if needed).
• Compatible message type and quality of service.

Commands
• ros2 topic is a tool for displaying topic information
$ ros2 topic list/info/type/echo/pub/hz/bw/delay/find
$ ros2 topic <command> --help
• rqt_graph is a tool to visualize node topic communication
$ rqt_graph

[Link]
[Link]
[Link]

22 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Topics: Example

23 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Topics: Example

24 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Services
Services
• One-time bidirectional request-response communication
• Between a service server and a service client.
• Only one service server per service name but many clients
• Reduce network load due to the request-driven communication
compared to continuous updates and data streams of topics.

Command
• ros2 service a tool for listing and querying ROS services
$ ros2 service list/type/call/find
$ ros2 service <command> --help

[Link]
[Link]

25 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Services: Example

26 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Services: Example

27 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Actions
Actions
• Built on topics and services
• One-time bidirectional request-response communication with
continuous feedback for long running tasks
• Between an action server and an action client: The action client
sends a goal to the action server that acknowledges the goal and
returns a stream of feedback and a result.
• Possible to cancel a running action request without completion.

Command
• ros2 action a tool for listing and querying ROS services
$ ros2 action list/info/send_goal
$ ros2 action <command> --help

[Link]
[Link]

28 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Actions: Example

29 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Parameters
Parameters
• Configuration values (integers, floats, booleans, strings, and lists) Node
maintained by individual nodes for their settings Parameters
• Composed of a key, a value, and a descriptor (empty by default)
• Declaring all node parameters at the startup is preferred to avoid
misconfiguration, but undeclared parameters are also allowed.
• Parameters can be set at the start via command-line tools, launch files,
and YAML files.

Command
• ros2 param a tool for listing and querying ROS parameters
$ ros2 param list/get/set/dump/load/delete/describe
$ ros2 param <command> --help

[Link]

30 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Parameters: Example

31 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Part IV - ROS Programming

32 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


To install colcon: $ sudo apt install python3-colcon-common-extensions

Tip: Place your group’s GitLab repository inside the src/ folder.
ROS Workspace
ROS software is developed over a specific workspace structure that can built with colcon
workspace_folder/ -- WORKSPACE
src/ -- SOURCE SPACE
package_1/
[Link]
[Link]
package_1/
src/

package_n/
COLCON_IGNORE -- Optional empty file to disable building this package folder
[Link]
[Link]
package_n/
src/

build/ -- BUILD SPACE Item Description
COLCON_IGNORE -- Disable building this folder
… [Link] Package build configuration file
install/ -- INSTALL SPACE [Link] Package meta-information file
local_setup.bash -- Settings for sourcing your underlay workspace
[Link] /src
-- Settings for sourcing your ROS overlay and underlay workspace Source folder containing the package source code
COLCON_IGNORE -- Disable building this folder /build Build space that keeps intermediate built files

log/ -- LOG SPACE /install Directory where each package is installed to
latest_build -- Log information for the latest colcon build
COLCON_IGNORE --Disable building this folder /log Logging information about each colcon build

33 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


[Link] $ sudo rosdep init
[Link]
[Link] $ rosdep update
$ rosdep --help
Creating a ROS Workspace
$ mkdir -p ~/4tm00_ws/src # Create a ROS workspace and source folder
$ cd ~/4tm00_ws # Move to the workspace folder
$ rosdep install –i –-from-path src --ignore-src -y # Resolve and install ROS dependencies
$ colcon build –-symlink-install # Build your workspace with symbolic links

$ source ~/4tm00_ws/install/local_setup.bash # Apply the underlay install settings

34 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS_DOMAIN_ID:
A unique integer ROS2 network identifier

ROS Environment Configuration


between 0 and 101 such that only ROS2
elements on the same domain can discover
and send messages to each other.

ROS_LOCALHOST_ONLY:
$ gedit ~/.bashrc # Custom ROS settings Limits ROS2 communication to localhost
only if enabled.
# ROS2 Environment Settings
source /opt/ros/humble/[Link]
export ROS_DOMAIN_ID=0
export ROS_LOCALHOST_ONLY=0

# COLCON Settings
source /usr/share/colcon_cd/function/colcon_cd.sh
export _colcon_cd_root=/opt/ros/humble/
source /usr/share/colcon_argcomplete/hook/[Link]

# ROS Workspace Settings


source ~/4tm00_ws/install/local_setup.bash

35 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Package [Link] [Link] [Link] my_package

Packages
• are the basic units of ROS software
include src scripts config
• should provide easy-to-use and reusable functionality
• might contain ROS nodes, source codes, configuration files,
message types, datasets, etc. launch msg srv action
Commands [Link] Package meta-information file
• ros2 pkg create is a tool to easily create a new ROS package [Link] Build configuration file
$ ros2 pkg create <package_name> [Link] Python installation instructions
$ ros2 pkg create -- help [Link] Python settings for executables
• colcon build is a tool to build a ROS workspace of packages include/ C++ headers & libraries
$ colcon build --help src/ C++ source code
• rosdep is a tool for managing package system dependencies my_package Python module folder
$ rosdep init/update/install/check scripts/ Python executable node scripts
config/ Node configurations (YAML, XML)
$ rosdep --help
bagfiles/ Datasets
msg/ Message files
srv/ Service files
action/ Action files

36 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Creating a ROS Package for C++ or Python:
my_first_ros_pkg_cpp & my_first_ros_pkg_py
$ cd ~/4tm00_ws/src # Change to the workspace source folder
$ ros2 pkg create my_first_ros_pkg_cpp –-build-type ament_cmake # Create a CMake ROS package
$ ros2 pkg create my_first_ros_pkg_py –-build-type ament_python # Create a Python ROS package
$ cd ~/4tm00_ws # Change to the workspace folder
$ colcon build # Build your ROS workspace
$ colcon build –-symlink-install # Use symlink instead of copying install files

COLCON_IGNORE
37 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)
[Link]

Creating a ROS Package for C++ and Python:


my_ros_pkg_template
$ cd ~/4tm00_ws/src # Change to workspace source folder
$ ros2 pkg create my_ros_pkg_template --build-type ament_cmake # Create a CMake package
--dependencies rclcpp rclpy std_msgs # with dependencies rclcpp, rclpy, …
$ cd my_ros_pkg_template # Change to package folder
$ touch include/my_ros_pkg_template/cpp_header.hpp # Create an empty C++ header file
$ echo ‘#include “my_ros_pkg_template/cpp_header.hpp"’ > src/cpp_node.cpp # Create a C++ node using the header
$ echo ‘int main(){return 0;}’ >> src/cpp_node.cpp # and returning 0
$ mkdir my_ros_pkg_template # Create python package
$ touch my_ros_pkg_template/__init__.py # Add Python package initialization
$ touch my_ros_pkg_template/my_module.py # Add an empty python package module
$ mkdir scripts # Create python executable script folder
$ echo ‘#!/usr/bin/env python3’ > scripts/py_node.py # Add an empty executable python node
$ echo ‘import my_ros_pkg_template.my_module’ > scripts/py_node.py # Use python module in python node
$ chmod +x scripts/py_node.py # Make python node executable
$ mkdir launch # Create a folder for launch files
$ touch launch/[Link] # Add an empty python launch file
$ mkdir config # Create a configuration folder
$ touch config/[Link] # Add an empty yaml config file
$ cd ~/4tm00_ws # Change to the workspace folder
$ colcon build –-symlink-install # Build ROS workspace

Package Dependencies
• rclcpp (ROS C++ client library)
38 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS) • rclpy (ROS Python client library)
• std_msgs (Standard ROS messages)
[Link]

Creating a ROS Package for C++ and Python:


my_ros_pkg_template
my_ros_pkg_template/
[Link]
[Link]
include/
cpp_header.hpp
src/
cpp_node.cpp
my_ros_pkg_template/
__init__.py
my_module.py
scripts/
py_node.py
launch/
[Link]
config/
[Link]

39 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


[Link]

my_ros_pkg_template/[Link]
my_ros_pkg_template/
[Link]
[Link]
include/
cpp_header.hpp
src/
cpp_node.cpp
my_ros_pkg_template/
__init__.py UPDATE
my_module.py
scripts/
py_node.py
launch/
[Link]
config/
[Link]

40 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


[Link]

my_ros_pkg_template/[Link]
my_ros_pkg_template/
[Link]
[Link]
include/
cpp_header.hpp
src/
cpp_node.cpp UPDATE
my_ros_pkg_template/
__init__.py
my_module.py
scripts/
py_node.py
launch/
[Link]
config/ UPDATE
[Link]

41 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


[Link]

my_ros_pkg_template/[Link]
my_ros_pkg_template/
[Link]
[Link]
include/
cpp_header.hpp
src/
cpp_node.cpp
my_ros_pkg_template/
UPDATE
__init__.py
my_module.py
scripts/
py_node.py
launch/
[Link]
config/
[Link]

42 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


[Link]

my_ros_pkg_template/…
my_ros_pkg_template/
[Link]
[Link]
include/
cpp_header.hpp
src/
cpp_node.cpp
my_ros_pkg_template/
__init__.py
my_module.py
scripts/
py_node.py UPDATE
launch/
[Link]
config/
[Link]

43 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Tip: All node scripts should be executable, i.e., chmod +x my_node.py

Adding a ROS Node:


my_ros_pkg_template/scripts/my_publisher.py

DOWNLOAD

$ cd ~/4tm00/src/my_ros_pkg_template/scripts
$ chmod +x my_publisher.py

44 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Tip: All node scripts should be executable, i.e., chmod +x my_node.py

Adding another ROS Node:


my_ros_pkg_template/scripts/my_subscriber.py

DOWNLOAD

$ cd ~/4tm00/src/my_ros_pkg_template/scripts
$ chmod +x my_subscriber.py

45 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


How to deal with so many nodes and terminals

Running my_publisher.py & my_subscribers.py nodes

46 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Launch
Launch files
• are a mechanism for starting many nodes all at once.
• enable node configurations and parameter setting at the
start, and composition of multiple launch files.
• are written in the Python, XML, and YAML formats.

Commands
• ros2 launch is a tool for running multiple nodes
$ ros2 launch <package-name> <launch-file>
$ ros2 launch <launch-file>
$ ros2 launch --help
• Use Ctrl-C to terminate an active ros2 launch

[Link]
[Link]
[Link]
[Link]

47 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


CORE Rule of Thumb for ROS Modular Programming!
Every ROS node should have a dedicated launch and config
ROS Launch: Example file for a modular, reusable interface, and documentation.

my_ros_pkg_template/launch/my_publisher_subscriber.launch

48 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Launch: Example
my_ros_pkg_template/launch/my_publisher_subscriber.launch

49 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Do I always need /my_publisher to test /my_subscriber?

ROS Launch: Example


my_ros_pkg_template/launch/my_publisher_subscriber.launch

50 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


ROS Bags
Bag Files Topic
• use a specific format for storing timestamped ROS message data. Avocado
• are often used for recording from and playing back to ROS topics.
• allow offline developing, testing, and debugging of ROS packages. Topic
• can be played back using simulation time by setting parameter Topic Grapes
Apple
/use_sim_time true.

Commands
• Ros2 bag is a tool for recording and playing back of ROS topics
$ ros2 bag record/play/info
$ ros2 bag --help
• rqt_bag is a visualization tool for bag file data
$ rqt_bag --help

[Link]
[Link]

51 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Part V – Gazebo Simulator

52 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Gazebo – Simulate before you physically build and experiment
• Physics Engines (ODE, DART, Bullet)
• High Fidelity Sensors (IMU, LiDAR, Cameras, Magnetometer)
• Control Plugins (Velocity Control, Ackermann Steering)
• Realistic 3D Environment Rendering (OGRE, Optix)
• Flexible Simulation Descriptions (SDF)
• Many robotics models ([Link])
• Easy ROS Integration (ros_gz_bridge)
• Command-line & Graphical Interface

53 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Gazebo Fortress Installation

Documentation: [Link]
Installation: [Link]
CORE Instructions: [Link]
Tutorials: [Link]
Library Reference: [Link]
Simulator API: [Link]

54 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


CORE 4TM00 Software: [Link]

Gazebo – Examples
RoboCyl TurtleBot3

55 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Summary

• ROS Introduction
• ROS Concepts (Node, Interfaces)
• ROS Communication (Topics, Services, Actions)
• ROS Programming in Python
• Gazebo Simulator

Next Lecture: Robot Programming with ROS

56 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Thank you for your attention!

57 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)


Guided Self-Study Exercise
• Go through the lecture slides and the following online ROS2 Humble tutorials ([Link]
• What are the major differences between the lecture slides and online tutorials? Why?

58 Ömür Arslan | 4TM00 | Introduction to Robot Operating System (ROS)

You might also like