Module VI- ROS and Programming of Robots-updated
Module VI- ROS and Programming of Robots-updated
Programming of Robots
Prepared by
Dr.R.Priyadarshini
Syllabus
Introduction to robot control, Robot
programming and Languages- Introduction to
ROS, Languages, software's and Ros, ROS1,
ROS2, GAZEEBO, Architecture Diagram,
Characteristics of ROS.
Classification of Robot Languages
Robot languages can be grouped broadly in to
three major classes
– First generation language
– Second generation language
– World modelling and task-oriented object
language
General Requirements of a Language for Robot Control
• Understanding the architecture of ROS involves recognizing the roles of its key
components. These components are designed to work together seamlessly:
• Nodes: Independent processes that represent software programs performing
specific tasks in ROS.
• Messages: Data exchanged between nodes. This could be sensor information
or control inputs.
• Services: Defined locations in the code where functions can be called
remotely.
• Topics: Established channels for nodes to send and receive messages
asynchronously.
• Packages: Organizational unit for ROS code, containing nodes, configuration
files, and sometimes datasets or libraries.
• These components together facilitate communication and coordination for
robot tasks, enhancing functionality and ease of development.
Core Elements of ROS Architecture
Navigation Perception
Coordinate
frame
Simulation
representatio
n
ROS Robots
https://robots.ros.org/
When to use
ROS?!
•1- The robot contains many different
sensors and actuators. ROS will help you
create a distributed system for all those
components, instead of having one big
monolith code base that will be hard to
maintain and scale.
•2- For Education Purposes. ROS helps students
see the full picture of robotics applications.
•3- For Research Purposes. Prevents re-inventing
the wheel.
•4- For Fast Prototyping
Why might ROS be not preferable?!
Difficulty in learning:
Difficulties in starting with
ROS can be difficult to learn. It simulation:
has a steep learning curve and
The toughness of learning
developers should become
simulation using Gazebo and
familiar with many new concepts
ROS is a reason for not using it
to get benefits from the ROS
in projects.
framework.
Package
Manifests:
Metapackag Message
Packages:
es: (msg) types:
Service (srv)
types:
ROS filesystem
n Graph
Level
The ROS Computation Graph
is the peer-to-peer network of
the ROS process that TOPICS SERVICES BAGS
processes data together.
The following are the basic
concepts of ROS CGL: Communication Tools
•A node really isn't much more than an executable file
within a ROS package. ROS nodes use a ROS client
ROS Nodes library to communicate with other nodes. Nodes can
publish or subscribe to a Topic. Nodes can also provide
or use a Service.
A node can be
A node is a
launched
ROS program
independently
that uses
of other nodes
ROS’s
and in any
middleware for
order among
communicatio
launches of
ns.
other nodes.
ROS Nodes Many nodes A node is
can run on the useful only if it
same can
computer, or communicate
nodes may be with other
distributed nodes and
across a ultimately with
network of sensors and
computers. actuators.
• • ROS topics are Named buses in which ROS
ROS Topics nodes can send a message. A node can publish or
subscribe any number of topics.
ROS Topics
ROS Master • When a node wants to publish something, it will inform the ROS
master. When another node wants to subscribe to a topic, it will
ask the ROS master from where it can get the data. You can
see the ROS master as a DNS server for nodes to find
where to communicate.
Creating ROS Applications
• How to create:
1. ROS workspace.
2. ROS package.
3. ROS nodes.
ROS Build System : CATKIN
$ cd ~/<workspace_name>/src
$ catkin_init_workspace
$ cd ..
$ catkin_make
$ source
~/<workspace_name>/devel/setup.bash
ROS Packages
What is ROS ROS software is organized into
packages, each of which contains
packages?! some combination of code, data,
and documentation.
$ catkin_create_pkg ros_package_name
package_dependencies
Note make sure you are at the source file when you creating your
packages
So what is the purpose of these files?!
3
the ROS client library of the
Roslis Lisp language. It is mainly
used in motion planning
: p:
libraries on ROS it is not as
popular as roscpp and
rospy.
Include the header files
and modules used in
ROS nodes.
#include "std_msgs/String.h"
# include "std_msgs/Int32.h"
# include "std_msgs/Int64.h"
• If there is a custom message type, we can call it with the following syntax:
# include
"msg_pkg_name/message_name.h"
NOTE: The complete list of message types inside the std_msgs package is at
http://wiki.ros.org/std_msgs.
For python:
rospy.init_node('name_of_node',
anonymous=True);
Printing Messages in a ROS Node
$mkdir –p ~/myHello/src
$cd ~/myHello/src
$catkin_init_workspace
$cd ..
$catkin_make
2. Creating a hello_world Package
$ cd ~/myHello/src
$ myHello/src $ catkin_create_package hello_world roscpp rospy std_msgs
Package.xml
After saving CMakeLists.txt, we can build the source code. The command to build the
nodes is catkin_make. Just switch to the workspace folder and execute the
catkin_make command.
To switch to the catkin_ws folder, assume that the workspace is in the home folder:
$ cd ~/catkin_ws
Executing the catkin_make command to build the nodes:
$ catkin_make
6. Executing C++ Nodes
• https://rdk.flexiv.com/manual/ros2_bridge.html
Evolution of ROS – Differences ROS1 &
2
• ROS has evolved significantly since its inception in 2007. It was initially developed at Willow Garage and later supported
by the Open Source Robotics Foundation (OSRF). Over the years, ROS has transitioned through multiple versions, each
bringing functionality, performance, and usability improvements. Initially designed for research purposes, ROS quickly
gained traction due to its modular architecture, facilitating collaboration and code reuse within the robotics community.
Its adaptability across various hardware platforms and open-source nature fueled its growth, making it a go-to
framework for robotics development worldwide.
• As ROS evolved, it expanded beyond research labs into industrial applications, enabling the development of complex
robotic systems for autonomous vehicles, industrial automation, healthcare, and more. As per the official ROS website,
over 740 businesses employed ROS in 2022. Such expansion was supported by the creation of ROS 2, addressing the
limitations of the original ROS and enhancing its capabilities for real-time and industrial-grade deployments.
• ROS Versions
• 1. ROS 1
• Initial development: ROS 1, also known as ‘Boxturtle’, was the first major release introduced in 2010. It laid the
groundwork for the ROS framework, primarily focusing on research and experimentation in robotics.
• Evolution and updates: Subsequent releases within ROS 1, named after different turtles such as Fuerte, Groovy,
Hydro, Indigo, Jade, Kinetic, Lunar, and Melodic, brought about improvements in stability, performance, and expanded
libraries for various functionalities.
• Limitations addressed by ROS 2: Despite its success, ROS 1 faced challenges related to real-time capabilities,
scalability, and support for modern architectures, leading to ROS 2’s development.
• 2. ROS 2
• Introduction and focus: ROS 2 was introduced in 2022 to address the limitations of ROS 1 and expand its capabilities
for more diverse and complex robotics applications, especially in industrial and commercial settings.
• Key features: ROS 2 brings several improvements, including better real-time performance, enhanced security,
increased modularity, improved middleware (using Data Distribution Service – DDS), and expanded platform support.
• Versions and advancements: ROS 2 versions include releases named after alphabetically ordered code names such
as Ardent, Bouncy, Crystal, Dashing, Eloquent, Foxy, and Galactic, with each iteration refining the system and making it
more suitable for industrial-grade deployments.
Evolution of ROS – Differences ROS1 &
2
• The transition from ROS 1 to ROS 2 signifies a shift toward more robust, scalable, and
real-time-capable robotics frameworks. ROS 2’s development is ongoing, with a focus
on addressing further industrial requirements, interoperability, and integration with
modern technologies, marking it as the future of ROS for a wide array of robotics
applications.
• What Is Robotic Process Automation (RPA)? Meaning, Working, Software, and Uses
• How Does ROS Work?
• Understanding how the robot operating system works involves delving into its core
concepts and the step-by-step processes it employs. Here’s a breakdown of the
workings of ROS into key technical steps:
• 1. Node creation
• The foundation of ROS lies in its nodes, which are individual processes responsible for
specific tasks. Developers create these nodes using ROS libraries in languages such as
C++ or Python. Each node typically performs a particular function, such as controlling
a sensor, processing data, or executing algorithms.
• 2. Mastering the ROS Master
• At the core of ROS is the ROS Master, a critical component that facilitates
communication among nodes. It acts as a centralized registry where nodes can find
each other. When a node starts, it registers with the ROS Master, providing information
about its name, type, and functionalities.
• 3. Communication via topics
• Nodes communicate with each other using a pub-sub model through topics. Topics are
named buses, where nodes can publish messages (publishers) or subscribe to receive
messages (subscribers). For instance, a camera node might publish images to a
‘camera’ topic, while an image processing node subscribes to this topic to receive and
process the images.
• 4. Services for request-response communication
• In addition to topics, ROS employs services for request-response communication
between nodes. A node provides a service with a specific functionality; other nodes can
call this service to request that functionality. For example, a node controlling a robotic
arm might offer a ‘move’ service that other nodes can call to instruct the arm’s
movement.
• 5. Parameter server for configuration
• ROS includes a parameter server that stores and manages dynamic configuration data.
Nodes can store and retrieve parameters from this server, allowing easy configuration
changes during runtime. Parameters can control various aspects, such as motor speeds,
algorithm parameters, or sensor configurations.
• 6. ROS packages and file system hierarchy
• ROS uses a specific file system hierarchy for organizing code into packages. A package
typically contains nodes, configuration files, launch files (scripts to start multiple
nodes), and other resources. This structure fosters modularity and reusability, enabling
developers to share and collaborate on specific functionalities or algorithms.
• 7. Tools for visualization and simulation
• ROS provides a suite of powerful tools for visualization and simulation, which are key
aspects of robotics development. Some of the key examples include:
• RQT: RQT is a powerful graphical user interface (GUI) framework within ROS that
provides a collection of plugins for visualization, data inspection, and interaction
with ROS nodes. It offers a customizable interface, allowing users to visualize data,
manipulate parameters, and interact with multiple nodes simultaneously.
• Stage: Stage is a 2D simulation environment within ROS that focuses on
simulating robot behaviors in a 2D space. It allows for quick prototyping and
testing of robot navigation algorithms in simplified environments.
• MoveIt!: MoveIt! is a ROS package specifically designed for motion planning and
manipulation. It offers tools for motion planning, kinematics, collision checking,
and grasping, facilitating the development and testing of robotic manipulation
tasks.
• ROS Control: ROS Control provides a framework to control robot joints and
actuators. It includes controllers for various types of robots, allowing users to
interface with hardware and control robot movements in simulation and real-world
scenarios.
• These tools, along with RViz and Gazebo, constitute a comprehensive suite within
ROS, offering a range of functionalities crucial to developing, testing, and
deploying robotic systems across different domains.
• 8. Integration of hardware abstraction
• ROS abstracts hardware interfaces, allowing nodes to communicate with various
sensors, actuators, and devices without worrying about low-level details. This
abstraction layer simplifies development by providing standardized interfaces for
different hardware components, promoting interoperability among robotic systems.
• 9. Message types and serialization
• Communication between nodes involves passing messages. ROS defines message types
for various data formats, such as integers, floats, images, and custom data structures.
These messages are serialized for transmission across the ROS network, allowing nodes
written in different languages to communicate seamlessly.
• 10. Scalability and adaptability
• ROS is designed to be highly scalable and adaptable to various robotic applications. Its
modular nature allows developers to add or remove nodes easily, enabling the creation of
complex robotic systems by combining different functionalities. Moreover, ROS supports
distributed computing, allowing nodes to run on multiple machines, enhancing
performance and scalability.
• In essence, ROS operates by providing a structured and modular framework for
developing robotics software. It abstracts complexities, enabling seamless communication
between nodes, organizing code into packages for easy sharing, and offering a suite of
tools for visualization, simulation, and hardware integration. This architecture empowers
developers to focus on building advanced robotic applications without getting entangled
in the intricacies of low-level system integration.
• Applications of a Robot Operating System
• ROS has found extensive applications across various domains in robotics due to its
flexibility, modularity, and rich set of tools. As per a July 2023 MarketsAndMarkets report,
the ROS market was valued at $581 million in 2023 and is projected to reach $1,082
million by the end of 2028. The report underscores Asia Pacific, Europe, and North
America as significant regional markets shaping the ROS landscape.
• With the adoption of ROS growing, we need to explore its diverse applications through
examples demonstrating its usage in various domains.
Introduction to ROS2 Basics
• Basics of Robotics & ROS
• Setting up the Development Environment
• Core ROS2 Concepts
• Hands-on Practice
Basics of ROS in Robotics
Fun Fact : ROS sometimes is also interpreted as "Really Odd Stuff" or "Roughly Operating System." This reflects
the complexity and quirks users might encounter while working with it
ROS1 vs ROS2 Key Differences
ROS1 vs ROS2 Differences
Building Environment The build tool changed from from catkin to colcon
A single command line tool (ros2) is used, with different options (pkg, node, run, launch,…)
Reorganization in the package structure, mainly for the Python packages
The TurtleBot robot, a popular platform for ROS learning, is often nicknamed "Turtle." This playful
name adds a touch of lightheartedness to the learning process.
ROS2 Design
ROS 2 provides a convention on
writing nodes using inherited
Node class with all functionalities
The basic functionality of all ROS 2 elements
are implemented in a single C library called rcl;
then the libraries rclcpp and rclpy adapt this
functionality to the particularities of each
language, C++ and Python
mkdir -p ~/ros2_ws/src && cd ~/ros2_ws Create ros2_ws and Change Directory into it
source install/setup.bash Source local folder. You can also use colcon test to test our build
• We can also modify the turtlesim node; goto ~/ros2_ws/src/ros_tutorials/turtlesim/src and open
turtle_frame.cpp in VS Code.
• Change setWindowTitle("TurtleSim"); to setWindowTitle(“myTurtleSim");
• Colcon build in ros2_ws
• Run ros2 run turtlesim turtlesim_node
colcon build --packages-select my_package Build the package. In this command, only my_package is built and not
all other packages
source install/local_setup.bash Source the workspace
ros2 run my_package my_node To run the executable you created using the --node-name argument
during package creation
Creating Simple Publisher Node
ros2 pkg create --build-type ament_cmake --license Apache-2.0 Navigate into the ros2_ws/src and run this command. Make sure the
cpp_pubsub folder is sourced.
wget -O publisher_member_function.cpp Download the publisher node and examine the contents of
https://raw.githubusercontent.com/ros2/examples/humble/rclcpp/topi publisher_member_function.cpp. Use VS Code to view the contents
cs/minimal_publisher/member_function.cpp
add_executable(talker src/publisher_member_function.cpp) Add executable and name it talker so that we can use ros2 run
ament_target_dependencies(talker rclcpp std_msgs)
install(TARGETS Lastly, add install(TARGETS..) so that our ros2 run can find the
talker executable
DESTINATION lib/${PROJECT_NAME})
Creating Simple Subscriber Node
wget -O subscriber_member_function.cpp Download the subscriber node and examine the contents of
https://raw.githubusercontent.com/ros2/examples/humble/rclcpp/topi subscriber_member_function.cpp. There is no timer here as subscriber
cs/minimal_subscriber/member_function.cpp only needs to wait for whatever data published
add_executable(listener src/subscriber_member_function.cpp) After ament_cmake, add below two lines as package needs rclcpp and
ament_target_dependencies(listener rclcpp std_msgs) std_msgs in package.xml
install(TARGETS
talker
listener
DESTINATION lib/${PROJECT_NAME})
source /opt/ros/humble/setup.bash Use this command on every new terminal to have access to ROS
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc 2 commands
export ROS_DOMAIN_ID=<your_domain_id> Isolates different ROS2 systems running on the same network
echo "export ROS_DOMAIN_ID=<your_domain_id>" >> ~/.bashrc
mkdir –p ros2_ws/src
colcon build
Creating a workspace
ros2 run demo_nodes_cpp talker Testing if everything is setup and working. Repeat the demo
ros2 run demo_nodes_cpp listener codes using _py for running python code
ROS users sometimes refer to the "ROS dance" or the "ROS shuffle," which describes the process of debugging
and troubleshooting issues, often involving trial and error and a bit of head-scratching.
Core ROS Concepts
Nodes: Independent processes that perform specific
tasks within a robot application
Topics: Channels for data exchange between nodes
using standardized message types
Services: Mechanisms for requesting specific
functionalities from other nodes
ROS Tools : roscore, rostopic, rosrun, rqt_console
rviz: 3D visualization tool for robot models, sensor
data, and robot paths.
ROS website: Extensive documentation, tutorials,
and community forums. https://www.ros.org/
Hands On
sudo apt install ros-humble-turtlesim Install turtlesim
ros2 run turtlesim turtlesim_node --ros-args --remap Remap node like we did before for teleop. ros2 node list after
this to see all nodes mapped
__node:=my_turtle
ros2 topic echo /turtle1/cmd_vel All published data of cmd_vel is shown. Move
turtle for change of values. Recheck rqt_graph
for new topic
ros2 interface show geometry_msgs/msg/Twist Shows linear and angular velocity of turtle
ros2 topic pub --once /turtle1/cmd_vel Repeat the same without using –once. Once is
geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, an optional argument
angular: {x: 0.0, y: 0.0, z: 1.8}}"
ros2 topic echo /turtle1/pose Here we see that turtlesim is also publishing
pose topic
Interesting Facts
Demonstrates using tf2 library to set up three coordinate frames in ROS: world, turtle1, and turtle2. It employs
a tf2 broadcaster to publish the turtle frames and a tf2 listener to calculate the positional differences between
the turtles, enabling one turtle to follow the other. view_frames creates diagram of frames being broadcasted.
View frames in pdf format in a 5 second interval
ros2 run tf2_tools view_frames
ros2 run tf2_ros tf2_echo turtle2 turtle1 See transform values displayed on the
screen. Move turtles to see values change
* Terminator Controls : Ctrl+Shft+O and Ctrl+Shft+E to split. Ctrl+Shft+W and Ctrl+Shft+Q to close. Ctrl+Shft+I for new window
ROS2 Visualization (rViz)
rviz2 is a 3D visualization tool that is useful for examining tf2 frames.
ros2 run rviz2 rviz2 or simply rviz2 to open rviz window
ros2 run rviz2 rviz2 -d $(ros2 pkg prefix --share Opens rViz windows. Make sure tf demo is
turtle_tf2_py)/rviz/turtle_rviz.rviz running and turtles still alive. World is
getting hotter everyday and turtles are
endangered
In the side bar you will see the frames broadcast by tf2. As you drive the turtle around you will see
the frames move in rviz. In the next slide, we will understand the units that make a rViz screen
Tools
Displays
3D Window View Cameras
Display Status
Website : https://siliris.com
E-Commerce : https://veerobot.com
Our Portfolio
From PCB manufacturing to Robot building, we have our foot set
everywhere
PCB
Design to
Assembly
Li-Po / Li-Ion
Battery
Hobby
Drones Packs
Robot Kits
/ UAV’s
Surveillan
ce
Robots
Customized
Solutions Electric
Cycles
Arms & Grippers Sensors & Modules
Hobby
Robot Kits
Drones
/ UAV’s
Racing Drones
Drones Kits
Li-Po / Li-Ion
Battery Standard ebike / eScooter Customized Lithium based Battery Solutions
Packs Batteries
PCB
Design to Rigid 1-2 Sided Rigid Flex
Assembly