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

Deep diving into the electromechanics

As explained in GoPiGo's official documentation (https://www.dexterindustries.com/GoPiGo/learning/technical-specifications-for-the-gopigo-raspberry-pi-robotics-kit/), the specifications of the GoPiGo3 robot are as follows:

  • Operating voltage: 7V-12V
  • External interfaces:
    • I2C ports: Two Grove ports connected to the Raspberry Pi I2C bus through a level-conversion chip
    • Serial ports: One Grove port connected to the serial pins on the Raspberry Pi through a level-conversion chip
    • Analog digital ports: Two Grove ports connected to the GoPiGo3 microcontroller
  • Encoders: Two magnetic encoders with six pulse counts per rotation (with 120:1 gear reduction for a total of 720 pulses per wheel rotation)
  • Wheels diameter: 66.5 mm
  • Distance between wheels: 117 mm
  • More: Design information is available at the official GitHub repository (https://github.com/DexterInd/GoPiGo3)

This is just a summary of what we explained in the section titled The GoPiGo3 board. In this section, we will concentrate on describing the devices that are connected to the GoPiGo3 board.

The most useful sensors

The sensors we are going to mount onto the GoPiGo3 are the ones that we need in order to accomplish the top-level task of the robot—that is, navigation with motion planning, while keeping costs low. These sensors are as follows:

  • Distance sensor
  • Line follower
  • Inertial Measurement Unit (IMU) sensor
  • 2D camera

In the case of using the line-follower sensor, since the robot will follow a marked path on the floor (usually painted in black), the motion-planning part can be skipped and navigation will be much easier. If there is an obstacle on the path, you will have to apply an algorithm to move around the obstacle and return to the path—that is, place the line-follower sensor above the black line again.

Now, we should take the time to understand what information each sensor provides. Later in this book, you will encounter such a navigation problem and the algorithms that can be used to implement it.

Distance sensor

The simple distance sensor allows us to measure the distance to the object in front of it. It has a small laser that measures the distance to an object. The sensor applies the time of flight method for a very fast and accurate distance reading. The product page can be viewed at https://www.dexterindustries.com/product/distance-sensor/:

Image courtesy: Dexter Industries: https://shop.dexterindustries.com/media/catalog/product/cache/4/image/1800x2400/9df78eab33525d08d6e5fb8d27136e95/d/e/dexter-industries-raspberry-pi-robot-distance-sensor-for-robots-front-of-sensor-1.jpg

You can connect the distance sensor to any of the two I2C ports. Be aware that the GoPiGo3 software libraries will not ask you to specify which of the two ports you are using. This will be detected automatically.

You can mount the sensor onto a servo package to scan a wide angle of about 180°. The servomotor can be connected to either servo port 1 or servo port 2. The product page can be viewed at https://www.dexterindustries.com/product/servo-package/:

Image courtesy: Modular Robotics: https://www.dexterindustries.com/wp-content/uploads/2019/09/GoPiGo3-Molded-Servo-Frontal-300x200.jpg

In Chapter 2, Unit Testing of GoPiGo3, there is a specific test you can run with your robot to check that this unit works properly.

Line follower

The line follower of GoPiGo3 is composed of six pairs of LED phototransistors. The LED emitter is the right-most part of each pair when you position the sensor in front of you to read the letters. This can be seen in the following photograph, which is a picture of the powered sensor, although you cannot yet see the LED light beams:

Why don't you see them in the picture? Because LEDs emit infrared light, which can't be detected by your eyes; however, it can be revealed by a phone camera (by default, the optics of these cameras do not include infrared filters). So, if, later on, you find that the line follower does not work properly, the first thing you must check is the hardware. To do this, simply take a photo with the camera app that ships with your smartphone.

In the following image, the sensor view has been intentionally blurred so that you can see the rays and confirm that the light beams come from the right-hand side of the LED phototransistor. The receiving part—that is, the phototransistor—is the component that detects whether there is reflected light coming from the LED emitter. The product page for this component can be viewed at https://www.dexterindustries.com/product/line-follower-sensor/:

Now, you are in a position to understand the working principles of the line-follower sensor:

  • If the rays are reflected off the floor because it is white, the phototransistor receives the mirrored beam and provides this information in the data sensor stream.
  • If the sensor is over a black surface, the phototransistor does not receive any reflected light and lets the robot know.

Reflection makes the sensor electronics report a signal close to 1 (white surface), while absorption provides a value close to 0 (black surface). But what if the sensor is far away from the floor or not facing it? Well, from the point of view of the sensor, absorption is equivalent to the lack of reflection. Therefore, the reported signal is close to zero. This property allows GoPiGo3 not only to follow a black path on the ground, but also to walk along edges avoiding drops that could damage the robot.

Since you have six pairs, you will have six signals, where each reports 0 or 1. These six numbers will allow us to infer how well centered the robot is over a black line. The sensor's specifications are as follows:

The following is a bottom view of the emitter-receiver. This face is the one that has to be a few millimeters above the floor to ensure a proper reflection of the LED's emission:

Image courtesy: Modular Robotics: https://shop.dexterindustries.com/media/catalog/product/cache/4/thumbnail/1800x2400/9df78eab33525d08d6e5fb8d27136e95/l/i/linefollower_bottom.jpg

The following image shows the line follower sensor mounted on the GoPiGo3 at the proper position—that is, above the floor:

Image courtesy: Modular Robotics: http://www.dexterindustries.com/wp-content/uploads/2019/03/linefollowerinaction.jpg

For instructions on how to assemble and calibrate the sensor, go to https://www.dexterindustries.com/GoPiGo/line-follower-v2-black-board-getting-started/. For connecting, you can use either of the two available I2C connectors on the line-follower sensor. Remember that one of them will be in use by the distance sensor.

The line follower can also be connected to one of the AD ports if you are using Raspbian For Robots (https://www.dexterindustries.com/raspberry-pi-robot-software/). It's for more advanced use, and coding for this setup is slightly different.

For the purposes of introducing robotics, we will take it easy by connecting the sensor to an I2C port and use the more friendly DexterOS (https://www.dexterindustries.com/dexteros/). In Chapter 2, Unit Testing of GoPiGo3, we will go over a specific test you can run with your robot to check that this unit works properly.

IMU sensor

The IMU sensor allows us to measure the orientation of the robot, as well as obtain an estimation of its position as it moves. The product page of the Dexter Industries IMU can be viewed at https://www.dexterindustries.com/product/imu-sensor/. The respective aspect of the sensor can be seen in the following image:

Image courtesy: Dexter Industries: https://shop.dexterindustries.com/media/catalog/product/cache/4/thumbnail/1800x2400/9df78eab33525d08d6e5fb8d27136e95/i/m/imu-sensor_mount2-800x800.jpg

In the following image, you can see it mounted on the GoPiGo3. To connect to the robot, you only have to plug it into either AD1 or AD2 on the GoPiGo board:

Image courtesy: Dexter Industries: https://shop.dexterindustries.com/media/catalog/product/cache/4/thumbnail/1800x2400/9df78eab33525d08d6e5fb8d27136e95/i/m/imu-sensor_gpg3_3.jpg

This IMU has nine degrees of freedom (DOF), plus temperature measurement capabilities. Let's talk about each sensor of the IMU and what kind of data they provide:

  • Let's start with the simpler one, the temperature. This provides the ambient room temperature and can be used in combination with the rest of the sensors to create, for example, a temperature map of a room, by taking measurements at several locations as the GoPiGo3 covers the surface.
  • The accelerometer is an absolute sensor because its value is always referred to as zero acceleration (static object). It provides a value for each of the three axes, X, Y, and Z:
    • It is good for measuring the inclination of the robot (an angle whose cosine is the vertical acceleration divided by the value of gravity = 9.81 m/s²) and the free-fall condition, which is equivalent to a 90° ramp and is a vertical wall (gravity is continuously detected by the sensor—that is, 9.81 m/s², if the object stays in a horizontal plane).
    • The accelerometer is not as accurate for the measurement of velocity because this value is not directly provided by the sensor. We can obtain it by performing the integral of the acceleration signal over time, which produces cumulative errors (drift), mainly coming from the sensor noise (electronics) and the measurement error itself. This is where the gyroscope comes into the picture to provide an accurate speed measurement.
    • The gyroscope is a differential sensor that provides the three rotations (X, Y, and Z axes) with respect to an arbitrary reference. What they really provide is the rotation velocity. This means that they are accurate for measuring rotation velocities, but not good for measuring angular position (you have to integrate of the speed signal over time, accumulating measurement errors and sensor noise, thereby producing drift).

A six-DOF IMU will be one that combines the accelerometer (three DOFs) and gyroscope (three DOFs):

  • The accelerometer accurately measures the inclination with respect to the vertical. It does not have drift in the medium/long term, but is not accurate for short-term measurements.
  • The gyroscope accurately measures rotation velocities, but they have drift. This means that they are not good for medium/long-term measurements.

By combining the six values from the accelerometer and gyroscope, it is possible to obtain an improved measurement of the orientation. This is expressed by means of the Euler angles—α, β, γas shown in the following diagram:

Image courtesy: https://commons.wikimedia.org/wiki/File:Euler_angles_zxz_int%2Baxes.png, License CC BY-SA 4.0

Something's that's more commonly used than the Euler angles are the Tait-Bryan version or navigation angles, roll-pitch-yaw, which can be defined as follows:

Image courtesy: https://es.m.wikipedia.org/wiki/Archivo:Flight_dynamics_with_text.png, License CC BY-SA 3.0

These angles are obtained by applying a special filter, called a complimentary filter, to the sensor's signals. It works like this:

  • For the signal from the accelerometer, it behaves as a low-pass filter since we trust its medium/long-term measurement.
  • For the signal from the gyroscope, it behaves as a high-pass filter since we trust its short-term measurement.

Mathematically, the complimentary filter is expressed as follows:

Here, A and B has to sum 1. These constants are determined by the calibration of the sensor, and typical values include A = 0.98, B = 0.02. The complimentary filter offers very similar results to the Kalman filter, which is the best linear (unbiased) estimator (BLE) but more computationally intensive.

Now, we have three rotations (about the X, Y, Z axes), but they are not absolute angles just yet:

  • Thanks to the accelerometer, the orientation with respect to the vertical is an absolute reference, but for the orientation on the horizontal plane we are lacking such a reference because the gyroscope is a differential sensor.
  • This is where the magnetometer appears to give us the orientation (three axes X, Y, Z) of the Earth's magnetic field.

Therefore, with our 6 + 3 = 9 DOFs IMU, we have the absolute orientation of our robot, with the gravity and the magnetic field vectors as references. In Chapter 2, Unit Testing of GoPiGo3, we'll go over a specific test you can run with your robot to check that this unit works properly.

Pi Camera

The Pi Camera is a custom 2D camera with a Camera Serial Interface (CSI). The following image shows the two physical components—that is, the camera's electronic board and a ribbon cable:

Image courtesy: https://commons.wikimedia.org/wiki/File:Raspberry_Pi_Camera_Module_v2_with_ribbon.jpg, License CC BY-SA 4.0

In the following image, we can see how the ribbon is connected to the CSI port of the Raspberry Pi:

Image courtesy: https://www.flickr.com/photos/nez/9398354549/in/photostream by Andrew, License: CC BY-SA 2.0

The Pi Camera is able to provide an HD resolution (1920 x 1080 pixels) up to a frame rate of 30 frames per second (FPS). You can find the possible configurations for this in the documentation at https://picamera.readthedocs.io/en/release-1.12/fov.html. In Chapter 2, Unit Testing of GoPiGo3, we'll go over a specific test that you can run with your robot to check that this unit works properly.

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