Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo
Learning ROS for Robotics Programming - Second Edition

Book Description

Your one-stop guide to the Robot Operating System

About This Book

  • Model your robot on a virtual world and learn how to simulate it
  • Create, visualize, and process Point Cloud information
  • Easy-to-follow, practical tutorials to program your own robots
  • Who This Book Is For

    If you are a robotic enthusiast who wants to learn how to build and program your own robots in an easy-to-develop, maintainable, and shareable way, this book is for you. In order to make the most of the book, you should have a C++ programming background, knowledge of GNU/Linux systems, and general skill in computer science. No previous background on ROS is required, as this book takes you from the ground up. It is also advisable to have some knowledge of version control systems, such as svn or git, which are often used by the community to share code.

    What You Will Learn

  • Install a complete ROS Hydro system
  • Create ROS packages and metapackages, using and debugging them in real time
  • Build, handle, and debug ROS nodes
  • Design your 3D robot model and simulate it in a virtual environment within Gazebo
  • Give your robots the power of sight using cameras and calibrate and perform computer vision tasks with them
  • Generate and adapt the navigation stack to work with your robot
  • Integrate different sensors like Range Laser, Arduino, and Kinect with your robot
  • Visualize and process Point Cloud information from different sensors
  • Control and plan motion of robotic arms with multiple joints using MoveIt!
  • In Detail

    If you have ever tried building a robot, then you know how cumbersome programming everything from scratch can be. This is where ROS comes into the picture. It is a collection of tools, libraries, and conventions that simplifies the robot building process. What’s more, ROS encourages collaborative robotics software development, allowing you to connect with experts in various fields to collaborate and build upon each other's work.

    Packed full of examples, this book will help you understand the ROS framework to help you build your own robot applications in a simulated environment and share your knowledge with the large community supporting ROS.

    Starting at an introductory level, this book is a comprehensive guide to the fascinating world of robotics, covering sensor integration, modeling, simulation, computer vision, navigation algorithms, and more. You will then go on to explore concepts like topics, messages, and nodes. Next, you will learn how to make your robot see with HD cameras, or navigate obstacles with range sensors. Furthermore, thanks to the contributions of the vast ROS community, your robot will be able to navigate autonomously, and even recognize and interact with you in a matter of minutes.

    What’s new in this updated edition? First and foremost, we are going to work with ROS Hydro this time around. You will learn how to create, visualize, and process Point Cloud information from different sensors. This edition will also show you how to control and plan motion of robotic arms with multiple joints using MoveIt!

    By the end of this book, you will have all the background you need to build your own robot and get started with ROS.

    Style and approach

    This book is an easy-to-follow guide that will help you find your way through the ROS framework. This book is packed with hands-on examples that will help you program your robot and give you complete solutions using ROS open source libraries and tools.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Learning ROS for Robotics Programming Second Edition
      1. Table of Contents
      2. Learning ROS for Robotics Programming Second Edition
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Author
      7. Acknowledgments
      8. About the Author
      9. Acknowledgments
      10. About the Author
      11. Acknowledgments
      12. About the Reviewer
      13. About the Reviewer
      14. Acknowledgments
      15. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      17. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      18. 1. Getting Started with ROS Hydro
        1. PC installation
        2. Installing ROS Hydro – using repositories
          1. Configuring your Ubuntu repositories
          2. Setting up your source.list file
          3. Setting up your keys
          4. Installing ROS
          5. Initializing rosdep
          6. Setting up the environment
          7. Getting rosinstall
        3. How to install VirtualBox and Ubuntu
          1. Downloading VirtualBox
          2. Creating the virtual machine
        4. Installing ROS Hydro in BeagleBone Black (BBB)
          1. Prerequisites
          2. Setting up the local machine and source.list file
          3. Setting up your keys
          4. Installing the ROS packages
          5. Initializing rosdep for ROS
          6. Setting up the environment in BeagleBone Black
          7. Getting rosinstall for BeagleBone Black
        5. Summary
      19. 2. ROS Architecture and Concepts
        1. Understanding the ROS Filesystem level
          1. The workspace
          2. Packages
          3. Metapackages
          4. Messages
          5. Services
        2. Understanding the ROS Computation Graph level
          1. Nodes and nodelets
          2. Topics
          3. Services
          4. Messages
          5. Bags
          6. The ROS master
          7. Parameter Server
        3. Understanding the ROS Community level
        4. Tutorials to practice with ROS
          1. Navigating by ROS Filesystem
          2. Creating our own workspace
          3. Creating a ROS package and metapackage
          4. Building an ROS package
          5. Playing with ROS nodes
          6. Learning how to interact with topics
          7. Learning how to use services
          8. Using Parameter Server
          9. Creating nodes
          10. Building the node
          11. Creating msg and srv files
          12. Using the new srv and msg files
          13. The launch file
          14. Dynamic parameters
        5. Summary
      20. 3. Visualization and Debug Tools
        1. Debugging ROS nodes
          1. Using the GDB debugger with ROS nodes
          2. Attaching a node to GDB while launching ROS
          3. Profiling a node with valgrind while launching ROS
          4. Enabling core dumps for ROS nodes
        2. Logging messages
          1. Outputting a logging message
          2. Setting the debug message level
          3. Configuring the debugging level of a particular node
          4. Giving names to messages
          5. Conditional and filtered messages
          6. Showing messages in the once, throttle, and other combinations
          7. Using rqt_console and rqt_logger_level to modify the debugging level on the fly
        3. Inspecting what is going on
          1. Listing nodes, topics, services, and parameters
          2. Inspecting the node's graph online with rqt_graph
        4. Setting dynamic parameters
        5. When something weird happens
        6. Visualizing node diagnostics
        7. Plotting scalar data
          1. Creating a time series plot with rqt_plot
        8. Image visualization
          1. Visualizing a single image
        9. 3D visualization
          1. Visualizing data in a 3D world using rqt_rviz
          2. The relationship between topics and frames
          3. Visualizing frame transformations
        10. Saving and playing back data
          1. What is a bag file?
          2. Recording data in a bag file with rosbag
          3. Playing back a bag file
          4. Inspecting all the topics and messages in a bag file
        11. Using the rqt_gui and rqt plugins
        12. Summary
      21. 4. Using Sensors and Actuators with ROS
        1. Using a joystick or a gamepad
          1. How does joy_node send joystick movements?
          2. Using joystick data to move a turtle in turtlesim
        2. Using a laser rangefinder – Hokuyo URG-04lx
          1. Understanding how the laser sends data in ROS
          2. Accessing the laser data and modifying it
            1. Creating a launch file
        3. Using the Kinect sensor to view objects in 3D
          1. How does Kinect send data from the sensors, and how do we see it?
          2. Creating an example to use Kinect
        4. Using servomotors – Dynamixel
          1. How does Dynamixel send and receive commands for the movements?
            1. Creating an example to use the servomotor
        5. Using Arduino to add more sensors and actuators
          1. Creating an example program to use Arduino
        6. Using an ultrasound range sensor with Arduino
        7. How distance sensors send messages
          1. Creating an example to use the ultrasound range
            1. Using the IMU – Xsens MTi
          2. How does Xsens send data in ROS?
          3. Creating an example to use Xsens
        8. Using a low-cost IMU – 10 degrees of freedom
          1. Downloading the library for the accelerometer
          2. Programming Arduino Nano and the 10 DOF sensor
          3. Creating an ROS node to use data from the 10 DOF sensor
        9. Using a GPS system
          1. How GPS sends messages
          2. Creating an example project to use GPS
        10. Summary
      22. 5. Computer Vision
        1. Connecting and running the camera
          1. FireWire IEEE1394 cameras
          2. USB cameras
        2. Writing your own USB camera driver with OpenCV
          1. Using OpenCV and ROS images with cv_bridge
          2. Publishing images with image transport
          3. Using OpenCV in ROS
          4. Visualizing the camera input images
        3. Calibrating the camera
          1. Stereo calibration
        4. The ROS image pipeline
          1. The image pipeline for stereo cameras
        5. ROS packages useful for Computer Vision tasks
        6. Using visual odometry with viso2
          1. Camera pose calibration
          2. Running the viso2 online demo
          3. Running viso2 with our low-cost stereo camera
        7. Performing visual odometry with an RGBD camera
          1. Installing fovis
          2. Using fovis with the Kinect RGBD camera
        8. Computing the homography of two images
        9. Summary
      23. 6. Point Clouds
        1. Understanding the point cloud library
          1. Different point cloud types
          2. Algorithms in PCL
          3. The PCL interface for ROS
        2. My first PCL program
          1. Creating point clouds
          2. Loading and saving point clouds to the disk
          3. Visualizing point clouds
          4. Filtering and downsampling
          5. Registration and matching
          6. Partitioning point clouds
        3. Segmentation
        4. Summary
      24. 7. 3D Modeling and Simulation
        1. A 3D model of our robot in ROS
        2. Creating our first URDF file
          1. Explaining the file format
          2. Watching the 3D model on rviz
          3. Loading meshes to our models
          4. Making our robot model movable
          5. Physical and collision properties
        3. Xacro – a better way to write our robot models
          1. Using constants
          2. Using math
          3. Using macros
          4. Moving the robot with code
          5. 3D modeling with SketchUp
        4. Simulation in ROS
          1. Using our URDF 3D model in Gazebo
          2. Adding sensors to Gazebo
          3. Loading and using a map in Gazebo
          4. Moving the robot in Gazebo
        5. Summary
      25. 8. The Navigation Stack – Robot Setups
        1. The navigation stack in ROS
        2. Creating transforms
          1. Creating a broadcaster
          2. Creating a listener
          3. Watching the transformation tree
        3. Publishing sensor information
          1. Creating the laser node
        4. Publishing odometry information
          1. How Gazebo creates the odometry
          2. Creating our own odometry
        5. Creating a base controller
          1. Using Gazebo to create the odometry
          2. Creating our base controller
        6. Creating a map with ROS
          1. Saving the map using map_server
          2. Loading the map using map_server
        7. Summary
      26. 9. The Navigation Stack – Beyond Setups
        1. Creating a package
        2. Creating a robot configuration
        3. Configuring the costmaps – global_costmap and local_costmap
          1. Configuring the common parameters
          2. Configuring the global costmap
          3. Configuring the local costmap
          4. Base local planner configuration
        4. Creating a launch file for the navigation stack
        5. Setting up rviz for the navigation stack
          1. The 2D pose estimate
          2. The 2D nav goal
          3. The static map
          4. The particle cloud
          5. The robot's footprint
          6. The local costmap
          7. The global costmap
          8. The global plan
          9. The local plan
          10. The planner plan
          11. The current goal
        6. Adaptive Monte Carlo Localization
        7. Modifying parameters with rqt_reconfigure
        8. Avoiding obstacles
        9. Sending goals
        10. Summary
      27. 10. Manipulation with MoveIt!
        1. The MoveIt! architecture
          1. Motion planning
          2. The planning scene
          3. Kinematics
          4. Collision checking
        2. Integrating an arm in MoveIt!
          1. What's in the box?
          2. Generating a MoveIt! package with the setup assistant
          3. Integration into RViz
          4. Integration into Gazebo or a real robotic arm
        3. Simple motion planning
          1. Planning a single goal
          2. Planning a random target
          3. Planning a predefined group state
          4. Displaying the target motion
        4. Motion planning with collisions
          1. Adding objects to the planning scene
          2. Removing objects from the planning scene
          3. Motion planning with point clouds
        5. The pick and place task
          1. The planning scene
            1. The target object to grasp
            2. The support surface
          2. Perception
          3. Grasping
          4. The pickup action
          5. The place action
          6. The demo mode
          7. Simulation in Gazebo
        6. Summary
      28. Index