Вы находитесь на странице: 1из 15

The Robot Operating System Day 2 and 1/2

Programming ROS Packages The Publisher/Subscriber and Service Models

J. Angelo Gurzoni Jr.


31 January 2013

January 30, 2013

Outline
Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences between the models

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Preliminaries
Create a workspace to store your ROS packages and stacks. The workspace informs ROS system where to search for your packages. Setting the workspace location:
echo export ROS PACKAGE PATH=/ros workspace:$ROS PACKAGE PATH >> /.bashrc . /.bashrc

Resultant environment variable


$ROS PACKAGE PATH=/home/user/ros workspace:/opt/ros/fuerte/share:/opt/ros/fuerte/...

Have your IDE ready (No notepad programming ) Eclipse is a good option. more about IDEs at the end, stay awake IDE Conguration details http://www.ros.org/wiki/IDEs

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Creating a ROS Package


ROS packages have a common le structure: manifest.xml, CMakeLists.txt, mainpage.dox, and Makeles. roscreate-pkg automates the creation of new packages, and eliminates common errors caused by hand-typing build les and manifests Basic Syntax roscreate-pkg [package name] [depend1] [depend2] [...] example: roscreate-pkg tutorial1 std msgs rospy roscpp Auto-generated manifest.xml, showing the dependencies

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Creating a ROS Package


Auto-generated CMakeLists.txt

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Building a ROS Package

After the package has been created and the source code written, youll need to build it. rosmake is just like the make command, but it does some special ROS magic. When you type rosmake tutorial1, it builds not only the package, but also all packages that your package depends of. Basic Syntax rosmake [package name] example: rosmake tutorial1

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Understanding ROS Nodes


Up to now, we have shown how to create and build packages, now we will add functionality into them. Before to proceed, a recap. of ROS graph concepts: Nodes: executables that use ROS to communicate with other nodes. Topics: Nodes can publish messages to a topic and/or subscribe to a topic to receive messages. Services: Another way Nodes communicate, making requests and receiving back responses. Messages: data packets sent/received when subscribing or publishing to a topic. Master: Name service for ROS (i.e. to help nodes nd each other) rosout: ROS equivalent of stdout/stderr roscore: Master + rosout + parameter server

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Writing a publisher/subscriber (C++)


As the name suggests, a publisher/subscriber consists of a publisher and (surprise) a subscriber. Publisher is the entity responsible for sending the data. One example of publisher could be an application that reads a sensor and sends the reading. Subscriber is the entity that, to receive the data, subscribes to the data feed, or topic in ROS language. It can be compared to one who subscribes to a magazine, and then receives it every week. Remark: it is common to nd modules performing these two functions on the same binary. Well develop two simple applications to demonstrate the concept: talker.cpp the publisher module listener.cpp the subscriber module

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be Talker.cpp

Talker.cpp

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be Listener.cpp

Listener.cpp

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Writing a Service/Client (C++)


A Service/Client provides request-reply functionality.
The server provides the named service(s). The client sends requests and receives responses in return.

Both requests and responses are ROS messages. These can be standard or customized types (msg les). The srv le describes the format of the request and response message structures. example of custom msg le
Header header string child frame id geometry msgs/PoseWithCovariance pose

srv le example
# request elds oat latitude oat longitude --# response elds int goal

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be Service Server

Service Server

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be Service Client

Service Client

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Conceptual Dierences between the models

When to use Publisher/Subscriber ? When to use a Service ? Learn by example (a.k.a. the engineers way)
Temperature sensor or a Valve actuator A query to a facial recognition database Sending the target location the robot should move Wake-up the rescue robots stationed in the warehouse

Preliminaries Creating a ROS Package Building a ROS Package Understanding ROS Nodes Publisher/subscriber Service/Client Conceptual Dierences be

Conceptual Dierences between the models

When to use Publisher/Subscriber ? When to use a Service ? Learn by example (a.k.a. the engineers way)
Temperature sensor or a Valve actuator - Publisher A query to a facial recognition database - Service Sending the target location the robot should move - Service Wake-up the rescue robots stationed in the warehouse - Publisher

Вам также может понравиться