|
12 Doors Down: Tutorial
Tutorial for 12 Doors Down
Here, we start the tutorial of the ROBOTIX event, 12 Doors Down.
First of all, let us review the problem statement. The robotix.in site says that
"Just make one autonomous and one manual robot such that the manual bot guides the autonomous bot out of a square grid of cells covering a specified number of checkpoints and reaches the end point."
Now, we take a closer look at the problem statement. The manual bot has to first REACH the cell next to the autonomous bot. So, it has to move around and open doors. Therefore, the manual bot is a mobile robot with a mechanism to move and a mechanism to open and close doors. This will be covered in the tutorial. Then, the autonomous bot has to move whenever it sees that just one door is open. In this case it needs a mechanism to detect the presence/absence of doors. This will be covered. Plus, we need to stop the bot from moving once it has reached the center of the next cell. For this, an intersection of 2 white lines has been provided. So, it needs a mechanism to follow the white lines and detect the intersection. And, we missed a thing, the basic drive of the autonomous bot, it needs to be a CONTROLLED one! For that, we explore stepper motors. Or, we can use uncontrolled motion with a feedback arrangement.
So, to cover up all the necessary details, we break down the tutorial and in the end sum up with a basic algorithm to solve the problem statement.
We divide the tutorial into the following divisions:
The simplest drive, the Differential drive is explained here.
Differential Drive, as the name suggests, is the drive caused due to a "difference".This is chosen by beginners generally for its simplicity and ease in use. Actually, the rotational motion of the bot occurs in a differential drive due to the difference in the direction of rotation of two different wheels. When it is to be moved forward/backward, the two wheels rotate in the same direction.
It basically contains two wheels controlled by two DC motors(preferably geared) on one axis, and one extra caster wheel for support.
For more information on constructing a differential drive, you may check the link Differential Drive
If you are having problems with this, you may put a query on the technical forum.
Now, if you are happy with constructing the drive, we come to controlling it.
Specifically for manual robots, one good method of controlling it is the H-bridge. It is basically controlling one motor with two single pole switches.
Two switches can be set on/off in 4 different ways, each way corresponds to rotating the motor clockwise, anticlockwise, braking it, or allowing it in free-running condition.
The circuit is very simple.
When the left high and right low are switched on, the motor moves in one direction. When the right high and left low are switched on, the motor moves in the opposite direction. When both the high side switches are switched on, the motor brakes and comes to an instant halt.
When both the low side switches are on, the motor is in a free running condition and does not force/resist motion.
You can learn the H-bridge in detail here H-bridge
For the autonomous robot, two stepper motors will be used, and the differential drive will be used, but it will be controlled by the microcontroller.
Mechanism to open/close the door
Two mechanisms to open/close the door are explained.
Mechanism 1 Using a Rack And Pinion mechanism
The entire set up of the mechanism should be parallel to the door.
Keep the pinion stationary and keep the rack movable. Attach a hook to one end of the rack and use that to catch the hook on the door. Make the pinion rotate with the help of a high torque motor, so that the rack moves in one direction. This would cause the motion of the door.
Mechanism 2: Moving the bot itself with the door.
One hook is attached to a side of the bot. Then, use the hook to catch the hook on the door. Move the bot in either direction to open/close the door accordingly.
Detection of open/closed doors
For detecting open/closed walls, we can use Infra Red(IR) proximity detectors. This is basically an IR emitter-IR receiver pair. The emitter emits IR rays, which bounce back from the obstruction(wall/object) and reach the receiver. The voltage drop across the receiver is dependent on the distance.
The total details of the IR proximity detector can be found here
Once you are clear with the working of the sensor, you may continue to the next part, calibration.
It can be calibrated to give a high at a desired distance. Assuming the use of a comparator, e.g. LM339 has 4 comparators, we can have a preset voltage value with the help of a variable resistor on the negative terminal of the comparator and the voltage drop across the resistance adjacent to the IR receiver on the positive terminal. Then, keep the emitter receiver pair at the required distance from a wall (not paper) and measure the voltage drop across the mentioned resistor. Then, turn the pot so that the voltage is the same as the value of the measured voltage. Then, we have a calibrated proximity detector! But, mind the fact, if you are using it for the first time, you may have several problems regarding the calibration. Mostly, beginners face the problem with the circuit, i.e. shorts, loose soldering etc.
To check whether your IR LED is working or not, simply view the LED using a phone's camera or any digital camera available, and the LED can be seen glowing.
But, if you have bought a ready made one, then you shouldn't have any problem with it. If, in any case you are facing problems, you are free to post it on the technical forum.
These generally work till distances of 25 cm.
The above sensor is a quite complicated one, it works on a single frequency. i.e. TSOP sensor.
Now, to detect an open/closed door, calibrate the IR proximity detector at a distance a little greater than the distance of that sensor from the door. So, when the door is open, it gives a low, and when the door is closed, it gives a high.
In the current problem statement, we can attach 4 such sensors on all 4 directions of the bot, so that a door can be detected in any direction.
Detection of the line intersection and line following
The line intersection is useful for the bot when it is moving from one cell to another. When it does this, it needs a landmark in the next cell where it has to stop. That landmark should be at the center of the next cell. So, an intersection serves as a useful thing which once detected, means that the bot has reached the center of the next cell!
Now, detection of the line intersection can be done with the IR proximity detector. But, debugging the sensor becomes very hectic, as you can't see which emitter is actually emitting, while the bot runs. So, an alternative method can be using visible light instead of Infra Red. In this case, you can always see when the light is being emitted and hence the debugging becomes easier.
So, we can use an LED-LDR combination i.e.Light Emitting Diode and Light Dependent Resistor Combination. LED is simply a small bulb-like thing which emits light on being provided DC power.
LDR, as the name suggests, is a resistor whose resistance depends on the intensity of the light incident on it. The resistance is inversely proportional to the intensity of the light. It generally varies around the 10k Ohm range. So, using a 10k Ohm resistor in series with the LDR should be a wise choice. This works on almost the same principle as the IR proximity detector. But, there is a slight difference. The difference comes in the calibration and the way it detects the white area.
Some of the required details can be found here
LDR-Photoresistor
Mechanism of working
Basically, a small intense red/white LED in series with a 120 ohm resistor is sufficient for the light emission.
Now, for detection of the line intersection, we have to use a certain property which differentiates black color from white. We use the fact that the white surface reflects more light than the black surface. Light is emitted from the LED, reaches the surface and is reflected back, to be received by the LDR. So, the voltage drop across the 10k resistor will be greater when the sensor is facing the white surface. We connect this across the comparator, again with a preset value attached to the negative terminal. Hence, we get a high output for the white surface, and we have detected the line intersection!!!
The calibration is a bit different in this case. Here, we keep the sensor above the white surface. Measure the voltage drop across the 10k resistor. Note the value as V1. Then repeat this with the sensor above the black surface. Note the value as V2. Turn the preset so that the voltage supplied to the negative terminal of the comparator is (V1 + V2)/2.
And, we have a calibrated sensor! ready for work!
You can check the following link for more details.
Kam Leang robotics
How to build a line follower, and how to use these sensors are explained in the last section.
Microcontrollers
A lot of description has been given about the detection of the doors, the central white circle. But, how do we use it? we need to have some sort of a system which takes these data as the input and correspondingly plans the motion. Now, since this is an autonomous event, the bot needs to be self controlled. So, using a computer is ruled out. We need something which performs small processing operations like this, and can be attached to the bot itself. A good option can be using microcontrollers. Microcontrollers are basically small processors with input and output ports. These are widely used in autonomous events.
There are chiefly 3 types of microcontrollers used in India. 8051/52, the most common one. AVR microcontrollers and PIC microcontrollers.
Here, the AVR can be used. AVR is chosen because it is quite easy to program with the help of the serial/parallel ports of the desktop computer. The programming circuit is the easiest and cheapest to build. The programming can be done in most of the common languages such as C or Assembly language.
Now, there is a basic mechanism followed to make a working AVR. Say for instance we use Atmega16, which is one of the members of the family of AVR microcontrollers. The entire architecture, working, details etc. can be found in its Datasheet.
The mechanism goes as follows : write down the code in a valid programmer's notepad or visual C++ (depends on the language you are using, we take C as the base language here). Then, compile it using WinAVR. Then, using a programming software such as PonyProg, connect it to the programmer circuit, which can be built or bought ready made, and over!
One such programmer circuit is shown here . You can also buy it from any of the roboshops.
To learn the coding of the program, you may check the following links,
http://www.omegav.ntnu.no/avr/resources.php3 (for material)
http://209.85.175.104/search?q=cache:9B6kteeE_CsJ:www.engr.sjsu.edu/bjfurman/courses/
ME106/projects/auto_temp_control.pdf+delay.h+lcd.h+atmega&hl=en&ct=clnk&cd=15&gl=i
n&client=firefox-a#14
(for sample code with timer)
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=320566 (for avr timer)
http://members.shaw.ca/climber/avrtimers.html (for timer n other links)
http://avrbeginners.net/ (complete basic)
http://www.ee.iitb.ac.in/uma/~kartikmohta/tech/avr/tutorial/ (for more sample codes)
http://winavr.scienceprog.com/ (different topics)
Now, we look at one important part of the tutorial. i.e. the burning of the code you write into your microcontroller. It is generally quite confusing for the first time users, but becomes subsequently simple once you are comfortable with it.
The procedure and some tips to program it is as follows
- For compiling the code, use WinAVR, it is freeware. Download WinAVR
- For burning the compiled code, use PonyProg for parallel/serial port programmers.
Note : - The USB to serial converter CANNOT be used with PonyProg, because it uses its own interface for burning and it is not compatible with the hardware. - Always refer the datasheet while programming, it is more informative than any book!
- Run calibration and interface setup from setup in PonyProg, and run appropriate setup according to your hardware.
- Open the flash file you want to burn on the microcontroller and click on Write Program Memory.
Always check power supply voltage and polarity before doing anything with the chip.First burn fuesbits setting on chip according to the chip and oscillator, because the AVR chip gets damaged easily. - Now, if you are done in your first attempt, it is well and good. Otherwise, check the power supply well, check for loose connections from the computer side as well as the computer side.
- For debugging purposes, you can use AVR studio, which can be used for simulation.
- Before compiling the main code, you need to make a MAKEFILE, which will be described later.
- After the MAKEFILE is made, you need to change certain settings in it, according to our needs.
- F_CPU(frequency of the oscillator), which is by default 8000000 should be changed to 1000000, if no external oscillator is used. TARGET must be changed to our file name WITHOUT any extension. e.g. "XYZ" instead of "XYZ.c"
- Always take care of AVR Registers, e.g. before taking the input from the ADC, the ADMUX registers must be set to proper values.
- Change fusebits very very carefully! Because once AVR is locked, its nearly impossible to unlock it. Refer datasheet for information about the fusebits.
Making the flash file
- First install WinAVR
- Open Programmers' Notepad.
- Make a new file for your format ( .c or .cpp), write down the code, and save it.
- Then, go to Start -> All Programs ->WinAVR ->Mfile
- Set these options - makefile-> Main file name =name of ur file WITHOUT EXTENSION
makefile-> MCU Type=which chip you are using like ATmega 16 or ATmega32
makefile-> ouput format=hex (default)
makefile-> Optimization level= s (default)
makefile-> Debug Format = AVR-ext-COFF
makefile-> Programmer which programmer for AVR u r using
makefile-> which port u r using for burning (This is implemented only if u r burning through winAVR) - Then Save As and save it in the same folder (i.e. ur code file .c or .cpp)
- Then open it with notepad and change F_CPU value (i.e Frequency of XTAL oscillator you ar eusing) (default 8000000)
- Now go to winAVR and open your code file (i.e .c file)
- Go to Tools and click on "Make All"
You will get your flash file in the same folder.
It can be burnt using PonyProg.
As described in the introduction, we need controlled motion. To make a bot go from one pre-defined point to another pre-defined point, we need to have a control over the motion, i.e. a predictability of the motion of the wheels of the bot. The normal DC geared motors are not usable as they have a very low predictability. They can be used when a proper feedback mechanism is placed, which will be explained later. So, we need to have a certain motor over which we can have total control! This should work as a proper motor for locomotion. Under these conditions, the most widely used motor is the stepper motor. One might argue that servo motors also have the property of controlled rotation, so why not these? But, the fact is, servos are quite costly and less available as compared to stepper motors. A single stepper motor may cost just 150 INR, but a servo may cost around 700 or more. Plus, servos are designed to have a rotation range of 180 degrees. We need to modify it for continuous rotation.
Stepper motors are basically motors used for controlled step by step rotation. Traditionally, several instruments have stepper motors. The printer which we use uses a stepper motor. The small machine which is used for printing price tags at retail stores also uses a stepper motor. Most of the stepper motors available in the market are those extracted from faulty instruments which don't work anymore but have a good motor. But, take care, that most of these have quite low torque ratings. It is suggested that you buy one with sufficient torque.
Stepper motor works on pulses. Pulses are delivered after a certain interval to the motor. This interval is termed as the delay provided. It generally ranges around 40 ms. This can be done with the help of the microcontroller. At each pulse to the motor, it rotates by a certain angle. Unipolar steppers rotate by 1.8 degrees and Bipolar by 0.9 for every pulse. Hence, we obtain a control over the rotation.
The accuracy with a unipolar stepper motor is enough for the current problem statement. Now, for each pulse given, the shaft rotates by an angle of 1.8 degrees. We can attach a wheel to each motor and we get linear motion. Since the rotation is controlled, the linear motion is controlled too and we achieve controlled motion of the bot!!
Some tutorials are given
Driving Steppers with AVR Microcontroller
Stepper control basics and microcontroller interfacing with PIC
Basic working
Stepper control using L298 (video)
Theory with interfacing
Now, the most common problem with loss in control of the motor, is that it misses steps. i.e. at some situations, it jumps a few steps. This happens when the holding torque is less than the torque externally applied.
This can be avoided by using motors with sufficiently high torque.
Over all algorithm for programming the autonomous bot
Here, we'll see one algorithm which can be used for programming the autonomous bot.
For line tracking, one can refer to the standard algorithms available.
Line following algorithms
Also, for navigation in the grid, you can check this link:
Grid Navigation algorithms
This is just the idea of one basic algorithm, you are free to implement your own.
At first, we review the problem statement. It goes as, bringing the autonomous bot out from the one cell (1,1) to (3,3). So, the commando i.e. the manual bot has to open doors and allow the autonomous bot to enter the next cell. So, to accomplish this task, we open just one door for allowing the autonomous bot to move. However, if the manual bot remains in that cell, it would lead to a penalty. So, the programming of the lost man can be done as --- Put one IR sensor on each side of the autonomous bot. Whenever one side detects low, i.e. there is no door on that side, the lost man should have a proper delay to allow the commando to leave the cell in which it is, and then move to the next cell, and so on. While moving to the next cell, the autonomous bot moves until it reaches the next line intersection, whose detection has been described earlier. Hence, the problem statement can be solved in this manner.
[top]
If you have faced any problem, you are free to post it in the technical forum.






