Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Robotics at Home with Raspberry Pi Pico

You're reading from   Robotics at Home with Raspberry Pi Pico Build autonomous robots with the versatile low-cost Raspberry Pi Pico controller and Python

Arrow left icon
Product type Paperback
Published in Mar 2023
Publisher Packt
ISBN-13 9781803246079
Length 400 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Danny Staple Danny Staple
Author Profile Icon Danny Staple
Danny Staple
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1: The Basics – Preparing for Robotics with Raspberry Pi Pico
2. Chapter 1: Planning a Robot with Raspberry Pi Pico FREE CHAPTER 3. Chapter 2: Preparing Raspberry Pi Pico 4. Chapter 3: Designing a Robot Chassis in FreeCAD 5. Chapter 4: Building a Robot around Pico 6. Chapter 5: Driving Motors with Raspberry Pi Pico 7. Part 2: Interfacing Raspberry Pi Pico with Simple Sensors and Outputs
8. Chapter 6: Measuring Movement with Encoders on Raspberry Pi Pico 9. Chapter 7: Planning and Shopping for More Devices 10. Chapter 8: Sensing Distances to Detect Objects with Pico 11. Chapter 9: Teleoperating a Raspberry Pi Pico Robot with Bluetooth LE 12. Part 3: Adding More Robotic Behaviors to Raspberry Pi Pico
13. Chapter 10: Using the PID Algorithm to Follow Walls 14. Chapter 11: Controlling Motion with Encoders on Raspberry Pi Pico 15. Chapter 12: Detecting Orientation with an IMU on Raspberry Pi Pico 16. Chapter 13: Determining Position Using Monte Carlo Localization 17. Chapter 14: Continuing Your Journey – Your Next Robot 18. Index 19. Other Books You May Enjoy

Planning to extend this robot

I rarely view robot projects as complete, especially those that are learning and development platforms. There are always new sensors to try, new programming algorithms to make, or simply bugs and quirks to iron out. On the other hand, there are ways to make robots more robust and cope with rougher environments, making the chassis lighter or the electronics simpler, so let’s start by considering some ideas for this robot and hopefully inspire some of your own.

Sensors you could add

The first exciting way to extend this robot is to add more sensors. Sensors are fun to program to get data from. This means you may have to figure out how to incorporate them into existing behaviors and mount them, though.

The following figure shows a selection of sensor extensions that could be interesting:

Figure 14.2 – Robot sensor extensions

Figure 14.2 – Robot sensor extensions

The preceding figure shows a selection of sensors that would be great to extend this robot and the things you could get it to do. The sensor types are numbered:

  1. Line detectors or reflectance sensors: These light up with an Infrared (IR) LED and then detect how much light reflects from an object that they point toward, or how bright/dark it is. Makers mount these under the robot as a line-following sensor. Some sensors, such as the SunFounder 5-channel line sensor, come with arrays of light detectors, which can be used with code to follow a line drawn on a floor. An example of a single sensor type is a TCRT5000.
  2. Bump switches: Makers use these less in modern robots, and distance sensors should mean they aren’t needed. However, you could use them so that if a robot surpasses a safe distance and bumps into something, it will immediately disengage or move back. They tend to be simple on-off switches with long lever arms to extend the edge along which they sense.
  3. Additional distance sensors: We’ve used two sensors and moved them around. A set of four sensors would allow the different existing behaviors to be enhanced. It also offers more information for Monte Carlo simulation and could be used for a maze-following behavior.
  4. A camera: There are camera sensors that we could use with Pico, such as OV7670 camera modules. They are complicated to connect and may require an additional Raspberry Pi Pico. Using downscaling and running edge detection or ML algorithms on it, it is possible to match objects. A good alternative is cameras with onboard processing, such as the HuskyLens (https://bit.ly/3Dzurrb). Another type of camera is a FLIR IR heat camera.
  5. LIDAR sensors: These scan and return the depths of objects in their field of view. Having many distance sensors could extend the accuracy of Monte Carlo simulation. However, these produce a lot of data quickly and may need a more powerful CPU to control them. Solid-state sensors are low-power, small, and cheap. Pictured in Figure 14.2 is an LDRobot LD-07 solid-state LIDAR.

Light sensors can read how much light falls on them. You could use these to program behaviors that move toward or away from light or more complex interactions with light.

A robot can have internal sensors, such as thermal, current, and voltage monitors, to monitor its batteries and motors so that the code can respond to low-battery or high-current scenarios.

Optical flow sensors, such as the PAA5100JE, facilitate odometry based on the flow of the ground below a robot and can be used to detect the overall speed of the robot; this can compensate for issues such as wheels slipping, which encoders would miss.

We’ve covered some sensor ideas for our robot, but another way to get information to and from a robot is through user interactions.

Interacting with the robot

The robot in this book doesn’t have many options for user interaction:

Figure 14.3 – Human interaction I/O

Figure 14.3 – Human interaction I/O

Figure 14.3 shows many ways to improve human interaction with the robot:

  1. Buttons: Add buttons for starting and stopping a behavior on a robot.
  2. LED lights: Some LED lights, perhaps with different colors, can be good to show a little feedback on what is running. Big LEDs can also be used as headlights.
  3. RGB LED displays: These come in strips or panels, and each LED can be set to a different color. They can provide more debugging and can make cute eyes or faces too. They use multiple interfaces, a custom one-pin system, and SPI or I2C. The Pimoroni PIM435 pictured uses I2C.
  4. OLED screens: These can show pictures, dials, menus, text, or graphics right on the robot. These come in mono or color varieties and are frequently I2C-controlled. One such mono I2C device is the Velleman WPI438 I2C screen.
  5. Game joypads: A game joypad controller would be a nice way to control a robot. However, it may require a more advanced Bluetooth setup to interface with Raspberry Pi Pico.
  6. A phone web app: We’ve been using the BlueFruit app, but by swapping Bluetooth for Wi-Fi (such as with Raspberry Pi Pico-W), you can write far more interactive phone control. This will require writing more code for a frontend. At the time of writing, a system for graphing on a smartphone requires a fair amount of code to produce over Wi-Fi, and a convenient app, such as BlueFruit LE Connect, doesn’t yet exist.
  7. A beeper: These can make beeping and buzzing sounds for the robot. You can drive some of these directly from GPIO pins, with musical tones indicating the program’s state or making interesting sounds.
  8. A microphone: There are UART-capable voice control modules suitable for Raspberry Pi Pico. They have a small set of commands to start behaviors, and, with LED or beeper feedback, could be a novel way to interact with the robot.

User interactions can manipulate behaviors, but we need somewhere good to mount these LEDs. What can we do to the robot’s chassis to improve and extend it?

Chassis and form enhancements

The robot’s chassis is simple and light, but we could take this much further, making it a more robust or aesthetically pleasing robot:

Figure 14.4 – Chassis enhancements

Figure 14.4 – Chassis enhancements

Figure 14.4 has examples of two ways to improve the robot or its sensors with an outer shell:

  1. Figure 14.4 (1) shows a lunchbox adapted into a robot. A lunchbox, ice cream tub, or roller paint tray with holes cut into it can be made into the fairing for the robot, enclosing the electronics and holding its wiring and electronics.
  2. Figure 14.4 (2) shows a robot with sensor mounts that have been 3D-printed. Custom fairings and brackets can be made this way or through vacuum forming or laser cutting. See the Design and manufacturing section later in this chapter.

Whichever method you choose, it needs to be lightweight and easy to remove so that the electronics are accessible and you can change the batteries. It could be held in place by bolts or Velcro.

You‘ll need to consider how to make controls accessible – such as putting switches and charging ports on the outside. Having a fairing invites more decoration, the use of color, and style paneling. Combining this with the RGB LEDs could make for an interesting-looking robot. You could take style cues from your favorite sci-fi robot and use a similar color scheme.

Electronics enhancements

The electronics we’ve used so far have been composed of modules tethered together with connector cables, using breadboards to assemble them. Breadboards are great for prototyping but take up a lot of space and weight and are susceptible to movement and vibration, with wires quickly coming loose or forming poor connections. They also look messy. What could we research to upgrade this?

Here are some sturdiness enhancements we can make to the robot electronics:

Figure 14.5 – Improving robot electronics

Figure 14.5 – Improving robot electronics

Electronics in the robot could be made smaller, lighter, and tidier. Try these ideas:

  1. Pictured in Figure 14.5 (1) is an Inventor 2040 W from Pimoroni (https://shop.pimoroni.com/products/inventor-2040-w). Motor and robot boards for Raspberry Pi Pico or incorporating an RP2040 will reduce the amount of wiring. The Inventor 2040 W includes motor control, lights, and servo connections.
  2. Soldered boards will be tidier. An intermediate option is using a stripboard or perfboard. These pre-made printed circuit boards can mimic the wiring arrangement of breadboard strips, allowing you to transfer breadboard designs onto them. You can then solder parts and wires into them. Wires going to external parts, such as motors and sensors, will have their connectors soldered into the board.

Figure 14.5 (2) shows a custom Printed Circuit Board (PCB) from https://github.com/uwrobotics/MarsRoverHardware. You can download or design your own using software such as KiCad. This is complicated but gives you lots of options for customization. You use a PCB view to lay out a circuit board and route connections between parts. Using PCBs allows you to make small, light, and tidy robot designs. In addition, it opens your designs to using surface mount electronics, which makes more components available. You can use design rules to ensure that the connections are all made and tracks are not touching. After this, you can then prepare the part for manufacture. You can take these designs to a board house, such as Seeed Studio (https://www.seeedstudio.com/), that prints the board for you.

Some board houses offer a Printed Circuit Board with Assembly (PCBA) service, where, at additional cost, they will solder on components, sockets, and connectors before sending the part to you. Using a PCBA service means you just need to plug in the external sensors and perhaps a Pico into a socket on receiving the board. That means that you do not need to solder surface mount parts yourself. Just be aware that this will take experience, and you may produce boards that aren’t right the first time.

Figure 14.6 – Tidying wiring

Figure 14.6 – Tidying wiring

  1. You can tidy robot cabling using 6 mm spiral wrap and cable clips, as shown in Figure 14.6 (3), or just masking tape, as shown in Figure 14.6 (4). Wiring can be aesthetically pleasing if you make an effort to route it nicely.
  2. For connectors, we have used Dupont connectors due to their convenience. However, once you are on a soldered circuit board, you can consider locking connectors, such as JST or Molex PicoBlade connectors. These lock cables in place so that they will not vibrate loose or easily be pulled out, and add further protection by being polarized. You will need to get practice with a crimping tool to use these effectively, but it will be worth it for better robot builds.

With a robust chassis and tidier electronics, perhaps you can get more ambitious with further outputs. Let’s see things you could make the robot’s outputs do.

Outputs you could add

Outputs mean a robot could do more to move or alter its surroundings. Additional motors, such as servo motors, can be used to make interesting mechanical devices, for example, those shown in the following figure:

Figure 14.7 – Motors and outputs in use

Figure 14.7 – Motors and outputs in use

Figure 14.7 shows a few interesting ways to use further motors to extend the robot:

  1. A gripper – This could grasp items and move them around. The Pololu Micro Gripper Kit uses a single servo to open or close the jaws. These are fun to attach to the front of a robot.
  2. A pan-and-tilt mechanism – Putting sensors on this means you can direct a sensor at a particular point of interest or use the head to sweep with a sensor. One servo motor rotates the head left and right (panning), and the other tilts the head up and down. The Adafruit Mini Pan-Tilt Kit is a good example of this.
  3. A lift-and-lower mechanism – These use a motor to lift and lower a platform, like a forklift. This could be combined with the gripper to make a robot that can stack objects.
  4. A ball launcher – A launcher would be fun so that a robot could aim at targets. Robotics competitions such as PiWars have events that involve using these. Motors are required to direct the aim, and a motor or actuator is required for launching the ball.

These are just a few examples; there are plenty more mechanisms you can either buy or build. You could even add a whole arm with a kit such as the MeArm Servo Robot Arm Kit.

Now that we’ve seen some outputs, perhaps we can better use these sensors and outputs with more behaviors.

Extending the code and behaviors

The robot’s code and behaviors are what bring the robot to life. However, there are many ways we could improve the code on this robot, as shown in the following figure:

Figure 14.8 – Behavior suggestions

Figure 14.8 – Behavior suggestions

Figure 14.8 depicts some suggestions; the following list covers these and more:

  1. Line-following: Using the line detection sensors previously mentioned in the section on sensors, you could program a robot to follow lines drawn on the floor. Line-following can use if-then, bang-bang control, or a PID algorithm for smooth line-following.
  2. A menu system: You can combine all the behaviors in a menu for selection. Consider how each program would be tidied up so another can take over. A variation of this is using a voice control module, along with beeps, to indicate the current robot mode.
  3. Driving with a camera: Adding a camera and serving it to a phone web app means you could drive the robot with a camera view – a robot periscope.
  4. Maze solving: With more distance sensors, the robot would be able to look for openings and find its way around a maze. Depending on the complexity of the maze, simple rules such as always turning left might work, or the robot might have a map of the maze and use the Monte Carlo method with precision navigation. For example, a turning-left method using the encoders might be able to memorize what turns it took and where, backtrack, and try other routes.
  5. Camera navigation: Camera images can be scaled to low resolutions, and algorithms can be used to pick out features where image intensity or colors have changed over a threshold. The detected feature locations can then be combined with a PID algorithm to orient the robot relative to such features.
  6. Camera recognition: Recognition is considerably more complex and may require looking at a machine learning system such as TinyML. See https://bit.ly/3xy3twx for news on TinyML ports for CircuitPython. You can use similar techniques with microphones for speech recognition, but this may be intensive enough that multiple Raspberry Pi Pico boards would be required.

The following suggestions are not pictured but represent advanced behaviors:

  • Simultaneous Location and Mapping (SLAM): A robot can use its sensors to build up a map of its location and then keep track of its pose relative to what it has already mapped. This technique would use several sensors together and benefit from the LIDAR sensors that we have already mentioned. However, this advanced technique can be a deep rabbit hole!
  • Task planning and motion planning: Combining controlled turns, controlled movements, and location tracking with a hopper or gripper would mean you could make behaviors to seek out, collect items, and place them in a collection point.

These suggestions should hopefully inspire some creative behaviors. There are endless possibilities for combinations of code, sensors, and outputs, which you can use to improve your knowledge, solve problems with a robot, and extend your toolbox.

So far, though, these suggestions have been focused on extending the existing platform. So, what happens when we extend to thinking about your next robot platform?

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image