Book Image

Python Robotics Projects

By : Prof. Diwakar Vaish
Book Image

Python Robotics Projects

By: Prof. Diwakar Vaish

Overview of this book

Robotics is a fast-growing industry. Multiple surveys state that investment in the field has increased tenfold in the last 6 years, and is set to become a $100-billion sector by 2020. Robots are prevalent throughout all industries, and they are all set to be a part of our domestic lives. This book starts with the installation and basic steps in configuring a robotic controller. You'll then move on to setting up your environment to use Python with the robotic controller. You'll dive deep into building simple robotic projects, such as a pet-feeding robot, and more complicated projects, such as machine learning enabled home automation system (Jarvis), vision processing based robots and a self-driven robotic vehicle using Python. By the end of this book, you'll know how to build smart robots using Python.
Table of Contents (24 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Preface

In this book, you will learn the basics of robotics using Raspberry Pi as our hardware and Python as our programming language. The projects we undertake will help readers to understand the basics of the language and the hardware we are using. The technologies we are exploring in this book are the ones that act as a baseline for most of the robots we use. By going through this book, readers will not only understand how to make the projects mentioned in this book but also move a step ahead and give shape to their imagination. In this book, we will be using very cheap hardware and software that are open source, making it easy to afford. In this, we will start with Python, so even a 12-year-old will be able to understand and implement it. Besides this, we will be exploring different hardware and their working principle so that you just don't interface the hardware but get to know it to the most minute detail. For those who have a will to explore robotics using the latest technology and language, this could be the perfect place to start. 

Who this book is for

This book is for those who have a will to learn robotics and get familiar with the latest technology using the latest programming language. Age is no limit whether you are 12 years young or 60 years old; you can read this book and convert your ideas into reality. 

What this book covers

Chapter 1, Robotics 101, will make you understand the basics of our hardware and Python. Using simple LEDs, we will start to make simple programs in Python.

Chapter 2, Using GPIOs as Input, will discuss how to connect various sensors, starting with interfacing a switch through an ultrasonic range finder and finally to a light sensor (LDR) using an analog-to-digital converter. 

Chapter 3, Making a Gardener Robot, will use various sensors, such as a soil humidity sensor, and a temperature sensor to sense the climate, and using a solenoid valve controlled by a relay, we will be making a robot that waters the garden whenever required. 

Chapter 4, Basics of Motors, will discuss the working of motor and how it can be driven by a motor driver, how a full H bridge motor driver works, and also how the speed control mechanism works in the motor driver. While doing all this, we will control a motor and make it move in a different direction at different speeds. 

Chapter 5, Making a Pet Feeding Robot, will teach you how to make a robot that will feed your pet whenever you have programmed it using motors and other sensors. It would also sense if the pet is there or not, and until such time as the pet eats its food, the buzzer will always be left on to make sure that the pet understands that the food is dispensed. Also, using force sensors, we will be able to make out how much food has been eaten. After a sufficient quantity of food has been consumed, the buzzer will be deactivated.

Chapter 6, Bluetooth-Controlled Robotic Car, will teach more about steering and controlling a robotic vehicle, and the concepts of a skid-steer mechanism will be implemented. You will also learn how to use the Bluetooth onboard our Raspberry Pi and connect it to your mobile phone. Finally, using an app, we will control our robotic vehicle using our mobile phone. 

Chapter 7,Sensor Interface for Obstacle Avoidance, will provide an insight into  how we can use IR proximity sensors to determine distances. Also, we will make smart algorithms to sense distance on all sides and then move in the direction where the distance is greatest. 

Chapter 8, Making Your Own Area Scanner, will teach you the basics of servo motors and how they can be controlled. Using servo motor, we will make an area scanner, in other words, a homemade LIDAR. Using this home-built sensor, we would make a self-navigating car. 

Chapter 9, Vision Processing, will teach you how to prepare the Raspberry Pi to capture images using the camera and how processing takes place. 

Chapter 10, Making a Guard Robot, will teach you how to make a vision processing powered system that will be able to recognize faces using insights from the previous chapter. It would then be trained to recognize a specific face and react differently when it recognizes the face familiar to it. Finally, we will make a guard robot that will guard your house; when it recognizes your face, it will let you in. If it recognizes an unknown face, then it will raise an alarm. 

Chapter 11, Basic Switching, will control the equipment at your home with simple logic. Finally, we will make an alarm that will wake you up in the natural way by lights. This will have a smart automatic snooze.

Chapter 12, Recognizing Humans with Jarvis, will teach you how to control devices at your home with a room occupancy sensor that we will build at home using an IR proximity sensor. We will then make this occupancy sensor smart and ready to count the number of people in the room and only switch off the lights or other equipment once no one is left in the room. 

Chapter 13, Making Jarvis IoT Enabled, will provide you with insights into the concepts of IoT and MQTT server through which we will be able to monitor our home based on events. Also, you will learn how to control the devices in our home while sitting anywhere in the world. 

Chapter 14, Giving Voice to Jarvis, will teach you how the system can be made capable of synthesizing speech. Also, you will learn how you can make the system recognize our speech, and based on it, everything in the home can be controlled. 

Chapter 15, Gesture Recognition, will make you identify the gestures made on the board using electric waves, and based on those gestures, the smart home will be controlled. 

Chapter 16, Machine Learning, will make you understand the concepts of machine learning and especially the k-nearest algorithm. Using this algorithm, you will understand how data can be given to the system and predictions can be made based on it . Finally, you will execute a program to generate its own data by the inputs of the users over the course of time, and based on that data, it will start automatically controlling the home without any human intervention.

Chapter 17, Gesture-Controlled Robotic Vehicle, will teach you how to build a robot that will be controlled based on the tilt of your hand. The concepts of accelerometer and gyroscope will be understood and implemented. 

Chapter 18,Making a Robotic Arm,will help you make a robotic hand. You will understand how to set the physical limits of the servos for protection purposes, and we will then make a program in which you will control the robot will be controlled based on different frames. Finally, you will go ahead and understand how to control speed of motion of the robot.  

To get the most out of this book

There is no need of prior Python knowledge though having a prior experience will accelerate your learning curve. Readers will have to download and install RASPBIAN STRETCH WITH DESKTOP; this will give us the GUI interface for Raspberry Pi.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the on-screen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Python-Robotics-Projects. In case, there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it from https://www.packtpub.com/sites/default/files/downloads/PythonRoboticsProjects_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "We have to multiply 2 and 3 we simply write Multiply(2,3)."

A block of code is set as follows:

import RPi.GPIO as GPIO
from time import sleep 
GPIO.setmode(GPIO.BOARD) 
GPIO.setup(23,GPIO.OUT) 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

import RPi.GPIO as GPIO
from time import sleep 
GPIO.setmode(GPIO.BOARD)
GPIO.setup(23,GPIO.OUT) 

Any command-line input or output is written as follows:

sudo apt-get update
sudo apt-get upgrade

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Then select I2C to enable it. Then select Yes."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.