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

Strategy 1 – Keeping the code on a PC and uploading it

Secure File Transfer Protocol (SFTP) lets you transfer files from a computer to a Pi. This strategy enables you to write code on your computer, then upload it to the Raspberry Pi. You can choose your editor and have the safety of more than one copy.

Important note

But wait – which editor? Editing code requires software designed for this purpose. Recommendations for Python are Mu, Microsoft VS Code, Notepad++, and PyCharm.

SFTP uses SSH to copy files to and from the Raspberry Pi over the network. So, let's see how to do it:

  1. First, make yourself a folder on the PC to store your robot code in; for example, my_robot_project.
  2. Inside that folder, make a test file, using your editor, that will just print a bit of text. Put this code into a file named hello.py:
    print("Raspberry Pi is alive")
  3. We will copy this to the robot and run it. You can make the copy using the SFTP tool FileZilla...