• No results found

Programming with C++ Hands-On Robotics. Leverage Raspberry Pi 3 and C++ libraries to build intelligent. robotics applications.

N/A
N/A
Protected

Academic year: 2021

Share "Programming with C++ Hands-On Robotics. Leverage Raspberry Pi 3 and C++ libraries to build intelligent. robotics applications."

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

Hands-On Robotics

Programming

with C++

Leverage Raspberry

Pi

3

and C++

libraries

to

build

intelligent

robotics

applications

Dinesh Tavasalkar

(2)

Table of Contents

Preface i

Section

1:

Getting

Started with

wiringPi

on a

Raspberry

Pi

Chapter

1: Introduction to the

Raspberry

Pi g

Technical

requirements

9

Software

required

10

Hardware requirements 10

ForRaspberry Pi 3B+ and Raspberry Pi Zero W 11

Additional hardware forRaspberry Pi 3B+ 11

Additional hardware requirementsforRaspberry Pi Zero W 11

Understanding

the

Raspberry

Pi n

The RaspberryPi 3B+ 12

The RaspberryPi Zero W 13

Setting

up a

Raspberry

Pi 3B+ as a

desktop computer

15

Installing

Raspbian OSon an SD card 15

Downloading and installingEtcher 16

DownloadingtheRaspbian Stretch image 16

WritingtheRaspbian Stretch imagetoamicroSDcard 17

Setting up the Raspberry Pi 3B+ 19

ConnectingtheRaspberry Pi3B+to the internet 22

Connecting

the

Raspberry

Pi 3B+ to a

laptop

via Wi-Fi 23

Creating

anSSH fileon a microSD card 24

Connecting the Raspberry Pi 3B+ toa Wi-Fi network

using

PuTTY 28

Enablingthe VNCserver 34

Viewingthe Raspberry Pi outputonthe VNC Viewer 37

Increase the VNC'sscreen resolution 39

HandlingVNC and PuTTYerrors 40

Setting

up the

Raspberry

PiZero W as a

desktop

computer

41

Setting

up the Raspberry Pi Zero W 43

Connecting

the

Raspberry

Pi Zero W to a

laptop

via Wi-Fi 44

Connecting the Raspberry Pi Zero W toaWi-Fi network using PuTTY 48

EnablingVNC Viewer forRaspberryPi Zero W 48

Viewing

Raspberry

Pi Zero Woutputon VNC Viewer 48

Summary

48

Questions 49

Chapter

2:

Implementing

Blink with

wiringPi

51

Technical

requirements

51
(3)

TableofContents

Accessing Raspberry

Pi GPIO

pins

via wiringPi 57

Making

an LED blink 59

Wiring connections 59

The blinking program 60

Uploadingthe code to the RaspberryPi 62

Smart

light

-

working

with

digital

sensor 63 The LDRsensorand the way it works 63

Wiring connection 65

Smartlightprogram 65

Pulse Width Modulation

using

softPWM 67

How PWM works 67

The softPWM

library

69

Makingan LED blink with the softPWM library 70

Summary

72

Questions 72

Section 2:

Raspberry

Pi Robotics

Chapter

3:

Programming

the Robot 75

Technical

requirements

75

Choosing

a robot chassis 76

Constructing

and

connecting

the robot 77

Constructing

the robot 77

Connecting

the motordrivertothe

Raspberry

Pi 78

Whatis amotordriver? 78

Wiring connections 79

Working

with

H-bridge

80

Moving

the robot 83

Moving

the robot backward 85

Stopping

the robot 86

Different types of turns 86

Axial turns 86

Axial left turn 87

Axialrightturn 87

Radialturn 88

Radial left turn 88

Radialrightturn 89

Summary

89

Questions 90

Chapter

4:

Building

an

Obstacle-Avoiding

Robot 91

Technical

requirements

91

Using

an ultrasonicsensor 92

Howan ultrasonicsensor measures distances 93

The arithmetic equation fordetermining the timetaken 94

Wiring the ultrasonicsensorto the Raspberry Pi 95

(4)

Using

an LCD gg

Wiring

the 16x2 LCD to the Raspberry Pi 102

Programming the LCD 104

The LCDprogram 104

The LCD and the ultrasonicsensorprogram 106

What is the I2C protocol? 107

Wiringthe I2C LCD and the Raspberry Pi 109

Programmingthe LCD with the I2C LCD module log

The I2C LCD and the ultrasonicsensorprogram 114

Building

an

obstacle-avoiding

robot 115

Wiring connections 116

Programming theobstacle-avoiding robot 116

Summary

118

Questions 118

Chapter

5:

Controlling

a Robot

Using

a

Laptop

119

Technical

requirements

119

Installing

the ncurses

library

120

ncursesfunctions 120

Writinga HelloWorld program with ncurses 121

Compilingand runningthe program 123

Controlling

LEDs and a buzzer

using

ncurses 125

Wiring connections 125

Writingthe LEDBuzzer.cpp program 126

Controlling

a rover

using

a

laptop keyboard

129

Building a laptop-controlled roverprogram 130

Tracing

asquarepath 132

Installing

and

setting

up QT5 133

Setting

up QT5 135

Controlling

LEDs with GUI buttons 140

Creating a QTproject 141

Dealing with errors 14g

Controlling

a rover

using

a

laptop

with QT5 150

Summary

153

Questions 153

Section

3: Face and

Object Recognition

Robot

Chapter

6:

Accessing

the RPi Camera with

OpenCV

157

Technical

requirements

157

Installing OpenCV

4.0.0 on

Raspberry

Pi 158

Uninstalling

Wolfram and LibreOffice 158

Updating

your RPi isg

Installing

the cmake, image, video, andgtk packages isg

Downloading

and unzipping OpenCV4.0 and its contribution repository 160
(5)

TableofContents

Compiling

and installing OpenCV 161

Linking

OpenCV

toPython 163

Enabling

and

connecting

the RPi camera to RPi 166

Connectingthe RPicamerato RPi 168

Mounting

the RPicamera onthe robot 170

Capturing

images

and video with the RPi camera 172

Recording

avideo with the RPi camera 174

Installing the v4I2 driver 175

Reading

an

image using OpenCV

176

Summary

178

Questions 179

Chapter

7:

Building

an

Object-Following

Robotwith

OpenCV

181

Technical

requirements

181

Image processing

with

OpenCV

181

Importantfunctions in

OpenCV

182

Object

recognition using

OpenCV

190

Capturingtheimage 190

Findingthe RGB pixelvalues 191

Theobjectdetection program 195

The OpenCVcamera feed program 199

Building

an

object-following

robot 201

Ball

tracing using

moments 201

Programming logic 201

The ball tracing program 202

Setting up the object-following robot 205

Object-followingrobotprogram 205

Summary

207

Questions 208

Chapter

8: Face Detection and

Tracking Using

the Haar Classifier 209

Technical

requirements

209

Face detection

using

the Haar cascade 210

Basicworking of the Viola-Jones

algorithm

210

Face-detection program 212

Detecting

the eyes and smile 217

Detectingthe eyes 217

Eye detection using haarcascade_eye 218

Eye detection using haarcascade_lefteye_2splits

andhaarcascade_righteye_2splits 219

Detectingtheleft eye 219

Detectingtherighteye 221

Recognizing a smile 223

Programming logicfor smilerecognition 223

Face-tracking

robot 224

Wiring connections 225

(6)

Usingthe white doton the facetriangletomovethe robot 231

Summary

233

Questions 234

Section 4:

Smartphone-Controlled

Robot

Chapter

9:

Building

a Voice-Controlled Robot 237

Technical

requirements

238

An introduction to

App

Inventor 238

Creating

a

Talking

Pi Android app 238

Designing the app 242

Programming the blocks 248

Main block 249

Intermediate block 249

Final block 250

TheTalking Pi program 251

Importing and exporting the .aia file of the app 255

Creating

a voice-controlled bot app 256

Designing

the app 257

Adding and customizingthecomponents 258

Programming

the voice-controlled botblock 265

Pairing

the Android

smartphone

and RPi via Bluetooth 270

Enabling the Bluetooth serial port 276

Developing

the Bluetooth program for RPi 277

Socket

programming

277

VoiceBotserverprogram 280

Testingthe code 282

Summary

285

Questions 285

Assessments 287

Other Books You May Enjoy 291

References

Related documents

Blogging is a great way to show and share people’s enthusiasm and passion with the public. Many people with no web design or technical background have the possibility to build a

non-fractal images created using the mathematical convergence properties of iteration functions” (Kalantari) The polynomiography software is a tool, like a camera, and can be used

The aim of this study is to present the results of a comprehensive, Moodle compatible system designed for the development and evaluation of inter-personal competencies – teamwork

A pilot will be a success if executed correctly and providing results that are reliable (whether ‘positive’ or ‘negative’). Positive results prove a theory is

– Netflix’s costs rise and its price rises –for all users, not just Comcast customers – What are Comcast’s incentives to invest in more capacity. • Consider payment by consumer

Pooled data revealed that, application of pyrazosulfuron ethyl 10 % WP at 20 g a.i./ha as pre-emergent herbicide followed by the application of Bispyribac sodium 10 % SC @ 250

Certain statements in this presentation constitute forward-looking statements, including statements relating to NBG’s strategy, its additional capital needs, asset values,

This designation was based on alignment of sequences with control region sequences taken from 2 individuals from the Pacific, which were known to belong to the