Reader small image

You're reading from  Learn Robotics Programming - Second Edition

Product typeBook
Published inFeb 2021
PublisherPackt
ISBN-139781839218804
Edition2nd Edition
Concepts
Right arrow
Author (1)
Danny Staple
Danny Staple
author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple

Right arrow

Chapter 2: Exploring Robot Building Blocks – Code and Electronics

In this chapter, we'll take a robot apart to see its parts and systems. We'll explore the components of a robot, both the software (code, commands, and libraries) and the hardware, and how they go together. When starting to make a robot, it's valuable to think about the parts you want and how they relate to one another. I recommend sketching a plan of your robot—a block diagram as a guide to the connected code and parts, which we will explore in this chapter as well.

In this chapter, we will be covering the following topics:

  • Looking at what's inside a robot
  • Exploring types of robot components
  • Exploring controllers and I/O
  • Planning components and code structure
  • Planning the physical robot

Technical requirements

For this chapter, you will require the following:

Looking at what's inside a robot

We can start by looking at a robot as a physical system. In Figure 2.1, we can see a simple hobby robot:

Figure 2.1 – An assembled hobby robot

Figure 2.2 shows it in its disassembled form:

Figure 2.2 – A hobby robot's components laid out

The component groups in Figure 2.2 include nine types of components:

  1. The chassis or body forms the main structure of the robot; other parts are attached here.
  2. A castor wheel balances this robot.
  3. Two drive wheels. Other robots may use more wheels or legs here.
  4. Motors are essential for the robot to move.
  5. A motor controller bridges between a controller and connected motors.
  6. A controller, here a Raspberry Pi, runs instructions, takes information from the sensors, and processes this information to drive outputs, such as motors, through the motor controller.
  7. All robots must have power, usually one or more...

Exploring types of robot components

Before we look at the types of motors and sensors, let's get a brief understanding of what each of them is.

A motor is an output device that rotates when power is applied. Motors are a subset of a type of machinery called an actuator. It is an output device that creates motion from electrical power. This power can be modulated with signals to control movement. Examples of actuators are solenoids, valves, and pneumatic rams.

A sensor is a device that provides input to a robot, allowing it to sense its environment. There are more sensor types than a single book can list, so we'll keep to the commonly available and fun-to-use ones. Displays and indicators are debug output devices, for giving feedback on the robot's operation to a human user/programmer. A few of these will be covered in this section.

Now, let's look at them in detail.

Types of motors

There are a number of different kinds of motors that robots commonly...

Exploring controllers and I/O

At the center of the robot block diagram, as in Figure 2.3, are controllers. Robots usually have a primary controller, a computer of some kind. They may also have some secondary controllers, and some more unusual robots have many controllers. This book keeps things simple, with your code running on a conventional central controller. The controller connects all the other parts together and forms the basis of their interactions.

Before we look at controllers, we need to get a better understanding of an important component that connects controllers to other components, I/O pins.

I/O pins

I/O pins are used for input and output from the controller. They give the controller its ability to connect to real-world sensors and motors.

The number of I/O pins on the controller is a limiting factor in what you can connect to a robot without using secondary controllers. You may also see the term General Purpose Input Output (GPIO). Controller I/O pins have...

Planning components and code structure

You've now briefly seen some components you might use in a robot, and you've encountered a block diagram to put them together. This is where you may start taking the next step and thinking further about how to connect things, and how the code you write for them will be structured.

Code is easier to reason about when taken as logical blocks instead of one large lump. Arranging code in ways that are similar to a hardware functionality diagram will help navigate your way around as it becomes more complicated.

So, let's return to the robot block diagram in Figure 2.3 to think about what we'll need to handle in our code for it. That diagram has three sensors and two outputs. Each component (sensor, output, and controller board) may need some code to deal with it, and then you need some code for the behavior of combined modules.

Motor controllers come in many flavors. They have different ways to output to motors, and they...

Planning the physical robot

Let's now put all of this to use and plan the layout of the physical parts of robot that we are making in this book. While we go through chapters, we will be adding new components each time, and keeping an overall map in our minds as we go helps us to see where we are. It is quite exciting to start to picture all the things a robot will do. Let's start with a list of what our robot will do and be:

  • It will have wheels and be able to drive around the floor.
  • It will have a Raspberry Pi 3A+ controller.
  • It will have a motor controller for the wheels.
  • It will be able to indicate its status with a set of multicolored LEDs.
  • The robot will use a pair of servo motors for a pan and tilt mechanism.
  • It will be able to avoid walls and navigate around obstacles with either ultrasonic or laser distance sensors.
  • It will have an encoder per wheel to know how far it has moved.
  • The robot will use a camera to sense colored objects...

Summary

In this chapter, you've been able to see a number of the different component parts that go into a robot, and through a block diagram as a plan, start to visualize how you'd combine those blocks to make a whole robot. You've seen how you can quickly sketch your robot ideas on an envelope, and that drawing tools on a computer can be used for a neater version of the same diagram. You've had a quick tour of motors, sensors, and controllers, along with a few ways, including analog, digital, PWM, and data buses, for controllers to communicate with the other devices connected to them. Following on from this, you've seen a plan of the robot we will build in this book.

In the next chapter, we will look at Raspbian, the operating system used on the Raspberry Pi in our robot, and start configuring it.

Exercise

  1. Try creating a block diagram for a different robot, thinking about inputs, outputs, and controllers.
  2. Are the Raspberry Pi 4B and 3A+ still the most recent versions? Would you use another model, and what would be the trade-offs?
  3. What are the drawbacks of the laser ranging sensor versus the ultrasonic distance sensor?
  4. Try drawing an approximate physical layout diagram for a different type of robot with a different controller.

Further reading

  • Raspberry Pi Sensors, Rushi Gajjar, Packt Publishing: Learn to integrate sensors into your Raspberry Pi projects and let your powerful microcomputer interact with the physical world.
  • Make Sensors: A Hands-On Primer for Monitoring the Real World with Arduino and Raspberry Pi, Tero Karvinen, Kimmo Karvinen, Ville Valtokari, Maker Media, Inc.: Learn to use sensors to connect a Raspberry Pi or Arduino controller with the real world.
  • Make: Electronics: Learning Through Discovery, Charles Platt, Make Community, LLC: This is a useful resource if you want to find out more about electronic components and dive deeper into the individual components.
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learn Robotics Programming - Second Edition
Published in: Feb 2021Publisher: PacktISBN-13: 9781839218804
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple