Python Robotics Projects
eBook - ePub

Python Robotics Projects

Build smart and collaborative robots using Python

  1. 340 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Python Robotics Projects

Build smart and collaborative robots using Python

About this book

Leverage the power of Python to build DIY robotic projectsAbout This Book• Design, build, and stimulate collaborative robots• Build high-end robotics projects such as a customized personal Jarvis• Leverage the power of Python and ROS for DIY robotic projectsWho This Book Is ForIf building robots is your dream, then this book is made for you. Prior knowledge of Python would be an added advantage. What You Will Learn• Get to know the basics of robotics and its functions• Walk through interface components with microcontrollers• Integrate robotics with the IoT environment• Build projects using machine learning• Implement path planning and vision processing• Interface your robots with BluetoothIn DetailRobotics 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.Style and approachA simple step-by-step guide to help you learn the concepts of robotics using simple to advanced steps. You'll not only learn the concepts of AI, machine learning, and Vision Processing, but also how to practically implement them in your projects.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Recognizing Humans with Jarvis

By now we have understood in the last chapter how multiple layers of conditions can be clubbed together to get the functionality that is desired. We have just completed the first step in making Jarvis work for you. Now, it's time to make it even more capable.
In this chapter, we will make it control more electronics at your home, which can be controlled autonomously without you telling anything to the system. So without delay, let's get straight into it and see what we have in our bucket.

Turn on the light Jarvis

One of the basic functionalities of a smart home is to turn on the lights for you whenever you are around. It is one of the most basic things that any system can do for you. We will start off by turning on the light as soon as you come inside the room, thereafter, we will make the system more and more intelligent.
So, the first thing we need to do is recognize whether you are in a room or not. There are multiple ways to do that. One important characteristic of life is the presence of movement. You may say plants don't move, well they do; they grow, don't they? So detecting movement can be a key step in detecting whether someone is there or not!
This step will not be so difficult for you, as we have already interfaced this sensor previously. We are talking about the good old PIR sensor. So the sensor will sense any movement in the area. If there is any movement, then Jarvis will switch on the lights. I am sure this is something you can do by yourself by now. You can still refer to the code and the circuit diagram here:
Now upload the following code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
PIR = 24
LIGHT = 23
GPIO.setup(DOPPLER,GPIO.IN)
GPIO.setup(BUZZER,GPIO.OUT)
While True:
if GPIO.input(PIR) == 1:
GPIO.output(LIGHT,GPIO.HIGH)
if GPIO.input(PIR) == 0:
GPIO.output(LIGHT,GPIO.LOW)
In the preceding code, we are simply turning on the light as soon as the motion is detected, but the problem is that it will only switch on the light for the time the motion is there. What does that mean? Simple, while there is some movement, will keep the lights on and as soon as the movement stops, it will switch off the light.
This can be a very good code for a person who wants to lose weight, but for most of us, it will be annoying. So, let's include a small loop, which we have used in the previous chapter and make this a little better:
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

PIR = 24
LIGHT = 23
TIME = 5

GPIO.setup(PIR,GPIO.IN)
GPIO.setup(BUZZER,GPIO.OUT)

While True:

If GPIO.input(PIR) == 1:

M = datetime.datetime.now().strftime('%M')
M_final= M + TIME

for M < M_final:

GPIO.output(LIGHT,GPIO.HIGH)
M = datetime.datetime.now().strftime('%M')

if GPIO.input(PIR) == 1:
M_final = M_final + 1



if GPIO.input(PIR) = 0:

GPIO.output(LIGHT, GPIO.LOW)}
So, in this program, all we have done is we have added a for loop, which switches on the light for a set amount of time. How long that time will be can be toggled by changing the value of the variable TIME.
There is one more interesting part in that loop which is as follows:
 if GPIO.input(PIR) == 1
M_final = M_final + 1
Why did we do this you might wonder? Whenever the light will be switched on, it will remain on for 5 minutes. Then, it will switch off and wait for movement to occur. So, essentially, the problem with this code will be that if you are in the room and the light switches on, then for 5 minutes it will see if there is any motion detected or not. There is a chance that you will be in motion when it searches for the motion after 5 minutes. But for most of the time, it won't be the case. So we are detecting the movement using the PIR sensor. Whenever movement is detected, the value of M_final is incremented using the line M_final = M_final + 1, thereby increasing the time until which the light will be switched on.

Understanding motion

By now you must have figured that the PIR sensor is not the most idealistic sensor for us to switch the lights on or off. Mostly because, although the motion is one of the best indicators of presence, there can be times when you might not move at all, for example, while resting, reading a book, watching a movie, and so on.
What do we do now? Well, we can do a little trick. Remember in the last chapter we used our proximity sensor to sense whether a person has crossed a specific area or not? We will implant a similar logic here; but rather than just copy pasting the code, we will improve it and make it even better.
So rather than using one single IR proximity sensor, we will be using two of these things. The mounting will be as shown in the following diagram:
Now it is very evident that whenever a person walks in from the door side to the room side the Sensor 1 will show a lower reading when detecting a body. Then, while he is walking towards the room side, Sensor 2 will show a similar reading.
If first Sensor 1 is triggered and thereafter Sensor 2 is triggered, then we can safely assume that the person is travelling from the door side to the room side. Similarly, if the opposite is happening, then it is understood that the person is walking out of the room.
Now, this is fairly simple. But how do we implement it in a real-life situation? Firstly, we need to connect the circuit as follows:
Once that is done, upload the following code:
import GPIO library
import RPi.GPIO as GPIO
impor...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Robotics 101
  7. Using GPIOs as Input
  8. Making a Gardener Robot
  9. Basics of Motors
  10. Making a Pet Feeding Robot
  11. Bluetooth-Controlled Robotic Car
  12. Sensor Interface for Obstacle Avoidance
  13. Making Your Own Area Scanner
  14. Vision Processing
  15. Making a Guard Robot
  16. Basic Switching
  17. Recognizing Humans with Jarvis
  18. Making Jarvis IoT Enabled
  19. Giving Voice to Jarvis
  20. Gesture Recognition
  21. Machine Learning
  22. Gesture-Controlled Robotic Vehicle
  23. Making a Robotic Arm
  24. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Python Robotics Projects by Prof. Diwakar Vaish in PDF and/or ePUB format, as well as other popular books in Computer Science & Hardware. We have over one million books available in our catalogue for you to explore.