IAN LANG ELECTRONICS
Inside your head resides a lump of grey goo that is really quite remarkable. By a system of electrical, chemical and possibly mechanical occurences it processes information rapidly and produces an appropriate response. For example, when you go into Pizza Hut you will be greeted by a waitress. Here's what her brain is doing, step by step.
Four of you walk in. The waitress looks and sees you waiting to be seated. Her brain sends a message to her legs to stroll over to where you are and simultaneously counts you, Fat Dave, Big Paul and Little Pete waiting to stuff your faces with filled crusts. When she gets there, her brain activates her smile muscles, tells her voice to say "Table for four?" and makes her hands whip out four menus. You tell her no, six, but the other two (Ginger George and Top-Heavy Tracey from work) aren't here yet. Immediately her brain modifies the prior assumptions to reflect the new data received by her ears and she whips out two more menus. Now she's got to lead you to a table with six covers, so her brain delves into the memory and gives her co-ordinates from where she is now to where the table is, and her eyes tell her if anything is in the way such as another customer, a table, a chair or a horrible sticky child and acting on that information
steer her round the obstacles whilst at the same time she's telling you about the specials that day. You sit down and she asks you what you want to drink. She listens to your order and her brain tells her hand to use the pen that's in it to inscribe legible symbols on a notepad in her other hand. Prior to this it's told her hands to get out her pen and notepad. Once she's got your order she goes and makes it and then brings it back to the table and a few minutes later she repeats this feat with your food order. When you've scoffed your pizza, puddings and whatever else she will calculate (admittedly with the aid of a till) your bill and bring it to you. When you've waddled out stuffed full of deep-pan cheesy crust meatfeast she will clean your table and prep it up for the next lot.
Not only that, she could be doing this for six tables at a time and serving thirty-six people at the same time.Her computing power is enormous. You might want to remember this when leaving a tip.
Pizza Hut do not have any robot waitresses. McDonald's has no robot cashiers, and despite appearances KFC has no robots working on its cashdesk either. No, I promise you, they are, out of the chicken place, regular people just like you and me. You try working in KFC and you'll get into a robotic frame of mind too.
The reason that the above and indeed the Ritz, the Savoy and the Fat Duck have no robot catering staff is that an electronic brain cannot process anywhere near as much information per second as the waitress in Pizza Hut can. Even if the waitress is particularly bad, I promise she makes a better job of it than even Asimo would.
Anything man-made is not going to be nearly as adept as a blob of grey goo in somebody's head simply because of the limits of technology. So, in this part of the section we are going to look at what a robot brain consists of, starting at the base levels and going on to more advanced concepts as we progress.
Here's where we start and it doesn't get more basic than this:
This is exactly what the waitress does. Her inputs are her eyes and ears, and her outputs are her voice, arms and legs. For our electronic devices, inputs are a sensor of any description and outputs are motors, actuators, LEDs or any other device that lets a human or another machine know what's going on. Now, for a ROV such as BAMbot (see Scrapbots) There's not much processing goes on. You press a button on the radio transmitter, it transmits a signal of a certain frequency. Depending on the button you press, this is one one of four frequencies in the 40 MHz band. The receiver picks up this signal and sends out a high input on the correct channel. When that's high, it allows a signal to the input pin or pins of the motor driver by saturating a transistor. Depending on which pins are high and which low on the motor driver, BAMbot's motors will act accordingly in one of the following states: Both motors off, Both motors turning clockwise, both turning anticlockwise, motor one turning anticlockwise and motor two turning clockwise, motor one turning clockwise and motor two turning anticlockwise. Consequently BAMbot can't do much, just go forwards, backwards, left and right and stand still. He does not have speed controls and putting anything else switchable on him is going to be out of the question because there only four channels to work with. If we want a large number of channels we can of course use a transmitter with such; RF solutions will sell you a Bravo module with eight channels. You'll need two at least, one for the transmitter and one for the receiver, and with clever transistor logic you can combine many more together to make a complex switch to however many outputs you want. A Bravo module costs (at the time of writing) £11:57 (or £7:78 if you buy 100 or more) and it is fine if you want to drive a robot by telecommands but it won't let you do a great deal other than drive motors and it's more suited to domestic and industrial switching systems. In addition you need a complex logic board to control the outputs from the modules if you use more than one.
Clearly this is not going to suitable for a bot that needs a drive, servo control and a discrete voltage system, and it won't help at all if the device has to have any degree of autonomy. So, almost universally, a modern robot will have a microcontroller embedded into it as the brains of the operation. Let's look at how a typical device might work.
Microcontrollers come in the physical hardware (a large chip, some resistors and capacitors and an oscillator which may be external or built-in to the chip) and the software with which to program them. Above is a diagram of the inputs and outputs found. You'll see that digital appears on either side, and indeed on some controllers a digital pin can be either input or output and is known as digital I/O. It is set to be one or the other at run time and can be changed. Within the chip is a pull-up resistor which can be enabled or disabled. Input pins are set to a high impedance state, output to low impedance. You can't put an input to a low-impedance pin- you risk damaging the pin. If you have a chip with low-impedance pins you cannot change by programming you can put a 100 MegaOhm resistor before the pin to make it high impedance, but of course you can't do this at run time. A high impedance pin takes very little current from the circuit it is sampling but it can't provide a high current output; it will not be able to saturate a transistor properly. Microcontrollers work in 3.3 and 5V as a rule; don't input more than the stated voltage to a pin or you will damage it. Digital outputs will always output the full voltage of the microcontroller. It's either full on or full off - no inbetween. Analogue (or for our American readers, analog) pins are inputs though on some microcontrollers they can be set to be digital outputs if needed. An analogue pin reads an analogue voltage which can be anywhere between 0 and whatever the working voltage (3.3V, 5V) of the microcontroller is. A digital one will read 0V and a threshhold, say 2.5V and if it is under the threshold it is low, if at or over the threshhold it is high.
PWM stands for pulse width modulation. PWM pins put out a variable voltage. It's always the full digital voltage, so if the microcontroller works on five volts the PWM pin puts out five volts. I hear you now say "Well, how is that variable then you wazzock?" but the clever bit is even though the voltage level does not vary the time it is supplied for does. If you switch that pin on and off roughly five hundred times a second, you get five hundred pulses. BUT- in those five hundred pulses, the voltage can be on for some of the time per pulse, and off for the rest. Let's say the bottom is 0V and the top 5V. If, in one pulse, the voltage is on for 50% of the time and off for the other 50% then you have a pulse lasting 1/500th of a second but a voltage lasting only half that. Any device receiving that pulse where the voltage is on for half the time gets 5V for 1/1000th of a second and 0V for another 1/1000th. This means the mean voltage it gets in that 1/500th of a second is in fact 2.5V and that's what it will see. If you feed this to a Darlington transistor at its base via a suitable resistor, you can take a voltage from the emitter that varies according to whatever level the PWM is being put out at. If you attach a motor, the speed can be varied. Here's how it's done:
This is a design by Meccano which they use in their Electronics in Meccano course and it shows two transistors linked in the Darlington fashion, sharing a collector and with the base of the second controlled by the emitter of the first. In fact you can get Darlingtons in one compact package, the BDX38 being common. In this design the 10k potentiometer is doing just the same job as a PWM output from a microcontroller. Here's the snag: being digital, a microcontroller can't be as precise as a potentiometer. It varies in discrete steps rather than the analogue
values of the potentiometer. Still, the difference is too small to be really noticeable if you code up the microcontroller in the right way. PWM is also used to signal to servos.
That leaves us with serial Rx and Tx. Those of you familiar with radios will know that Rx is receive and Tx is transmit. Those of you familiar with computers will know that serial means data pushed through one bit at a time. That's exactly what they do. They transmit and receive serial data. This means we can do a lot of things. We can have a wireless control system for a ROV. We can hook up to a computer. We can make the robots talk to each other or to a remote co-ordinator unit. If you read about Rudebot in one of the earlier chapters then you'll know I've equipped him with an XBee. It receives data from a transmitter and Rudebot does as I tell him because the microcontroller (an Arduino Pro-mini) parses that data received from the XBee through its data out (DOUT) pin and through the Arduino's serial Rx. In the transmitter, another Arduino senses the movement of the joystick through the analogue inputs, parses it and sends a piece of data through its Tx pin to the pin of another XBee which is data in (DIN). The XBee transmits that data and that's what the XBee in Rudebot receives. Piece of cake. There's data for direction of motor, speed of motor and position of steering servo, and there will be data for the pointing servo and the voiceboard when I finish him.
It follows then that as well as direct control from a radio (or possibly an IR system) the microcontroller can handle inputs from the robot itself, which is an interesting concept, because what we can now do is do away with human controls and let the robot go on its own. For instance, we could use an IR telemetry device to tell the robot when it is coming to an obstacle, and a group of them to let the robot decide for itself where to turn to avoid it. We could use microswitches to tell the device if it has come up against an obstacle. We can use a reference so the robot knows when the battery is low, and an IR beam to guide it back to its charging station. We can use a radio link to let it know it is in the presence of another robot. We can use probes to let it follow a line and short-range radio to instruct it when it gets there. The possibilities here are manyfold, but the lesson is clear- we need both hardware and software if we are to create anything more than an electric vehicle. This can be achieved only with a microcontroller. In these pages we use Arduino, but the circuits are valid for any other microcontroller too. Here's a picture of the Pro-mini, shown much larger than life, with the bits as shown above marked.
In green we have the digital pins with 3, 5, 6, 9, 10 and 11 able to provide PWM. In yellow the analogue input pins, and inpurple in the top right-hand corner there the Rx and Tx pins. The rest are VCC (the tap for a regulated 5V) RST (reset, assert by bringing low) GND (0V or negative) and RAW into which you feed the power supply, recommended 9V or below but not less than 6V. The six on the extreme right are the connecting interface with which the board is programmed using the Arduino IDE on Windows, Mac and Linux operating systems. You need either an FTDI cable or a USB to serial convertor- no USB is supplied on board because of the space consideration as the whole board measures 0.7 by 1.3 inches (~ 18 mm by 33 mm).
In summary then your robot will be a collection of electromechanical bits unless you give it some sort of control system. The constituents of an advanced control system are the input mechanisms, the processing core, and the output mechanisms. When the output mechanisms react to the input mechanisms in a predictable and reliable way and can be made to alter or refine their behaviour for a given set of conditions, this is known as physical computing. Physical computing is at the heart of robotics, and microcontrollers are at the heart of physical computing, hence microcontrollers are at the heart of real robotics.
Ian Lang, September 2013