Skip to Content
Hands-On ROS for Robotics Programming
book

Hands-On ROS for Robotics Programming

by Bernardo Ronquillo Japón
February 2020
Intermediate to advanced
432 pages
10h 50m
English
Packt Publishing
Content preview from Hands-On ROS for Robotics Programming

Combining the publisher and subscriber in the same node

Can a node talk and listen at the same time as a real human does? Well, if ROS is a framework for robotics, it should be possible. Let's explore this:

  1. Launch these two commands in the first two terminals, with each one in an independent terminal:
T1 $ roscoreT2 $ rosrun ros_basics doubler.py

/doubler is a node that subscribes to the /number topic, as specified in these two lines of the doubler.py script:

rospy.init_node('doubler')...sub = rospy.Subscriber('number', Int32, callback)...

Additionally, /doubler publishes its result in the /doubled topic:

...pub = rospy.Publisher('doubled', Int32, queue_size=10)

You will notice that nothing happens, because it needs to be fed with a number ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering ROS for Robotics Programming

Mastering ROS for Robotics Programming

Lentin Joseph
ROS Robotics By Example - Second Edition

ROS Robotics By Example - Second Edition

Lentin Joseph, Carol Fairchild, Dr. Thomas L. Harman

Publisher Resources

ISBN: 9781838551308Supplemental Content