+ All Categories
Home > Documents > ROS Day2 Part2

ROS Day2 Part2

Date post: 29-Dec-2015
Category:
Upload: janko-jaridic
View: 13 times
Download: 2 times
Share this document with a friend
Description:
ros programming robot control system design robot operating system
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
Transcript
Page 1: ROS Day2 Part2

The Robot Operating System – Day 2 and 1/2Programming ROS Packages

The Publisher/Subscriber and Service Models

J. Angelo Gurzoni Jr.

31 January 2013

January 30, 2013

Page 2: ROS Day2 Part2

Outline

1 Preliminaries

2 Creating a ROS Package

3 Building a ROS Package

4 Understanding ROS Nodes

5 Publisher/subscriber

6 Service/Client

7 Conceptual Differences between the models

Page 3: ROS Day2 Part2

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

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 Configuration details

http://www.ros.org/wiki/IDEs

Page 4: ROS Day2 Part2

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

Creating a ROS Package

ROS packages have a common file structure:manifest.xml, CMakeLists.txt, mainpage.dox, and Makefiles.

roscreate-pkg automates the creation of new packages, and eliminatescommon errors caused by hand-typing build files 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

Page 5: ROS Day2 Part2

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

Creating a ROS Package

Auto-generated CMakeLists.txt

Page 6: ROS Day2 Part2

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

Building a ROS Package

After the package has been created and the source code written, you’llneed to build it.

rosmake is just like the make command, but it does some special ROSmagic. 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

Page 7: ROS Day2 Part2

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

Understanding ROS Nodes

Up to now, we have shown how to create and build packages, now wewill add functionality into them. Before to proceed, a recap. of ROSgraph concepts:

Nodes: executables that use ROS to communicate with other nodes.

Topics: Nodes can publish messages to a topic and/or subscribe toa topic to receive messages.

Services: Another way Nodes communicate, making requests andreceiving back responses.

Messages: data packets sent/received when subscribing orpublishing to a topic.

Master: Name service for ROS (i.e. to help nodes find each other)

rosout: ROS equivalent of stdout/stderr

roscore: Master + rosout + parameter server

Page 8: ROS Day2 Part2

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

Writing a publisher/subscriber (C++)

As the name suggests, a publisher/subscriber consists of a publisherand (surprise) a subscriber.

Publisher is the entity responsible for sending the data. One exampleof publisher could be an application that reads a sensor and sendsthe reading.

Subscriber is the entity that, to receive the data, subscribes to thedata feed, or topic in ROS language. It can be compared to one whosubscribes to a magazine, and then receives it every week.

Remark: it is common to find modules performing these twofunctions on the same binary.

We’ll develop two simple applications to demonstrate the concept:

talker.cpp

the publisher module

listener.cpp

the subscriber module

Page 9: ROS Day2 Part2

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

Talker.cpp

Talker.cpp

Page 10: ROS Day2 Part2

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

Listener.cpp

Listener.cpp

Page 11: ROS Day2 Part2

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

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 bestandard or customized types (msg files).

The srv file describes the format of the request and responsemessage structures.

example of custom msg file

Header headerstring child frame idgeometry msgs/PoseWithCovariance pose

srv file example

# request fieldsfloat latitudefloat longitude- - -# response fieldsint goal

Page 12: ROS Day2 Part2

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

Service Server

Service Server

Page 13: ROS Day2 Part2

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

Service Client

Service Client

Page 14: ROS Day2 Part2

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

Conceptual Differences between the models

When to use Publisher/Subscriber ? When to use a Service ?

Learn by example (a.k.a. the engineer’s way)

Temperature sensor or a Valve actuatorA query to a facial recognition databaseSending the target location the robot should moveWake-up the rescue robots stationed in the warehouse

Page 15: ROS Day2 Part2

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

Conceptual Differences between the models

When to use Publisher/Subscriber ? When to use a Service ?

Learn by example (a.k.a. the engineer’s way)

Temperature sensor or a Valve actuator - PublisherA query to a facial recognition database - ServiceSending the target location the robot should move - ServiceWake-up the rescue robots stationed in the warehouse - Publisher


Recommended