Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Hands-On ROS for Robotics Programming

You're reading from   Hands-On ROS for Robotics Programming Program highly autonomous and AI-capable mobile robots powered by ROS

Arrow left icon
Product type Paperback
Published in Feb 2020
Publisher Packt
ISBN-13 9781838551308
Length 432 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Bernardo Ronquillo Japón Bernardo Ronquillo Japón
Author Profile Icon Bernardo Ronquillo Japón
Bernardo Ronquillo Japón
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Section 1: Physical Robot Assembly and Testing
2. Assembling the Robot FREE CHAPTER 3. Unit Testing of GoPiGo3 4. Getting Started with ROS 5. Section 2: Robot Simulation with Gazebo
6. Creating the Virtual Two-Wheeled ROS Robot 7. Simulating Robot Behavior with Gazebo 8. Section 3: Autonomous Navigation Using SLAM
9. Programming in ROS - Commands and Tools 10. Robot Control and Simulation 11. Virtual SLAM and Navigation Using Gazebo 12. SLAM for Robot Navigation 13. Section 4: Adaptive Robot Behavior Using Machine Learning
14. Applying Machine Learning in Robotics 15. Machine Learning with OpenAI Gym 16. Achieve a Goal through Reinforcement Learning 17. Assessment 18. Other Books You May Enjoy

Getting familiar with the embedded hardware

Do you remember which hardware is for what? The GoPiGo3 board is for interfacing with sensors and actuators, while Raspberry Pi is used for computing tasks. We will cover these topics in detail here.

The GoPiGo3 board

This customized board (https://www.dexterindustries.com/GoPiGo/learning/hardware-port-description/) provides the general features that are expected from a controller:

  • Real-time communication with sensors and actuators.
  • Interface input/output (I/O) through a serial peripheral interface (SPI) that feeds the data from the sensors to the Raspberry Pi and may also receive commands for the actuators (also from the Raspberry Pi, after running the logic in its CPU for every step of the control loop).
  • One single program loaded on board, known as the firmware. Since the goal of this software is to implement a communication protocol while the computer implements the logic, it doesn't need to be changed unless you decide to upgrade it when a new version is available.

Let's briefly explain the input/output interface protocol that we mentioned in the preceding bullet point list. SPI is a bus that's used to send data between microcontrollers and external devices, which are sensors, in our case. It uses separate clock and data lines, along with a select line to choose the device to talk to. The side of the connection that generates the clock is called the master, which is the Raspberry Pi in our case, while the other side is called the slave, which is the GoPiGo3 board. This way, both boards are synchronized, resulting in a faster form of communication than asynchronous serial, which is the typical communication protocol in general-purpose boards such as Arduino.

You can find out more about the SPI protocol in an easy-to-follow tutorial at https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi. Communication over SPI with the Raspberry Pi occurs through the headers interface, which can be seen in the top part of GoPiGo3 board in the following image. Only five out of the 40 GPIO pins are needed for such an interface:

Image courtesy: Dexter Industries: https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/07/GoPiGo3-Bottom_annotated-600x441.jpg

For interfacing with devices, the board provides the following (a top view of the board can be seen in the next diagram):

  • Two I2C ports—two Grove ports connected to the Raspberry Pi I2C bus through a level-conversion chip
  • One serial port—one Grove port connected to serial pins on the Raspberry Pi through a level-conversion chip
  • Two analog-digital ports—two Grove ports connected to the GoPiGo3 microcontroller
  • Two servo ports for the PWM type servomotor:
Image courtesy: Dexter Industries: https://32414320wji53mwwch1u68ce-wpengine.netdna-ssl.com/wp-content/uploads/2014/07/GoPiGo3-Top-768x565.jpg

Let's explain these new concepts:

  • Serial port: This is the complimentary communication protocol we mentioned previously when we talked about the SPI. While the last is synchronous (it needs five interface pins), the serial port is asynchronous—that is, there is no clock signal to follow and only two pins are needed: Tx for data transmission and Rx for data reception. In GoPiGo3, this port is directly connected to the Raspberry Pi serial pins through a level-conversion chip.
  • I2C ports: As its name suggests, this uses the I2C communication protocol. Just like SPI, it is a synchronous protocol, faster than asynchronous serial. I2C uses two lines, SDA for data and SCL for the clock signal. The third and fourth wires are for the power supply: VIN at 5V and the GND ground—that is, a 0V reference. SDA is bidirectional, so any of the connected devices can send or receive data. In these two ports, you will connect the distance sensor and the line follower sensor.
  • Analog-digital: These ports can connect to analog, digital, or I2C Grove devices. We will be connecting to one of the analog-digital port, the IMU sensor. We will talk about this in more detail later.
  • Servo ports, that connect PWM servomotors: These are cheaper and easier to control than encoder-equipped motors, all while offering enough accuracy to control the orientation of the support they will hold. In GoPiGo3, we can attach the distance sensor or the Pi camera to a servo motor. Pulse Width Modulation (PWM) technology refers to having control in a continuous range by changing the duty cycle of the voltage supply, resulting in an equivalent output ranging from 0V to 5V: 0V is the 0% duty cycle, while 100% corresponds to 5V being applied during the entirety of the cycle. By applying 5V for a percentage of the period lower than 100%, you get continuous control of the position, ranging from 0 to 180° rotation of the motor shaft. For an explanation about this, along with some useful figures, go to https://www.jameco.com/jameco/workshop/howitworks/how-servo-motors-work.html.

Raspberry Pi 3B+

Raspberry Pi has the largest community both in terms of education and the industry, which makes it the best single-board computer of choice when developing embedded software for robots or for Internet of Things (IoT) devices. The following image shows the Raspberry Pi 3B+, the most common model that powers GoPiGo3:

Image courtesy: https://en.wikipedia.org/wiki/File:Raspberry_Pi_3_B%2B_(39906369025).png, License CC BY-SA 2.0

The main characteristics of Raspberry Pi 3B+ are as follows:

  • A Central Processing Unit (CPU) composed of four Cortex-A53 1.4 GHz.
  • A Graphics Processing Unit (GPU) is a Broadcom VideoCore IV at 250 MHz.
  • The Synchronous Dynamic Random-Access Memory (SDRAM) is 1 GB, which is shared with the GPU.
  • On-board storage is provided through a MicroSDHC slot. You can choose whatever micro SD card size fits your needs. In any case, the general recommendation is to use a class-10 micro SD of 16 GB capacity—10 means that it is able to be written at 10 Mb/second.

Let's go over the functionality of each of these components:

  • The CPU provides the computation capacity to run all kinds of algorithms. This is where the intelligence of our robot resides.
  • The GPU's mission is to handle computer graphics and image processing. In our case, it will mostly be devoted to processing the images from the Pi camera and providing computer vision capabilities.
  • SDRAM has 1 GB volatile storage that's shared with the GPU, so this is a balance of how much memory you assign to the GPU (by default, it takes up to 64 Mb). RAM is where the program is loaded so that it can be executed.
  • On-board microSD card is the persistent storage that contains the operating system as well as all the installed software.

Raspberry Pi runs an operating system, typically a Linux-based distribution such as Debian or Ubuntu.

Although Raspbian—the Debian-based distro by the Raspberry Pi Foundation—is the official distribution, we will be using Ubuntu—supported by Canonical—because it's the platform that Open Robotics (https://www.openrobotics.org) uses to deliver a version of ROS every year, synchronized with the yearly versions of Ubuntu.

Why does a robot need a CPU?

Apart from the fact that this book's goal is to get you some hands-on experience with ROS—and for that, you need a Linux OS to install the software on—if you really want to create a smart robot, you need the processing capacity to run compute-intensive algorithms, and that is what a CPU such as Raspberry Pi provides.

Why is this computation needed? Because a smart robot has to integrate information from the environment with the logic of the task at hand to be able to complete it successfully. Let's use the example of carrying one object from its current position to a target destination. To do so, devices such as a laser distance sensor, a 3D camera, and/or a GPS provide the robot with information from the environment. These sources of data have to be combined so that the robot is able to locate itself in the environment. By supplying a target destination, it also has to compute the optimum path to carry the object on, something that it is called path planning. When executing such a path plan, it has to detect obstacles that may appear along the path and avoid them without losing focus of the goal. Hence, every step of the task involves executing an algorithm in the CPU of the robot.

This is one of the many practical scenarios that you will learn to solve using ROS, which is currently the de facto industry standard for the development of robotics applications.

You have been reading a chapter from
Hands-On ROS for Robotics Programming
Published in: Feb 2020
Publisher: Packt
ISBN-13: 9781838551308
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime