Python Robotics Projects
eBook - ePub

Python Robotics Projects

Build smart and collaborative robots using Python

Prof. Diwakar Vaish

Share book
  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

Prof. Diwakar Vaish

Book details
Book preview
Table of contents
Citations

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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
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 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
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 here.
Is Python Robotics Projects an online PDF/ePUB?
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.

Information

Year
2018
ISBN
9781788837149
Edition
1

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