Preface

Learn Robotics Programming is about building and programming a robot with smart behavior. It covers the skills required to make and build a gadget from parts, including how to choose them. These parts include sensors, motors, cameras, microphones, speakers, lights, and a Raspberry Pi.

This book continues with how to write code to make those parts do something interesting. The book uses Python, together with a little bit of HTML/CSS and JavaScript.

The technology used is intended to include things that are available and affordable and the code is shown to demonstrate concepts, so they can be used and combined to create even more interesting code and robots.

The topics combine aspects of being a programmer with aspects of being a robot maker, with a number of specialist topics such as computer vision and voice assistants thrown in.

Who this book is for

This book is intended for someone with a little programming experience, or someone more experienced but looking to apply their skills to a hardware project. You do not need to be an expert-level programmer, but do have to have written some lines of code and be comfortable with looping, conditionals, and functions. Knowledge of object-oriented- (class- and object-) based programming isn't necessary but is introduced in the book.

The book does not require a specialist workshop, although there will be a little soldering and bolting things together. This will be introduced later in the book.

You do not need to have any experience at all with electronics or making things, but hopefully, you'll have a healthy interest in learning more, since some very basic concepts are introduced throughout the book. Being keen to build a robot, get it to do stuff, and find out what to do with it next is probably the most important aspect of the book.

What this book covers

Chapter 1, Introduction to Robotics, introduces what robots are, and finds examples in the home and industry, along with the kinds of robots beginners build.

Chapter 2, Exploring Robot Building Blocks – Code and Electronics, looks at the components of a robot. We will start making choices about the robot's parts and see block diagrams for both systems and code.

Chapter 3, Exploring the Raspberry Pi, introduces the Raspberry Pi and its connections and the Raspbian Linux operating system we'll use on it, and also covers the preparation of an SD card for use in a robot.

Chapter 4, Preparing a Headless Raspberry Pi for a Robot, shows you how to set up an untethered Raspberry Pi and communicate with it wirelessly.

Chapter 5, Backing Up the Code with Git and SD Card Copies, shows how code can be lost or broken, then ways to protect your work and keep a history of it.

Chapter 6, Building Robot Basics – Wheels, Power, and Wiring, introduces the trade-offs for buying and test fitting a robot base, then assembling it.

Chapter 7, Drive and Turn – Moving Motors with Python, shows you how to write code to move a robot, laying down the foundations for the code in subsequent chapters.

Chapter 8, Programming Distance Sensors with Python, adds sensors and code to make a robot that autonomously avoids walls and obstacles.

Chapter 9, Programming RGB Strips in Python, adds multicolored lights to your robot. Explore this additional output to use for debugging or fun on the robot.

Chapter 10, Using Python to Control Servo Motors, shows how to use these motors to position a sensor head, and where they could be used in arms or legs on other robots.

Chapter 11, Programming Encoders with Python, demonstrates how odometry/tacho wheels can be read in your code, letting your robot drive in a straight line, make an accurate turn, or record how far it's driven. This chapter also introduces the PID controller.

Chapter 12, IMU Programming with Python, introduces the Inertial Measurement Unit (IMU), a set of sensors to measure temperature, acceleration, turning speeds, and magnetic fields. This chapter also gives you an introduction to soldering and VPython.

Chapter 13, Robot Vision – Using a Pi Camera and OpenCV, shows how to get data from a camera and use computer vision to make movements based on what the robot sees. This chapter also streams processed video to a browser.

Chapter 14, Line-Following with a Camera in Python, demonstrates how to make line-following behavior with the Raspberry Pi camera.

Chapter 15, Voice Communication with a Robot Using Mycroft, builds a voice control agent to link with your robot, letting you talk to control it and receive voice feedback.

Chapter 16, Diving Deeper with the IMU, takes the sensors we learned about in Chapter 12, IMU Programming with Python, and combines them to provide data about the orientation of the robot, building behavior that responds to the compass direction.

Chapter 17, Controlling the Robot with a Phone and Python, builds a menu system and a gaming-style control pad for your robot from your smartphone, letting you drive while seeing what the robot sees.

Chapter 18, Taking Your Robot Programming Skills Further, looks at the wider world of robotics, what communities there are, how to get in touch with other robot builders and makers, potential development areas, and where to compete with a robot.

Chapter 19, Planning Your Next Robot Project – Putting It All Together, is the final chapter, where we summarize what you have seen in the book, while encouraging you to plan the construction of your next robot.

To get the most out of this book

Before you begin with this book, you need to have programmed a little in a text programming language. I am assuming some familiarity with variables, conditional statements, looping, and functions.

You will need a computer, running macOS, Linux, or Windows, an internet connection, and Wi-Fi.

In terms of manual skills, I assume that you can use a screwdriver, that you can deal with occasional fiddly operations, and that you won't be too scared off by the possibility of soldering things.

Code examples have been tested on Python 3 with Raspbian Buster and Picroft Buster Keaton. The book will show you how to install these when needed. The book will show you how to choose and find robot parts when needed too.

Please read the appropriate chapters with trade-offs and recommendations before buying robot hardware.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

After reading the book, please come and join the #piwars community on Twitter for lots of robot discussion.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the Support tab.
  3. Click on Code Downloads.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learn-Robotics-Programming-Second-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Code in Action

Code in Action videos for this book can be viewed at http://bit.ly/3bu5wHp.

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781839218804_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "This sets one LED at led_number to the specified color."

A block of code is set as follows:

cyan_rgb = [int(c * 255) for c in cyan]

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

right_distance = self.robot.right_distance_sensor.distance

  # Display this

            self.display_state(left_distance, right_distance)

Any command-line input or output is written as follows:

>>> r.leds.show()

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select 4 for Other USB Microphone and try the sound test."

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.183.89