You are on page 1of 36

ROS For Absolute Beginners

(Robot Operating System)

Lentin Joseph
http://robocademy.com Founder/Instructor of Robocademy
Founder of Qbotics Labs
Day 4

Programming in ROS

http://robocademy.com
Agenda
• What is a ROS Package?

• Creating a ROS package?

• What are ROS Client libraries?

• roscpp and rospy

http://robocademy.com
Agenda

• Writing first ROS program using roscpp & rospy

• How to create a launch file?

• What is a ROS bag file?

http://robocademy.com
What is a ROS Package ?
• http://wiki.ros.org/Packages

• Software in ROS is organized in packages.

• A package might contain ROS nodes, a ROS-


independent library, a dataset, configuration files, a third-
party piece of software, or anything else that logically
constitutes a useful module.

• The goal of these packages it to provide this useful


functionality in an easy-to-consume manner so that
software can be easily reused.
http://robocademy.com
How to create a hello_world ROS
package inside ROS workspace?
• Go to src folder of ros_catkin_ws
• $ cd ~/ros_catkin_ws/src

• $ catkin_create_pkg hello_world
std_msgs rospy roscpp

http://robocademy.com
Inside hello_world package

http://robocademy.com
The CMakeFile.txt

http://robocademy.com
The package Manifest

http://robocademy.com
How to build hello_world package
• Switch to ROS workspace
– $ cd ~/ros_catkin_ws
• Build the packages inside workspace
– $ catkin_make
– $ catkin_make install
• Check package is installed
– $ roscd hello_world

http://robocademy.com
How to create/build a hello_world
ROS package?
• Creating and Building a Package Demo

http://robocademy.com
ROS Client Libraries

http://robocademy.com
What are ROS client libraries ??
• ROS client libraries provide API’s to
access ROS functionalities

• roscpp and rospy

http://robocademy.com
roscpp client library

• roscpp is a C++ implementation of ROS.

• It provides a client library that enables C++


programmers to quickly interface with
ROS functionalities.

• http://wiki.ros.org/roscpp
http://robocademy.com
rospy client library
• rospy is a pure Python client library for
ROS.

• The rospy client API enables Python


programmers to quickly interface with
ROS

• http://wiki.ros.org/rospy
http://robocademy.com
Other ros client libraries !!!
• roslisp – Client of Lisp

• rosgo - Client implementation of Go

• rosjava – Java implementation

• rosruby – Ruby implementation

http://robocademy.com
Writing ROS Nodes using
roscpp client library

http://robocademy.com
Exercise - 1
• Write a ros node for sending “Hello_World”
message to a topic called chatter using
roscpp

http://robocademy.com
talker.cpp

http://robocademy.com
listener.cpp

http://robocademy.com
CMakeLists.txt

http://robocademy.com
Building nodes using catkin_make

http://robocademy.com
How to run ROS nodes
• rosrun command : Run a ros node

• $ roscore
• $ rosrun hello_world talker
• $rosrun hello_world listener

http://robocademy.com
ROS Launch files

• roslaunch is a tool for easily launching


multiple ROS nodes locally and remotely
via SSH, as well as setting parameters on
the Parameter Server.

http://robocademy.com
How to run both nodes together ??
• roslaunch command : roslaunch is a tool
for easily launching multiple
ROS nodes locally and remotely via SSH,
as well as setting parameters on
the Parameter Server.
• $ roscore
• $ roslaunch hello_world
talker_listener.launch

http://robocademy.com
talker_listener.launch

http://robocademy.com
Writing ROS Nodes using rospy
client library

http://robocademy.com
Exercise - 2
• Write a ros node for sending “Hello_World”
message to a topic called chatter using
rospy

http://robocademy.com
talker.py

http://robocademy.com
listener.py

http://robocademy.com
How to run ROS nodes
• rosrun command : Run a ros node

• $ roscore
• $ rosrun hello_world talker.py
• $rosrun hello_world listener.py

http://robocademy.com
How to run both nodes together ??
• roslaunch command : roslaunch is a tool
for easily launching multiple
ROS nodes locally and remotely via SSH,
as well as setting parameters on
the Parameter Server.
• $ roscore
• $ roslaunch hello_world
talker_listener_python.launch

http://robocademy.com
talker_listener_python.launch

http://robocademy.com
Command : rosbag
• Tool for Record /Playback ROS topics

• http://wiki.ros.org/rosbag

• $ rosbag record <topics>

• $ rosbag play <file_name>.bag

http://robocademy.com
Structure of ROS Package
CMakeLists.txt
package.xml talker.py
talker.cpp
tistener.py
listener.cpp

config include scripts src

launch msg srv action

http://robocademy.com
Conclusion
• Discussed ROS Client libraries

• Created a new ROS package and written


ROS nodes for publishing and subscribing
a string data using roscpp and rospy

• Discussed roslaunch files and rosbag

http://robocademy.com

You might also like