Python Robotics Projects
eBook - ePub

Python Robotics Projects

Build smart and collaborative robots using Python

Prof. Diwakar Vaish

Compartir libro
  1. 340 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Python Robotics Projects

Build smart and collaborative robots using Python

Prof. Diwakar Vaish

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Python Robotics Projects un PDF/ePUB en línea?
Sí, puedes acceder a Python Robotics Projects de Prof. Diwakar Vaish en formato PDF o ePUB, así como a otros libros populares de Computer Science y Hardware. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2018
ISBN
9781788837149
Edición
1
Categoría
Hardware

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...

Índice