(FREE PDF Sample) Beginning Robotics With Raspberry Pi and Arduino: Using Python and OpenCV 2nd Edition Jeff Cicolani Ebooks
(FREE PDF Sample) Beginning Robotics With Raspberry Pi and Arduino: Using Python and OpenCV 2nd Edition Jeff Cicolani Ebooks
com
https://textbookfull.com/product/beginning-
robotics-with-raspberry-pi-and-arduino-using-
python-and-opencv-2nd-edition-jeff-cicolani-2/
https://textbookfull.com/product/beginning-robotics-with-raspberry-pi-
and-arduino-using-python-and-opencv-2nd-edition-jeff-cicolani/
textbookfull.com
https://textbookfull.com/product/beginning-robotics-with-raspberry-pi-
and-arduino-using-python-and-opencv-2nd-edition-jeff-cicolani-2/
textbookfull.com
https://textbookfull.com/product/consolidated-b-24-liberator-1st-
edition-edward-shacklady/
textbookfull.com
Cornerstones of financial accounting Fourth Edition Jay S.
Rich
https://textbookfull.com/product/cornerstones-of-financial-accounting-
fourth-edition-jay-s-rich/
textbookfull.com
https://textbookfull.com/product/digital-twin-driven-smart-design-1st-
edition-fei-tao-editor/
textbookfull.com
https://textbookfull.com/product/sql-in-10-minutes-a-day-sams-teach-
yourself-5th-edition-ben-forta/
textbookfull.com
https://textbookfull.com/product/the-palgrave-handbook-of-wine-
industry-economics-adeline-alonso-ugaglia/
textbookfull.com
https://textbookfull.com/product/3d-photorealistic-rendering-
volume-1-interiors-exteriors-with-v-ray-3ds-max-1st-edition-cardoso/
textbookfull.com
TECHNOLOGY IN AC TION™
Beginning Robotics
with Raspberry Pi
and Arduino
Using Python and OpenCV
—
Second Edition
—
Jeff Cicolani
Beginning Robotics
with Raspberry Pi
and Arduino
Using Python and OpenCV
Second Edition
Jeff Cicolani
Beginning Robotics with Raspberry Pi and Arduino: Using Python
and OpenCV
Jeff Cicolani
Pflugerville, TX, USA
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
Index�������������������������������������������������������������������������������������������������349
x
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
About the Author
Jeff Cicolani currently lives in the Austin,
Texas, area with his wife, two dogs, and
dozen or so robots. He is currently working
as an embedded systems engineer, building
robotic and automated platforms for an AI
(artificial intelligence) company in Austin.
His journey to robotics was circuitous, taking
him through an odd career path that included
systems analysis and design and database
programming. In 2012, he joined The Robot
Group in Austin, where he joined a group of
robotics enthusiasts and began building robots as a hobby. In 2016, he
became president of The Robot Group. In this role, he leads the group in
their mission to promote STEM (science, technology, engineering, and
mathematics) education through robotics. He is currently working to
develop a better understanding of advanced robotics through ROS
(Robot Operating System) and machine learning.
xi
About the Technical Reviewer
Massimo Nardone has more than 22 years
of experience in security, web/mobile
development, cloud, and IT architecture. His
true IT passions are security and Android.
He has been programming and teaching
how to program with Android, Perl, PHP, Java,
VB, Python, C/C++, and MySQL for more than
20 years.
He holds a Master of Science degree in
Computing Science from the University of
Salerno, Italy.
He has worked as a project manager, software engineer, research
engineer, chief security architect, information security manager, PCI/
SCADA auditor, and senior lead IT security/cloud/SCADA architect for
many years.
xiii
Introduction
Robotics does not have to be difficult. In this book, I introduce you to the
field of robotics. The journey will be challenging; it’s intended to be. But
by the end of the book, you will have hands-on exposure to many of the
fundamental—and not so fundamental—aspects of robotics. You will work
with hardware, assemble and solder a circuit board, write code in two
programming languages, install and configure a Linux environment, and
work with computer vision. Everything else you do with robots will be an
extension of the lessons learned in this book.
xv
Introduction
This book is also for the student who wants to take their robot-building
experience beyond bricks and puzzle-piece programming, someone who
wants to work with hardware and software that more closely resembles
what they might see in college or in the professional world.
No assumptions are made about experience or background in
technology. As you go through the chapters, you may find parts that you
are already familiar with and you can skip ahead. But if you are new to
these topics, I try to provide you with a quick but easy introduction.
C
hapter Overview
You start by learning about the Raspberry Pi and how to work with it.
You download and install the Raspbian operating system (OS) and then
configure the Pi for our project. The goal is to set up your system to be able
to easily access your robot and write your code directly on it.
Once you are able to access your Pi remotely, in Chapter 3, you delve
into programming with Python. I show you how to write simple programs
on the Raspberry Pi. I also take you beyond the basics and cover some
intermediate topics, such as modules and classes. This is one of the longest
chapters since there is a lot of material to cover.
From there, you learn how to interface the Raspberry Pi with external
electronics, such as sensors and LEDs, through the Pi’s GPIO (general-
purpose input/output) header. Chapter 4 discusses the different ways
of addressing the pins on the header, some of the functionality exposed
through the header, and how to use an ultrasonic rangefinder to detect
objects. This gets you ready for the next chapter, which introduces the
Arduino.
In Chapter 5, you connect the Arduino to the Raspberry Pi. I discuss
some of the reasons you want to do this. I show you how to work with the
Arduino IDE (integrated development environment) to write programs.
xvi
Introduction
I cover serial communication between the two boards and how to pass
information back and forth between them. We do this using the same
ultrasonic rangefinder used in the previous chapter.
Chapter 6 has you turning motors with your Raspberry Pi. You use a
special board called a hat, or plate, to control the motors. This is where I
introduce another skill that you will inevitably need in robotics: soldering.
The header and terminals need to be soldered onto the board that was
selected for this purpose. The nice thing about soldering headers and
terminal blocks is that it’s hard to damage anything, and you will get plenty
of practice.
Chapter 7 is where we bring it all together. You build the robot, and I
discuss some of the physical characteristics of robotics. I cover some of
the design considerations that you will need to keep in mind when you
design your own chassis. Although I am listing a specific chassis kit for this
project, you do not need to use the same one. In fact, I encourage you to
explore other options to find the one that is right for you.
In Chapter 8, I introduce another type of sensor—the IR sensor—and
I show you how to use a very common control algorithm called a PID
(proportional, integral, and derivative) controller. I talk about the various
types of IR sensors and where you want to use them. This chapter also
discusses what PID control is and why you want to use it.
Chapter 9 is about computer vision, where you see the true power of
the Raspberry Pi. In this chapter, I cover an open source package called
OpenCV. By the end of this chapter, your little robot will be chasing a ball
around the table.
I leave you with some parting thoughts in Chapter 10. I provide a few
tips that I picked up, and I give you a glimpse into my workflow and tools.
After that, you will be ready to begin your own adventures in robotics.
xvii
Introduction
xviii
CHAPTER 1
Introduction
to Robotics
The word robotics can mean a lot of things. For some people, it is anything
that moves by itself; kinetic art is robotics. To other people, robotics means
something that is mobile or something that can move itself from place to
place. There is actually a field called mobile robotics; automatic vacuum
cleaners, such as a Roomba or a Neato, fall into this category. To me,
robotics falls somewhere in between kinetic art and mobile robotics.
A robot is technology that applies logic to perform a task in an
automated manner. This is a fairly broad definition, but robotics is a fairly
broad field. It can cover everything from a child’s toy to the automatic
parallel parking capabilities in some automobiles. We build a small mobile
robot in this book.
Many of the principles that you are exposed to in this book are easily
transferable to other areas. In fact, we will go through the entire process
of building a robot from beginning to end. A little later in this chapter, I go
over the project that we will build. At that time, I will provide a list of the
parts used in this book. These parts include sensors, drivers, motors, and
so forth. You are welcome to use whatever you have on hand because, for
the most part, everything we go through in this book can be applied to
other projects.
Robotics Basics
I like to tell people who are new to robotics, or are just robotics curious,
that a robot consists of three elements:
2
Chapter 1 Introduction to Robotics
3
Chapter 1 Introduction to Robotics
S
ensors and GPIO
GPIO stands for general-purpose input/output. It represents all the various
connections to devices. The Raspberry Pi has a lot of GPIO options: HDMI,
USB, audio, and so forth. However, when I talk about GPIO in this book, I’m
generally referring to the 40-pin GPIO header. This header provides direct
access to most of the board’s functionality. I discuss this in Chapter 2.
Arduino also has GPIO. In fact, one could argue that Arduino is all
GPIO and nothing else. This isn’t far from the truth given that all the other
connections are there to allow you to communicate with and power the
AVR chip at the heart of the Arduino.
4
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 Introduction to Robotics
All of these headers and GPIO connections are there so we can access
sensors outside the boards themselves. A sensor is a device that gathers
data. There are many different types of sensors, and all serve a purpose.
Sensors can be used for detecting light levels, the range to an object,
temperature, speed, and so forth. In particular, we will use GPIO headers
with an ultrasonic rangefinder and an IR detector.
M
otion and Control
One thing that most definitions of a robot have in common is that it needs
to be able to move. Sure, you can have a robot that doesn’t actually move,
but this type of device generally falls under the moniker of IoT, the Internet
of Things.
There are many ways to add motion to your project. The most common
is the use of motors. But you can also use solenoids, air, or water pressure.
I discuss motors more in Chapter 6.
Although it is possible to drive a motor directly off a Raspberry Pi
or an Arduino board, it is strongly discouraged. Motors tend to draw
more current than the processors on the boards can handle. Instead,
it is recommended that you use a motor controller. Like motors, motor
controllers come in many forms. The motor control board that we will use
is accessed through the Raspberry Pi’s header. I also discuss how to drive
motors with an L298N dual motor controller.
5
Chapter 1 Introduction to Robotics
6
Chapter 1 Introduction to Robotics
there are a few places where it does not excel. One area is interfacing with
external devices. It can work with sensors and external devices, but the
Arduino does this much better.
Arduino is another small processing device that is readily available and
easy to use. Unlike a Raspberry Pi, however, it does not have the capacity
for a full operating system. Rather than running a microprocessor like the
ARM, it uses a different type of chip called a microcontroller. The difference
is that a microcontroller is specifically designed to interact with sensors,
motors, lights, and all kinds of devices. It directly interacts with these
external devices. The Pi works through many layers of processing before it
ever reaches the pins that a device is connected to.
By combining the Raspberry Pi and the Arduino, we are able to
leverage what each does best. The Raspberry Pi offers the high-level
processing power of a full computer. Arduino provides the raw control over
external devices. The Pi allows us to process a video stream from a simple
USB camera, whereas the Arduino allows us to gather the information
from the various sensors and apply logic to make sense of all that data and
then return concise findings to the Pi.
You will learn more about the Raspberry Pi in Chapter 2. Later on, you
will connect an Arduino to the Pi and learn about programming it, as well
as how to pass information back and forth between the Arduino and the Pi.
P
roject Overview
In this book, we will build a small mobile robot. The robot is designed to
demonstrate the lessons that you learn in each chapter. However, before
we can actually build the robot, we need to cover a lot of material and lay
the foundation for future lessons.
7
Chapter 1 Introduction to Robotics
T he Robot
The robot that we will build is a small two- or four-wheeled autonomous
rover. It will be able to detect obstacles and the edge of a table and to
follow a line. The chassis that I selected is a four-wheeled robot, but there
are other designs suitable for this project (see Figures 1-3 and 1-4).
Figure 1-3. The front of our robot shows the ultrasonic sensors and Pi
T-Cobbler on a breadboard
Figure 1-4. The back of our robot shows the Raspberry Pi and motor
control board
8
Chapter 1 Introduction to Robotics
Although I provide a list of the parts that I used for the project, you are
welcome to use whatever parts you wish. The important thing is that they
behave in a similar manner as those I have listed.
9
Random documents with unrelated
content Scribd suggests to you:
Ven estampes y joguines
y llibrets de la passió.
Compareix la masovera
ab el seu menut a bras.
Ell se fa una mica enrera.
Ella avensa un altre pas.
Ja li ven escapularis
y dos ciris benehits,
confegint-li dos rosaris
que tenia mitg-partits.
Ja arreplega la capella
y'ls hi dona l'adeussiau.
Del portal se'l guaiten ella
y el menut cara-babau.
Mossa d'hostal
El bort
El vell
Mitgdiada eterna
Tragedia lluminosa
II.
A la masia
Posta arbitraria
Demunt la llar pairal
hi llengoteja el foc
qui ressegueix d'un soc
l'escorsa desigual.
A fora, esclata el xoc
suprem del temporal.
Sona confós el toc
de l'hora capvespral.
Quan les vaixelles tosques
reflexen a les fosques
el llengotetg qui mor,
la cuina llu clapada
com entre la brancada
llunyana posta d'or.
Rebost
Cambra
Porxo
Els pallers
Al fidelíssim ca
Oh fidelíssim ca
qui pagues les marfugues
del amo! cinc verrugues
t'enjoien. Al lladrar,
lladres tant fort y clar
y ab tanta bonhomia,
que'l teu lladruc desnia
un sentiment humà.
Soportes la mainada,
respectes la llocada,
dormites vora el foc,
convius ab tos col·legues,
els plats de cuina fregues
y no fas nosa enlloc.
El reial paó
Bell paó
radiant!
ets l'encant
del pastor.
Mostra, aurífic,
ton ventall,
geroglífic
devassall.
Per ta rara
petulància,
tens encara
l'elegància
que no sent
nostra gent.
L'horta
El veinat
I.
II.
A'l bany
Visió tardoral
En un decliu suavíssim, la prada, encara verda,
l'exuberància mostra de suculent pastura.
Les vaques s'hi rabegen ab l'herba a la cintura,
fregant ab les mamelles l'exuberància gerda.
Una pomera ostenta la soca ab una esquerda
del llamp, y dues branques socarrimades, mortes.
Mes son de tantes pomes les altres tres colltortes,
que besen ab les fulles els trèbols y l'userda.
Els penjarells qui branden, acurullats de pomes,
entre el fullatge brillen com ponentines bromes.
La copa's balandreja com femení ventall.
Y algunes pomes cauen com un aucell morent
qui, rodolant per l'herba, s'obra cami, talment.
Y tomben dins de l'aigua, perdent-se rec avall.
La càndida badella
Oh càndida badella!
com un segell sagrat
de ta nobilitat,
al front dus una estrella.
Ta vista s'esparpella
ab diafanitat.
Tremoles de novella
y saltes de bondat.
Y tens el morro encara
de llet materna moll,
que ja una dona rara
te penja arràn de coll
una feixuga esquella
¡oh càndida badella!
Quaresma
El pla de la Calma
Cinegètiques
Contemplant el cider
Oh placidesa de romandre
en la barraca, ab l'escopeta
disposta sempre en la mà dreta,
y en l'altra mà, caient de mandra
qualque volum d'André Chenier!
Sempre a l'aguait, quatre o cinch hores,
la vista erranta per les vores
y per les branques del cider,
l'aurella atenta a la cridòria
dels gaigs! La flauta d'una merla,
de tan propera, fa estremir.
Un espetec canta victòria…
Tomba una griba qui s'esberla
de caure, ubèrrima, al camí.
Guatlla captiva
Fallida
Els serradors
El molí
I.
II.
Y'l moliner, deixant la tasca pacienta,
aboca altra quartera de blat a la tramuja,
de blat lluent y fresc com un varal de pluja
qui's fon al xuclador del canalot. Rebenta,
la mola se'l ne du y, ab una giravolta,
l'escampa sota seu, frenètica el tritura
y raja el blat d'avans, tornat farina pura,
entre el xerricament d'una eternal absolta.
El moliner linfàtic, per escalfar la sang,
enfonsa arràn d'aixella el bras a la farina
y'n treu una grapada y escampa la polsina
y, emblanquinat, sorgeix com un atleta. Blanc
té'l borrissol dels brassos, les celles y la testa…
Per tot sembla que hi hagi passat una congesta.
III.
IV.
Els carboners
Dante.
Preludi
(Parla el poeta:)
Mirant el bosc ab persistència
m'esdevé'l temps eternitat
y se'm transforma l'existència
en un llarc somni improvisat.
Y tot jo quedo obsessionat:
el bosc se'm torna pròpia essència
y de mon jo la conciència
se fon dins l'ampla immensitat.
Y veig els arbres per dins meu,
y les arrels veig dins la terra,
veig les entranyes de la serra,
veig els cimals sota la neu.
Y al fons de tot m'hi veig a mi
guaitant dins meu el bosc lluhir.
Génessi