Robotics at Home with Raspberry Pi Pico: Build autonomous robots with the versatile low-cost Raspberry Pi Pico controller and Python

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Design, build, and program a mobile robot platform while gaining an understanding of the Raspberry Pi Pico, Free CAD, and robot sensors using Python to code, Bluetooth to connect & smartphone to control your projects

Key Features

  • Gain in depth knowledge of robotics with easy-to-follow instructions
  • Build a rover platform designed for experimentation and extension
  • Enhance your robot building skills through planning, building, and coding
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

The field of robotics is expanding, and this is the perfect time to learn how to create robots at home for different purposes. This book will help you take your first steps in planning, building, and programming a robot with Raspberry Pi Pico, an impressive controller bursting with I/O capabilities. After a quick tour of Pico, you’ll begin designing a robot chassis in 3D CAD. With easy-to-follow instructions, shopping lists, and plans, you’ll start building the robot. Further, you’ll add simple sensors and outputs to extend the robot, reinforce your design skills, and build your knowledge in programming with CircuitPython. You’ll also learn about interactions with electronics, standard robotics algorithms, and the discipline and process for building robots. Moving forward, you’ll learn how to add more complicated sensors and robotic behaviors, with increasing complexity levels, giving you hands-on experience. You’ll learn about Raspberry Pi Pico’s excellent features, such as PIO, adding capabilities such as avoiding walls, detecting movement, and compass headings. You’ll combine these with Bluetooth BLE for seeing sensor data and remotely controlling your robot with a smartphone. Finally, you’ll program the robot to find its location in an arena.

By the end of this book, you’ll have built a robot at home, and be well equipped to build more with different levels of complexity.

What you will learn

  • Interface Raspberry Pi Pico with motors to move parts
  • Design in 3D CAD with Free CAD
  • Build a simple robot and extend it for more complex projects
  • Interface Raspberry Pi Pico with sensors and Bluetooth BLE
  • Visualize robot data with Matplotlib
  • Gain an understanding of robotics algorithms on Pico for smart behavior

Who this book is for

This book is for beginner robot makers, keen hobbyists, technical enthusiasts, developers and STEM teachers who want to build robots at home. Prior knowledge of coding - beginner to intermediate programming, will be helpful.

Table of Contents

  1. Planning a Robot with Raspberry Pi Pico
  2. Preparing Raspberry Pi Pico
  3. Designing a Robot Chassis in FreeCAD
  4. Building a Robot Around Pico
  5. Driving Motors with Raspberry Pi Pico
  6. Measuring Movement with Encoders on Raspberry Pi Pico
  7. Planning and Shopping for More Devices
  8. Sensing Distances to Detect Objects with Pico
  9. Teleoperating a Raspberry Pi Pico Robot with Bluetooth LE
  10. Using the PID Algorithm to Follow Walls
  11. Controlling Motion with Encoders on Raspberry Pi Pico
  12. Detecting Orientation with an IMU on Raspberry Pi Pico
  13. Determining Position using Monte Carlo Localization
  14. Continuing Your Journey – Your Next Robot

Author(s): Danny Staple
Edition: 1
Publisher: Packt Publishing
Year: 2023

Language: English
Pages: 400
City: Birmingham
Tags: Robotics; CircuitPython; PIO; Raspberry Pi Pico; Free CAD; CAD; Robot Sensors; Python; Bluetooth

Cover
Copyright
Contributors
Table of Contents
Preface
Part 1: The Basics – Preparing for Robotics with Raspberry Pi Pico
Chapter 1: Planning a Robot with Raspberry Pi Pico
Technical requirements
What is Raspberry Pi Pico, and why is it suitable for robotics?
A microcontroller that runs Python
Raspberry Pi Pico’s interfaces for sensors and devices
What is CircuitPython?
Planning a Raspberry Pi Pico robot
An overview of robot planning
A note on trade-offs
Choosing a robot chassis
Choosing the power systems
Pin usage
Test fitting a Raspberry Pi Pico robot
Creating your first test-fit part
Motors
Power systems
Creating a rough chassis
Arranging the test-fit parts
A recommended shopping list for robot basics
Robot parts and where to find them
The robot workshop and makerspaces
Summary
Exercises
Further reading
Chapter 2: Preparing Raspberry Pi Pico
Technical requirements
Getting CircuitPython onto Raspberry Pi Pico
Preparing the CircuitPython library for Pico
Coding on Pico – first steps
Downloading the Mu editor
Lighting the Pico LED with CircuitPython
Blinking the LED with code
Soldering headers to Raspberry Pi Pico
Summary
Exercises
Further reading
Chapter 3: Designing a Robot Chassis in FreeCAD
Technical requirements
Introducing FreeCAD
The FreeCAD screen
Selecting workbenches
FreeCAD settings
Making robot chassis sketches in FreeCAD
Preparing the document
Sketching the chassis outline
Creating the upper parts main sketch
Sketching the motor holes
Designing the castor placement
Modeling chassis parts from sketches
Modeling the chassis plate
Modeling the other parts
Troubleshooting the model
Modeling the castor in 3D
Making FreeCAD technical drawings
Setting up the page
Adding parts to the drawing
Preparing the drawing for print
Summary
Exercises
Further reading
Chapter 4: Building a Robot around Pico
Technical requirements
Cutting styrene parts
Transferring CAD measurements to a plastic sheet
Cutting the plastic sheet
Finishing and sanding the chassis plate
Assembling a robot chassis
Attaching the caster and battery box
Attaching the motors and wheels
Wiring a Raspberry Pi Pico robot
Wiring Pico and the motor controller into the breadboard
Adding the batteries
Wiring in the motors and encoders
Powering the robot up
Summary
Exercises
Further reading
Chapter 5: Driving Motors with Raspberry Pi Pico
Technical requirements
Driving forward and back
Testing each motor with CircuitPython
Driving wheels in a straight line
Steering with two motors
An introduction to pulse width modulation speed control
Driving fast and slow
Turning while moving
Driving along a planned path
Putting line and turn moves together
The flaw with driving this way
Summary
Exercises
Further reading
Part 2: Interfacing Raspberry Pi Pico with Simple Sensors and Outputs
Chapter 6: Measuring Movement with Encoders on Raspberry Pi Pico
Technical requirements
About encoders and odometry
Absolute and relative sensing
Types of encoders
Encoder pulse data
Wiring in encoders on a Raspberry Pi Pico robot
Examining the motors
Examining the wiring
Programming Raspberry Pi Pico PIO
Introduction to PIO programming
Introducing PIOASM
Detecting input with PIO
PIO instructions and registers
Making a counter with PIO
Measuring encoder count for movement
Making a simple PIO change detection loop
Making a bidirectional counter with PIO
Making reusable encoder code
Measure counts for a known time
Summary
Exercises
Further reading
Chapter 7: Planning and Shopping for More Devices
Technical requirements
Introducing sensors
Analog sensor types
Timed pulses
Data bus sensors
The robot block diagram
Choosing device types
Distance sensors
Inertial measurement unit
Bluetooth devices
Device pin usage summary
Planning what to add and where
Bluetooth and IMU mounting plan
Distance sensor mounting plan
Shopping list – parts and where to find them
Preparing the robot
Designing the shelf
Cutting the shelf
Designing the front sensor brackets
Cutting the sensor brackets
Preparing the chassis plate
Assembling the robot
Summary
Exercises
Further reading
Chapter 8: Sensing Distances to Detect Objects with Pico
Technical requirements
How distance sensing works
Soldering headers and attaching them to the robot
Soldering headers
Mounting the sensors
Introduction to I2C communication
Communicating with a single distance sensor
Wiring the distance sensors
VL53LX theory of operation
Reading a single distance sensor in CircuitPython
Troubleshooting
Connecting two distance sensors
Troubleshooting
Building a wall avoider with Raspberry Pi Pico
Preparing the robot library
Wall-avoiding theory of operation
Distance sensor wall avoider code
Troubleshooting
Summary
Exercises
Additional reading
Chapter 9: Teleoperating a Raspberry Pi Pico Robot with Bluetooth LE
Technical requirements
Wireless robot connection options
Connecting Bluetooth LE to Raspberry Pi Pico
Attaching the Bluetooth module to the robot
Wiring the Bluetooth breakout to Raspberry Pi Pico
Connecting to the Bluefruit LE device with UART
Connecting a smartphone
Troubleshooting the Bluefruit module
Getting sensor data over Bluetooth LE on Raspberry Pi Pico
Graphing the data
Controlling the robot with Bluetooth LE
Printing what we got
Button control mode
Decoding button control packets to drive the robot
Troubleshooting
Summary
Exercises
Further reading
Part 3: Adding More Robotic Behaviors to Raspberry Pi Pico
Chapter 10: Using the PID Algorithm to Follow Walls
Technical requirements
Introducing the PID algorithm
Control and feedback
Bang-bang control
Distance sensing with proportional control
Troubleshooting
Using the integral to handle small distances
Dealing with oscillations using the derivative
Using PID to follow a wall
Changing the sensor’s placement
Wall-following code
Troubleshooting
PID tuning – using graphs to tune the PID
Controlling motor speed
The proportional component
Adjusting the derivative gain
Tuning the integral
Closing notes on tuning
Summary
Exercises
Further reading
Chapter 11: Controlling Motion with Encoders on Raspberry Pi Pico
Technical requirements
Converting an encoder count into a speed
Loose bolts and nuts
Robot wheel geometry
Encoder geometry
Measuring the speed of each wheel
Fixing the encoder glitches
Using PID to maintain speed and a straight line
The speed control system
Speed control code
Speed controller PID tuning
Driving a known distance
Theory of operation
Code to control distance and speed
Summary
Exercises
Further reading
Chapter 12: Detecting Orientation with an IMU on Raspberry Pi Pico
Technical requirements
What is an IMU and how to choose one
Components of an IMU
Choosing an IMU module
Connecting the IMU to the robot
Preparing the BNO055
Attaching the BNO055
Wiring the BNO055 to Raspberry Pi Pico
Setting up the software and connecting
Troubleshooting
Calibrating and getting readings
Calibration code
The calibration process
Always face North behavior
CircuitPython code for the face North behavior
Troubleshooting
Making a known turn behavior
Summary
Exercises
Further reading
Chapter 13: Determining Position Using Monte Carlo Localization
Technical requirements
Creating a training area for our robot
What we will make
How we will make the arena
Tips for cutting
Modeling the space
Representing the arena and robot position as numbers
Serving the arena from the robot
The Bleak library
Creating a Bluetooth LE wrapper library
Showing the robot’s data on the computer screen
Using sensors to track relative pose
Setting up poses
Displaying poses
Moving with collision avoidance
Moving poses with the encoders
Pose movement probabilities
Monte Carlo localization
Generating pose weights from a position
Resampling the poses
Incorporating distance sensors
Tuning and improving the Monte Carlo model
Summary
Exercises
Further reading
Chapter 14: Continuing Your Journey – Your Next Robot
Technical requirements
A summary of what you have learned in this book
Basic robotics with Raspberry Pi Pico
Extending a Raspberry Pi Pico robot with sensors
Writing CircuitPython behavior code for Raspberry Pi Pico
Planning to extend this robot
Sensors you could add
Interacting with the robot
Chassis and form enhancements
Electronics enhancements
Outputs you could add
Extending the code and behaviors
Planning your next robot
Form, shape, and chassis
Electronics and sensors
Code and behavior
Further suggested areas to learn about
Electronics
Design and manufacturing
Robotic competitions and communities
Robotics systems and code
Summary
Exercises
Further reading
Index
Other Books You May Enjoy