Cookie the Table Following Robot – Tutorial
September 5, 2010 10 Comments
I’m back again for another tutorial on robots. This one will be on the table following robot of which a video was posted earlier. For those who haven’t seen it, here is the video again (Wish I had a larger table 😦 ):
Well I initially started on this more than a year back but gave up because I didn’t have time and this was my first try at a micro-controller based robot. Later my friends decided to make a robot with this as one functionality and needed a little help so that’s how I ended up completing it.
If this is your first time with building circuits, I’d suggest you go through my first tutorial on robots (The Simplest Line Follower). It really is the simplest robot I have come across. For this you need to be familiar with some basic soldering.
You also need to be familiar with the 8051 based micro-controller, AT89C51 (made by Atmel). You need to know the basics of this chip and need to know how to write a program for it in C. I guess you could use any other controller as well with a few changes in the program.
In this tutorial, I will first describe the circuits that make up the robot and explain how these work. Next I will get into the construction details of the entire robot. After this, we’ll look at the code and finally, how you can improve this and my next robot plan (already working on it slowly).
The circuits for the robot weren’t my own. I used the circuits for the sensors and voltage regulator from this site:
A robot mainly requires the following blocks:
- A sensor system.
- A controller.
- An actuation system.
- Power supply.
Now lets look at the circuits for these one by one.
The sensors consist of IR (Infra-Red) photo-diodes and IR LEDs. I used four of these in my robot. Lets have a look at the circuit.
You can see that this one circuit contains all four sensors. The outputs of these sensors go to a port of the micro-controller. You can see that the above circuit has a single block repeated for each IR transmitter-receiver. Lets look at one of these blocks to understand how it works. Before that, I would like to add that, in my circuit, the transistor (see the circuit from the link above) is replaced by an IR photo diode connected in reverse bias.
If you look carefully, this is a comparator. If you do not know how an op-amp comparator works, I’d suggest reading about that first. You could refer to an book on electronics (Electronic Principles – Albert Malvino, my favorite). Wikipedia has some info as well. Now a comparator, as the name suggests, compares voltages. The op-amp has two inputs. When used as a comparator, the voltage levels at these inputs is compared and the output depends on their relative values. For the circuit to work, one of these voltages must be fixed as a reference. This is done with the voltage that enters the op-amp’s non-inverting terminal (look at the circuit above). The voltage is fixed to a value between Vcc (5V) and ground using a preset (potentiometer). Now the other pin goes to the IR photo diode – the actual sensor. The rest of the circuit is used to power an IR LED. This is used as the source for the IR signal.
Now this is how it works. The reference voltage is fixed (using the preset) to a level such that when IR light falls on the photo-diode, the voltage of this diode is above the reference and when no light falls on it, the voltage is below the reference. This is where the comparator’s operation comes. When no light falls on the photo-diode, since its voltage is below the reference, the output of the op-amp will be 0V. On the other hand, when light falls, since the voltage of the photo-diode is above the reference, the output of the comparator is 5V. Thats about it. Simple enough isn’t it? For the table follower this is used to figure out whether the robot is on the table or is at the edge. The IR LED shines a ray downwards. When the robot is on the table, the ray is reflected back and is received by the photo-diode and the comparator gives an output of 5V (logic 1). However if a sensor is at the edge, the light is not reflected and the photo-diode receives nothing causing an output of 0V from the comparator (logic 0) and thats how the sensor system works.
As I said before, the controller is 8051 based. I used Atmel’s AT89C51. Depending on the kind of IC programmer you have you can probably use any 8051 variant. Many of my friends use Philip’s (now NXP) 89V51 since the programmer is much cheaper. The link above does have a circuit to use a 2051 controller. This can be used to build a 8051 circuit as well. However a ready made circuit board was available so I didn’t want to spend time making my own. Here is a picture of the board (I used this in the servo motor controller project as well).
The board is very easy to use. It contains berg strips for each of the ports.
The controller is obviously dead without its program. However we will look at this in the end.
The actuation system is basically a pair of motors and a motor driver. I’ve used the same system as the line follower (see The Simplest Line Follower). Just like in that robot, I have used helical motors and the L293D motor driver (read the tutorial if you are interested in how this chip works). The only difference here is that I haven’t hard wired the input pins like I did before. All 6 control pins are connected to the micro controller. Here is the circuit for the actuation system.
The Power Supply
Finally we need the system which will power up the robot. We need two voltage levels – 10V for the motors (through the driver) and 5V for each chip’s Vcc input. Unlike my previous robot, I used a single 12V lead acid battery this time with a voltage regulator circuit to give me the 5V level. Here is the circuit for the regulator.
I’m still not sure how this works (if someone does know for sure please do post a comment) but from what I can understand, the diode prevents current surges back into the battery and protects it while the capacitors protect the circuit from spikes (seems to be the most obvious thing). The chip as just is a voltage regulator which converts a 10V DC voltage to 5V.
Putting It Together
Now lets get into the robot’s construction. We first need to look at two things – mounting the sensors and the chassis.
Mounting the Sensors
I thought the simplest way to mount the sensors is to use cardboard (I did the same in the line follower). However I needed a stronger support this time so I stuck three strips of cardboard for each section. Here is the basic idea behind it:
Its quite simple. For each mount, I used a pair of cardboard strips (each made of 3 strips stuck together). Each of these had slots cut out. The width of these slots must allow the LED and photo diode to just fit. Here are some photos of these:
We’ll need a total of four of these. Next lets look at the chassis for the robot.
I used switchboards made of acrylic. These are same as the ones I used to make the IC Trainer Kit. The motors were fixed to this using U-clamps (lots of drilling!). The mounts for the sensors were fixed on these using m-seal. I also used a third caster wheel for the front wheel (like I did for the line follower). Here are some pics:
That takes care of most of the construction. Now we’re left with putting all the circuits we’ve constructed. I fixed the pcb’s with screws (even more drilling!).
Take care of these connection details:
Lets look at a simple schematic of the robot:
The letters A, B, C and D correspond to the positions of the sensors. The sensors are connected to Port2 like this:
Sensor A – P2.0
Sensor B – P2.1
Sensor C – P2.2
Sensor D – P2.3
The motors, as we’ve seen before, are connected to the L293D driver. This is connected to Port1 with these connections:
EN12 – P1.0
EN34 – P1.1
IN1 – P1.2
IN2 – P1.3
IN3 – P1.4
IN4 – P1.5
Use a little imagination and creativity and you you can put this together in no time.
Some More Construction Details…
There were two things I did not mention before. One is that I have included a push button (tactile switch). This button is connected to Port2 bit 7 (ie.e P2.7). I use this to start the robot only when I want after it is connected to the battery. The circuit is quite straightforward. When the button is pressed, P2.8 is grounded and this can be detected in the program.
The second detail I missed out is that I used some kind of holders for the sensors. These are the same as the LED holders I used in the line follower. You can check the pics there or use your own way to keep the LED – photo-diode pair together.
The Finished Robot:
Finally, here is a pic of my robot after construction:
The photo is not of the robot thats in the video. I had taken this one when I first finished my construction. The robot went through a lot of changes after that and I completely forgot to take any photos. Right now the robot is moving on to being more than a table follower (I’ll talk about this later) so the current photo won’t work either.
The code was written entirely in C and I have uploaded it on box.net (check the left sidebar). The code is too long to post and explain here but there are sufficient comments so you should have no problems with it. If you do have any issues, please do post a comment (do not send me an email).
The code was split into multiple files because it was beginning to get too big. The algorithm is quite simple. The robot keeps checking the sensors’ states and decides what it should do next.
Also, there is a text file – LEDCodes.txt. It basically tells you what the robot should to when one more LEDs detect an edge. To understand how I came up with these rules, Keep your robot (or any object) at various positions on the tables edge and see what it should do so that it doesn’t fall off.
Like I said before, the robot is not the same now. Before we go to what all I’m adding to it, I’d like to share a little bit about the robot my friends made for their project because some of the ideas are from them.
Their robot was built as a surveillance bot. It has both an automatic and manual mode. In manual, its controlled from a computer using a wireless system. The software was written both in VB.NET and VB6. When in automatic mode, it behaves as a table edge follower. The robot also has a wireless camera which sends back video information back to the computer. Here is a pic of their robot:
Impressive isn’t it? Looks like a monster compared to mine! 🙂
Alright! Here are the planned upgrades for cookie!
- Remote controlled manual mode – Got inspired to go ahead with this after seeing my friends add this feature. But this isn’t your everyday remote. ;). I was lucky to get a free sample of the Cypress PSoC 3 First Touch Starter kit. This board has an accelerometer and I plan to use this to control my robot. In simple words – to move the robot front, I tilt the board forward. To move left or right, I tilt it in the respective direction. Well it is a plan that seems possible to accomplish. Lets see how long it’ll take.
- Obstacle avoiding system – This will be part of the automatic mode. I’m experimenting with ultrasonic sensors for this and one module has been done. Need to make one more before I can start testing. If this doesn’t work, I’ll have to use the TSOP IR sensors.
- All this in one – Well with all this put together, I intend cookie to work like this – By default, control is given to the wireless remote. However if an obstacle or an edge on the surface is detected, the robot switches to automatic mode, gets out of the situation where it would crash into the obstacle or fall off and then return control back to the remote (I guess I’ll have to use interrupts).
However, things are going quite slow and this will continue till I’m done with my training. Before I go ahead with this robot, I’m also working on an automatic lead – acid battery charger using a circuit I found online.
There are a lot of other things you can do to improve this robot. Try it yourself. Hope you enjoyed reading this tutorial. Will be back soon with another one. Thanks for reading 🙂