Book Image

Learn Robotics Programming - Second Edition

By : Danny Staple
Book Image

Learn Robotics Programming - Second Edition

By: Danny Staple

Overview of this book

We live in an age where the most complex or repetitive tasks are automated. Smart robots have the potential to revolutionize how we perform all kinds of tasks with high accuracy and efficiency. With this second edition of Learn Robotics Programming, you'll see how a combination of the Raspberry Pi and Python can be a great starting point for robot programming. The book starts by introducing you to the basic structure of a robot and shows you how to design, build, and program it. As you make your way through the book, you'll add different outputs and sensors, learn robot building skills, and write code to add autonomous behavior using sensors and a camera. You'll also be able to upgrade your robot with Wi-Fi connectivity to control it using a smartphone. Finally, you'll understand how you can apply the skills that you've learned to visualize, lay out, build, and code your future robot building projects. By the end of this book, you'll have built an interesting robot that can perform basic artificial intelligence operations and be well versed in programming robots and creating complex robotics projects using what you've learned.
Table of Contents (25 chapters)
1
Section 1: The Basics – Preparing for Robotics
7
Section 2: Building an Autonomous Robot – Connecting Sensors and Motors to a Raspberry Pi
15
Section 3: Hearing and Seeing – Giving a Robot Intelligent Sensors
21
Section 4: Taking Robotics Further

Building a Raspberry Pi camera stream app

Downloading one picture at a time is fine, but we need to do things with those pictures on our robot. We also need a handy way to see what the robot is doing with the camera data. For that, we will learn how to use a Flask web server to serve up our pictures so we can view the output on a phone or laptop. We can use the core of this app to make a few different behaviors. We'll keep the base app around for them.

A video or video stream is a sequence of images, usually known as frames.

Let's design our streaming server.

Designing the OpenCV camera server

The diagram in Figure 13.9 shows an image data pipeline, going from the camera, through the processing, and out to our web browser:

Figure 13.9 – The image server app

The image server app in Figure 13.9 starts with the camera. The camera feeds image data to a convert to OpenCV step, with the raw photo given. Image data needs some processing...