We’ve been fact-finding for our robot-building mission. Before we start our robot-building journey, we’ll make a rough plan of what we want to do, then refine it. We’ll make important decisions, which we can examine further as we start to build the robot.
An overview of robot planning
When planning the robot, there are several things we need to consider:
- What do we want this robot to do? What is it for?
- What style of robot is suitable?
- What kinds of sensors or outputs will we need?
- What rough shape and size will it have?
Once we’ve answered these questions, we can make further decisions about what we build. These don’t require much detail. Robotics is full of interesting diversions, making it tempting to jump between ideas. By having a constrained plan and working to it, you can keep your pace on getting a robot built, saving distractions and cool ideas for the next robot or three!
What do we want this robot to do? What is it for?
Will the robot solve a problem, clean your kitchen, explore a space, deliver packages, impress guests at a conference, or compete in a robot competition?
The robot we’ll build in this book has several purposes:
- Exploring Raspberry Pi Pico and its capabilities
- Trying out sensors
- Writing algorithms guided a little by challenges in robot competitions
- Navigating a known space
- Building a custom chassis, adaptable for future ideas
- Keeping it simple enough to get started
With these goals in mind, we can look at the specific details.
What style of robot is suitable?
There are many robot styles. We should choose one, probably the simplest possible for our goal. Take a look at the following diagram for a selection of different robot styles:
Figure 1.7 – Different robot styles
The first robot style is a robot arm used in industry. These are fascinating and fun to build. However, they do not satisfy our goals of building a robot chassis to try out sensors.
The next panel shows a quadcopter drone—an unmanned aerial vehicle (UAV). These are complicated to build and program, so they do not meet our goal of keeping it simple.
The third panel shows a walking robot—a hexapod. These require controlling many servo motors. Their power usage and complexity make them an unsuitable but exciting option for a follow-up robot!
The fourth panel shows a wheeled robot. Wheeled robots can be simple two-wheel-drive (2WD) robots with a roller, such as this one. 2WD rover platforms such as this satisfy our goals of building a chassis and getting to know sensors and algorithms. They can later be made more interesting, with tracks, mecanum wheels, rocker bogies, or individually steered wheels, allowing them to also meet the adaptable goal.
I recommend that we go ahead with a 2WD rover throughout this book but keep the other variations in mind for further robot builds!
What kinds of sensors or outputs will we need?
One of our goals is to try out different sensors. A robot made to navigate spaces will influence the sensors we’ll use. They all contribute to locating the robot.
Good sensors for this include the following:
- Distance sensors: What is in front of the robot? How far are the nearest objects? We might want more than one of these devices.
- Encoders: How has the robot moved? How far did it go?
- Inertial Measurement Unit (IMU): Has the robot turned? What is its position relative to north?
Along with these sensors, we can have simple outputs—the motors that we drive wheels with. As a later extension, we could also add Bluetooth to give us some feedback on our robot’s status. We don’t need to plan all of this yet but leave space for it so that we can extend the robot later.
What rough shape and size will it have?
Now, we have a firm idea of a 2WD robot. We know it probably needs to support the following:
- Raspberry Pi Pico
- A pair of motors with wheels and a caster
- Many sensors and, later, Bluetooth
- Power for the system, including batteries plus voltage conversion
- A breadboard for wiring all of this together
Although we don’t want the robot to be too big, we are going to need some real estate to play with. Let’s start with a rough estimate of 150 mm x 200 mm.
So, we’ve answered some questions about what we want. We will use the next few sections to dive deeper into the planning of this robot, looking at the different aspects of the planning and the choices we’ll make. The first of those is to consider trade-offs.
A note on trade-offs
All designs make trade-offs. The truth is that no design fits all cases, and usually, no design is perfect but will be good enough in the right aspects where it works. We will need to make decisions and read datasheets for parts to also assist us.
One example is size and weight—we already mentioned that we don’t want a large robot. After all, we have a limited workbench size, and larger robots require more power, larger motors, and larger batteries. Additionally, we’d need to work with tougher and—likely—harder-to-cut materials. For a different context and goal, perhaps a large, heavier robot would be more suitable. So, the first trade-off is to keep the robot small but not too small—that is, to keep it simple.
We’ve suggested Raspberry Pi Pico, and the trade-offs from Raspberry Pi there, for example lighter weight, reduced cost, and power.
But what of sensor trade-offs? Every sensor has multiple types, which we will dive into in their respective chapters. They differ in price, features, and complexity.
In many aspects, we can trade having more complexity for reduced weight or cost or more features for a higher cost.
Choosing a robot chassis
We have many options for our 2WD robot chassis. Again, this depends on what we want to learn or achieve. We have stated our goal of building a flexible chassis. Some good options for doing this are as follows:
- Buying a chassis kit
- Adapting a lunchbox or toy
- Doing a scratch build by hand
- 3D printing or laser cutting a chassis
Chassis kits are an easy option but have limited flexibility. Many come with motors, wheels, batteries, and even a motor driver designed for a specific main controller. In this way, they can save time and money, allowing you to focus entirely on the code and sensors, but they offer less opportunity to learn design aspects. It’s often tricky to find a chassis kit with the right shape and size, and as they get larger, they quickly become more expensive.
You could also adapt a lunchbox into a robot chassis—cutting mounting holes for motors, sensors, boards, and other parts can be a good place to learn design skills. However, you’d need to fit your robot electronics and hardware in a constrained space. Note that the curved sides of lunchboxes can complicate things.
Scratch-building a chassis gives you great flexibility. You can learn how to design in CAD and how to use hand tools. Additionally, you need to make choices about the type and thickness of the material, and in doing so, you’ll be able to understand more about making strong robots. You’ll learn how to fit sensors and expand your robot if things get a bit tight. This requires more time and patience than the kits, but the rewards are great.
3D printing and laser cutting require precise designs, along with expensive and specialist tools or services. As you dive further into robotics, and progress beyond a simple 2WD robot, creating more interesting shapes and sensor mounts, it is likely to be an important area of exploration. If you are not confident with hand tools, finding a laser-cutting service for the same parts will achieve good results, but it can be costly.
In this book, so that you can get exposure to the design and hand tools while still giving us lots of flexibility, we will take the scratch-building option. We will learn CAD skills that are transferable to 3D printing. We’ll learn how to cut and drill parts, looking at some premade parts to save time. Additionally, we’ll size our design at approximately 150 mm x 200 mm and modify this if needed. But what about the motors?
Choosing motors
This 2WD motor requires two main drive motors. We could consider stepper motors, which move a little each time they are pulsed, although these bring a little extra complexity—perhaps an idea to keep for later. DC motors, which rotate continuously when powered, seem like the right choice. They will need to be geared so that they have enough power to move the robot, without being too quick and hard to control.
We should keep these motors small and at a low voltage. As we are unlikely to want to build an additional gearbox, geared motors are sensible. There are some options here in terms of the size we are working with. First is the yellow TT motor with plastic gears— however, these motors are not of great quality and take up a fair amount of space. Another option is to use servomotors that are adapted for continuous rotation—however, these can be a little expensive.
A small, common, high-quality but inexpensive option is N20 or micro-metal gear motors. To save space and effort, there are models of these that have encoders pre-fitted. We can use similarly common plastic brackets to attach them to our robot. That makes them convenient to use, too.
Robot wheels
For a 2WD robot, there are a few ways in which to lay the wheels out. One possibility is to have two driving wheels with two idler wheels (that is, unpowered). However, those wheels can drag, making it harder to turn the robot. A common way is to have a third wheel as a caster—either a ball that can roll in any direction or a swivel wheel such as a shopping trolley. Because of the size of the robot, a ball caster seems like a good idea.
The wheels themselves should have a hub that is compatible with the motors that we’ve chosen. A pair of N20 wheels with a diameter of 60-100 mm should be suitable.
So, we have a rough size for our robot, and we know the controllers, motors, and some of the sensors. The next item to choose is the power systems.
Choosing the power systems
A robot isn’t much fun without independent power—by which I mean its own source of power without needing to be plugged into a wall. Usually, this means batteries. It then needs ways to provide power to the control electronics, sensors, external boards, and motors. Take a look at the following diagram for an outline of power distribution in a 2WD robot:
Figure 1.8 – Power distribution in a 2WD robot
In Figure 1.8, the thicker lines show raw battery power connections. A 2WD chassis will need to drive at least two motors, which are power-hungry devices that require a battery connection.
This robot needs to power Raspberry Pi Pico and other sensors. Since we intend to add Bluetooth, we should leave power aside for that. So, the other thick line goes to a regulator for these, making more palatable power for these systems—the raw battery voltage would likely destroy them. The thinner solid lines show regulated power.
The Pico will be sending/receiving electronic control signals, designated by the thin dashed lines in the preceding diagram. These also go to the motor controller. The motor controller will provide PWM-controlled power from the batteries to the motor, modulated by the signals the Pico sends to them. The motor power is shown by the thick dashed lines to the motors on the left-hand side.
Here, we have a few considerations to bear in mind. We require an input voltage that is suitable for the motors and to drive a regulator. We need a regulator that can handle the power capacity requirements for the Pico, sensors, and Bluetooth, and we need batteries that can supply enough current to drive them.
Calculating power requirements
Let’s start with what we know—5V is a good output voltage for a regulator, and where needed, the Pico can further regulate down to 3.3V. A regulator for 5V likely requires 7V or more.
Important note
Voltage measures electrical pressure. A current measures how fast electrical energy flows. Combining both of them shows system power usage. A current in amps or milliamps can be used as a stand-in for power in watts when the voltage is known.
Let’s look up the specifications for the N20 gear motors. Perform an online search for the N20 motor datasheet. You’ll be looking for a PDF document. Usually, these have a picture or diagram of the product, followed by the specification and feature tables. If you look for Rated Voltage, they say 6V; however, further down the sheet, there is usually a table relating to the voltage of the motor speed. Based on the motors and regulator basics, an input voltage of 7V-12V would make sense.
Our electronics don’t operate on voltage alone and require a current to operate. So, a regulator will need to handle the minimum current requirements. We’ll need to look at some datasheets and specifications for the other parts. We will include sensors. For Bluetooth, we will include a low-power Bluetooth Low Energy (BLE) board using the highest current measurements from https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-uart-friend/current-measurements.
We’ll base it on worst-case values so that we can handle them. Let’s start by looking at datasheets and gathering numbers into a table, as follows:
Table 1.3 – Device power requirements
Chapter 3 of the datasheet for Raspberry Pi Pico (which can be found at https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf) shows the electrical specification, with peak currents at a little under 92 mA (milliamps—a measure of current). We’ll round this up to 100 mA as a margin.
The Adafruit Bluetooth board uses only 15.2 mA when fully active, but we can round it up to 20 mA to be generous. The sensors need maybe 50 mA of extra room to accommodate them.
We can add these estimates together to suggest a minimum current specification. Based on these datasheets and estimates, any regulator capable of over 400 mA will be plenty.
Choosing a regulator
Motor control and power supplies can be totally separate concerns, giving great flexibility, but this can take up more space. There are boards designed for Raspberry Pi Pico that allow you to control motors while supplying power to Raspberry Pi Pico. However, will they supply 400 mA?
Kitronik has some neat Raspberry Pi Pico motor boards—a small motor only, along with a larger robotics board with servo motor outputs and a prototyping area. However, the supply for the Pico on the robotics board datasheet has 100 mA for peripherals, which won’t work.
Now, we understand that we need a regulator that is capable of outputting 5V, at a minimum of 400 mA. We want something small and simple. A suitable device for this is a Universal Battery Eliminator Circuit (UBEC). These can handle 3 A. We’d put this through a VSYS pin on the Pico.
Choosing a motor controller
The suggested motors are small. Motors have a stall current—that is, the power they draw if they are trying to move and block a logical maximum. For the N20s, their datasheet suggests 350 mA at 6V. It might be a little over that, perhaps 550 mA. A motor controller needs to handle a little over this peak per channel—motor controllers that are unable to handle motor load tend to go up in smoke! Take a look at the following two common simple motor controllers:
Figure 1.9 – An L298N motor controller next to a TB6612fng
In Figure 1.9, on the left-hand side, you can see the very common L298N—internet searches suggest this handles 2 A per channel. They are small, inexpensive, and easy to find. However, this is a 5V logic device. Raspberry Pi Pico outputs 3.3V logic, which might not work properly with this controller without logic-level conversion.
On the right-hand side is another good choice, the Toshiba TB6612fng. These handle 1.2 A per channel, which is a bit less than shown previously but still good enough. It will handle up to 15V for controlling motors and logic voltages from 3V to 5V, so it won’t require level shifters for Raspberry Pi Pico. There is a module from SparkFun for these, which will work well with the Pico and is small enough to fit on a breadboard next to it.
Additionally, we should plan to have a power switch on the breadboard from the batteries to the motor controller and regulator. Talking of batteries, we still need to select them.
Choosing batteries
We also need something to go through the power regulator—batteries.
While we can (and should, at a more advanced stage) consider Lithium-ion batteries, the type used in remote control cars, the simplest possible option is AA batteries. For our motor and regulator choice, 8 x AA gives 12V. These are easy to buy and replace but take up a lot of space for their power output. Our motors don’t require a lot of current, so they will be good enough.
Now that we’ve examined our power requirements and some solutions, we’ll take a look at which pins are being used on our Raspberry Pi Pico and ensure that our plans for hardware won’t conflict.
Pin usage
Our Raspberry Pi Pico has many IO pins, but we need to consider whether all the items we intend to connect to it will be able to simultaneously connect to it.
Let’s re-examine the specifications for the Pico at https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html:
- 26 General Purpose Input/Output (GPIO) pins
- 2 x UART, 2 x SPI, and 2 x SPI
The motor controller will consume two pins per motor, and we know these motors come with encoders, with a further two pins each. That means, so far, we’ve used 8 of the 26 IO pins. This should leave us plenty of room for expansion.
Now that we’ve checked our basic concept, we’ll move on to test fitting—an approximation of how we’ll build the robot.