Hands-On ROS for Robotics Programming

Book description

Take your ROS skills to the next level by implementing complex robot structures in a ROS simulation

Key Features

  • Learn fundamental ROS concepts and apply them to solve navigation tasks
  • Work with single board computers to program smart behavior in mobile robots
  • Understand how specific characteristics of the physical environment influence your robot's performance

Book Description

Connecting a physical robot to a robot simulation using the Robot Operating System (ROS) infrastructure is one of the most common challenges faced by ROS engineers. With this book, you'll learn how to simulate a robot in a virtual environment and achieve desired behavior in equivalent real-world scenarios.

This book starts with an introduction to GoPiGo3 and the sensors and actuators with which it is equipped. You'll then work with GoPiGo3's digital twin by creating a 3D model from scratch and running a simulation in ROS using Gazebo. Next, the book will show you how to use GoPiGo3 to build and run an autonomous mobile robot that is aware of its surroundings. Finally, you'll find out how a robot can learn tasks that have not been programmed in the code but are acquired by observing its environment. You'll even cover topics such as deep learning and reinforcement learning.

By the end of this robot programming book, you'll be well-versed with the basics of building specific-purpose applications in robotics and developing highly intelligent autonomous robots from scratch.

What you will learn

  • Get to grips with developing environment-aware robots
  • Gain insights into how your robots will react in physical environments
  • Break down a desired behavior into a chain of robot actions
  • Relate data from sensors with context to produce adaptive responses
  • Apply reinforcement learning to allow your robot to learn by trial and error
  • Implement deep learning to enable your robot to recognize its surroundings

Who this book is for

If you are an engineer looking to build AI-powered robots using the ROS framework, this book is for you. Robotics enthusiasts and hobbyists who want to develop their own ROS robotics projects will also find this book useful. Knowledge of Python and/or C++ programming and familiarity with single board computers such as Raspberry Pi is necessary to get the most out of this book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On ROS for Robotics Programming
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Code in Action
      4. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: Physical Robot Assembly and Testing
  7. Assembling the Robot
    1. Understanding the GoPiGo3 robot
      1. The robotics perspective
      2. The programming perspective
      3. Robot kit and resources
    2. Getting familiar with the embedded hardware
      1. The GoPiGo3 board
      2. Raspberry Pi 3B+
      3. Why does a robot need a CPU?
    3. Deep diving into the electromechanics
      1. The most useful sensors
        1. Distance sensor
        2. Line follower
        3. IMU sensor
        4. Pi Camera
    4. Putting it all together
    5. Quick hardware test
      1. Resources
      2. Getting started with DexterOS
      3. Coding with Bloxter
      4. Calibrating the robot
      5. Driving the robot
      6. Checking the sensors
      7. Shutting down the robot
    6. Summary
    7. Questions
    8. Further reading
  8. Unit Testing of GoPiGo3
    1. Technical requirements
    2. Getting started with Python and JupyterLab
      1. Launching JupyterLab for GoPiGo3
      2. Hardware testing
        1. Testing battery, LEDs, and motors/encoders
          1. Battery level
          2. Hardware information and current voltage levels
          3. LEDs and blinkers
          4. Motors and encoders test
    3. Unit testing of sensors and drives
      1. Quick start with sensors and motors
      2. Driving around
      3. Distance sensor
        1. Check port connections
        2. Distance sensor unit test
          1. GoPiGo3 API library
          2. DI sensors API library
      4. Servo package
        1. Servo package unit test
      5. Line follower
        1. Line follower unit test
      6. Inertial Measurement Unit (IMU)
        1. IMU unit test
      7. Raspberry Pi
        1. Pi unit test
      8. GoPiGo3 projects
    4. Summary
    5. Questions
    6. Further reading
  9. Getting Started with ROS
    1. Technical requirements
    2. ROS basic concepts
      1. The ROS graph
      2. roscore
      3. Workspaces and catkin
    3. Configuring your ROS development environment
      1. Installing ROS
        1. Ubuntu and ROS in the Raspberry Pi
      2. Integrated Development Environment (IDE)
        1. Installing RoboWare Studio
    4. Communication between ROS nodes – messages and topics
      1. Creating a workspace
        1. Creating a workspace and building it using RoboWare
      2. Setting up the ROS package
        1. Accessing package files and building the workspace using RoboWare
      3. A node publishing a topic
      4. A node that listens to the topic
      5. Combining the publisher and subscriber in the same node
    5. Using publicly available packages for ROS
    6. Summary
    7. Questions
    8. Further reading
  10. Section 2: Robot Simulation with Gazebo
  11. Creating the Virtual Two-Wheeled ROS Robot
    1. Technical requirements
    2. Getting started with RViz for robot visualization
    3. Building a differential drive robot with URDF
      1. Overview of URDF for GoPiGo3
      2. URDF robot body
        1. Caster
      3. The URDF model's left and right wheels
    4. Inspecting the GoPiGo3 model in ROS with RViz
      1. Understanding the roslaunch command
        1. Using Roboware to execute a launch file
      2. Controlling the GoPiGo3 robot's wheels from RViz
        1. Using the joint_state_publisher package
    5. Robot frames of reference in the URDF model
    6. Using RViz to check the model while building
      1. Changing the aspect of the model in the RViz window
      2. Helpful ROS tools for checking purposes
    7. Summary
    8. Questions
    9. Further reading
  12. Simulating Robot Behavior with Gazebo
    1. Technical requirements
    2. Getting started with the Gazebo simulator
    3. Making modifications to the robot URDF
      1. Extending URDF to produce an SDF robot definition
      2. Collisions and physical properties
      3. Gazebo tags
    4. Verifying a Gazebo model and viewing the URDF
      1. Launching the GoPiGo model in Gazebo
        1. Explaining configurable launch files using the <arg> tag
    5. Moving your model around
      1. Guidelines for tuning the Gazebo model
    6. Summary
    7. Questions
    8. Further reading
  13. Section 3: Autonomous Navigation Using SLAM
  14. Programming in ROS - Commands and Tools
    1. Technical requirements
    2. Setting up a physical robot
      1. Downloading and setting up Ubuntu Mate 18.04
      2. Access customization
        1. Updating your system and installing basic utilities
        2. Enabling SSH access
      3. Setting up a VNC server (x11vnc)
        1. Setting up autostart on boot
        2. Forcing the HDMI output and screen layout
      4. The Geany IDE
      5. Installing drivers for the GoPiGo3 and DI Sensors
      6. Setting up the Pi Camera
      7. Installing ROS Melodic
        1. Installing a Pi Camera ROS package
    3. A quick introduction to ROS programming
      1. Setting up the workspace
      2. Cloning a ROS package
      3. Our first execution of a ROS node
    4. Case study 1 – writing a ROS distance-sensor package
      1. Creating a new package
      2. Producing your source code
        1. Including the required libraries – rospy and msgs.msg
        2. Assigning a node name to the script
        3. Defining the publisher
        4. Setting up the msg_range object
        5. Changing units to the International System of Units
        6. Adding a measured distance and timestamp to the msg_range object
        7. Setting the reading frequency
        8. Running an infinite loop
        9. Publishing each new event
        10. Waiting until the next reading
        11. Launching the ROS execution environment
    5. Working with ROS commands
      1. Shell commands
        1. Changing the current location
        2. Listing files and folders inside a package
        3. Editing any file inside a package
      2. Execution commands
        1. The central process of the ROS environment
        2. Executing a single node
      3. Information commands
        1. Exploring topics
        2. Exploring nodes
        3. The rosmsg command
        4. The rosbag command
      4. Packages and the catkin workspace
    6. Creating and running publisher and subscriber nodes
    7. Automating the execution of nodes using roslaunch
    8. Case study 2 – ROS GUI development tools – the Pi Camera
      1. Analyzing the ROS graph using rqt_graph
      2. Displaying image data using rqt_image_view
      3. Graphing time series of sensor data with rqt_plot
      4. Playing a recorded ROS session with rqt_bag
        1. Distance sensor
        2. The Pi Camera
    9. Customizing robot features using ROS parameters
    10. Summary
    11. Questions
    12. Further reading
  15. Robot Control and Simulation
    1. Technical requirements
    2. Setting up the GoPiGo3 development environment
      1. ROS networking between the robot and the remote computer
        1. Communication between ROS environments
          1. Robot network configuration
          2. Laptop network configuration
        2. Launching the master node and connecting
    3. Case study 3 – remote control using the keyboard
      1. Running the gopigo3 node in the robot
        1. Inspecting published topics and messages
      2. Teleoperation package
      3. Running teleoperation on a laptop
        1. Teleoperation with the mouse
    4. Remote control using ROS topics
      1. The motion control topic – /cmd_vel
      2. Using /cmd_vel to directly drive GoPiGo3
      3. Checking the X, Y, and Z axes of GoPiGo3
      4. Composing motions
    5. Remotely controlling both physical and virtual robots
      1. Reverting the ROS master to the local computer
      2. Simulating GoPiGo3 with Gazebo
        1. Adding the controller to the Gazebo model of the robot
      3. Real-world and simulation at once
    6. Summary
    7. Questions
    8. Further reading
  16. Virtual SLAM and Navigation Using Gazebo
    1. Technical requirements
      1. ROS navigation packages
      2. ROS master running on the local computer
    2. Dynamic simulation using Gazebo
      1. Adding sensors to the GoPiGo3 model
        1. Camera model
          1. Simulating the camera
        2. Distance sensor
          1. Simulating the distance sensor
    3. Components in navigation
      1. Costmaps for safe navigation
    4. Robot perception and SLAM
      1. Adding a Laser Distance Sensor (LDS)
        1. Simulating the LDS
      2. SLAM concepts
        1. Occupancy Grid Map (OGM)
        2. The SLAM process
        3. The navigation process
    5. Practising SLAM and navigation with the GoPiGo3
      1. Exploring the environment to build a map using SLAM
      2. Driving along a planned trajectory using navigation
    6. Summary
    7. Questions
    8. Further reading
  17. SLAM for Robot Navigation
    1. Technical requirements
      1. Setting the ROS master to be in the robot
    2. Preparing an LDS for your robot
      1. Setting up YDLIDAR
        1. Integrating with the remote PC
        2. Running the YDLIDAR ROS package
      2. Integrating with Raspberry Pi
        1. Checking that YDLIDAR works with GoPiGo3
        2. Visualizing scan data in the Raspberry Pi desktop
        3. Grouping launch files
        4. Visualizing scan data from the remote laptop
      3. Processing YDLIDAR data from a remote laptop
    3. Creating a navigation application in ROS
    4. Practicing navigation with GoPiGo3
      1. Building a map of the environment
      2. Navigating GoPiGo3 in the real world
    5. Summary
    6. Questions
    7. Further reading
  18. Section 4: Adaptive Robot Behavior Using Machine Learning
  19. Applying Machine Learning in Robotics
    1. Technical requirements
    2. Setting up the system for TensorFlow
      1. Installing pip
        1. Installing the latest version
      2. Installing TensorFlow and other dependencies
      3. Achieving better performance using the GPU
    3. ML comes to robotics
      1. Core concepts in ML
        1. Selecting features in ML
      2. The ML pipeline
    4. From ML to deep learning
      1. ML algorithms
        1. Regression
        2. Logistic regression
        3. Product recommendation
        4. Clustering
        5. Deep learning
      2. Deep learning and neural networks
        1. The input layer
        2. The hidden layer(s)
        3. The output layer
    5. A methodology to programmatically apply ML in robotics
      1. A general approach to application programming
      2. Integrating an ML task
    6. Deep learning applied to robotics – computer vision
      1. Object recognition in Gazebo
      2. Object recognition in the real world
    7. Summary
    8. Questions
    9. Further reading
  20. Machine Learning with OpenAI Gym
    1. Technical requirements
    2. An introduction to OpenAI Gym
      1. Installing OpenAI Gym
        1. Without Anaconda (optional)
        2. Installing gym in development mode (optional)
      2. Installing OpenAI ROS
      3. Agents, artificial intelligence, and machine learning
      4. The cart pole example
        1. Environments
        2. Spaces
        3. Observations
        4. Running the full cart pole example
      5. Q-learning explained – the self-driving cab example
        1. How to run the code for the self-driving cab
        2. Reward table
        3. Action space
        4. State space
        5. Self-driving cab example using the RL algorithm
        6. Evaluating the agent
        7. Hyperparameters and optimization
    3. Running an environment
    4. Configuring the environment file
    5. Running the simulation and plotting the results
      1. Checking your progress with the logger
    6. Summary
    7. Questions
    8. Further reading
  21. Achieve a Goal through Reinforcement Learning
    1. Technical requirements
    2. Preparing the environment with TensorFlow, Keras, and Anaconda
      1. TensorFlow backend
      2. Deep learning with Keras
      3. ROS dependency packages
    3. Understanding the ROS Machine Learning packages
      1. Training scenarios
      2. ROS package structure for running a reinforcement learning task
    4. Setting the training task parameters
    5. Training GoPiGo3 to reach a target location while avoiding obstacles
      1. How to run the simulations
      2. Scenario 1 – travel to a target location
      3. Scenario 2 – travel to a target location avoiding the obstacles
        1. Testing the trained model
    6. Summary
    7. Questions
    8. Further reading
  22. Assessment
    1. Chapter 1: Assembling the Robot
    2. Chapter 2: Unit Testing of GoPiGo3
    3. Chapter 3: Getting Started with ROS
    4. Chapter 4: Creating the Virtual Two-Wheeled ROS Robot
    5. Chapter 5: Simulating Robot Behavior with Gazebo
    6. Chapter 6: Programming in ROS - Commands and Tools
    7. Chapter 7: Robot Control and Simulation
    8. Chapter 8: Virtual SLAM and Navigation Using Gazebo
    9. Chapter 9: SLAM for Robot Navigation
    10. Chapter 10: Applying Machine Learning in Robotics
    11. Chapter 11: Machine Learning with OpenAI Gym
    12. Chapter 12: Achieve a Goal through Reinforcement Learning
  23. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On ROS for Robotics Programming
  • Author(s): Bernardo Ronquillo Japon
  • Release date: February 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781838551308