Introduction:
The problem is going to be to build a Lego robot with sensors, a motor controller, and a microcontroller that 1. Follows a black tape. 2. Upon reaching the end of the tape will pause for three seconds. 3. After pausing for 3 seconds will return back to the starting point.
The next step in an engineering problem is to come up with a solution. Ideas of implementation must be thought of. There are two possibilities of making a robot come back to the starting point after pausing for three seconds. The first and most obvious way is to make the robot turn around and then drive back to the starting point following the line. This way of implementing has a lot of benefits. The first is that it is the easiest to implement, and it is relatively straight forward. When the robot hits the end of the tape, the sensor will notice that it is not sensing the tape anymore, and this will cause the robot to turn around and when it sees the tape again, will continue on its path. There is one problem with this way though. It is common.
We have all seen a line following robot, and it is neat, but not impressive. I wanted to do something that has not been done. I chose to implement my robot the second possible way, and the hardest way to implement. I wanted my robot to sense the end of the line, and then pause, and after a three second pause, I wanted it to drive in reverse and follow the line going backwards using a second set of sensors, so this is the robot that I will present. The only warning, and sad part of this project is that I can’t find my code. It is on a disk somewhere, and I have no idea where that is. I will provide code for a simple line-following robot though, and will explain the differences. In essence, I will tell you how to build both robots. On a positive note though, I do have a schematic of my robot, so you can see exactly how it is done.
Simple Line following robot:
We now have an idea of what we want to do, so we need to decide what circuits we need, and how to implement them together. We need to break this project into its components, and that is exactly how I did it. Once again, the circuits that we need are 1. An LED detector circuit. 2. A motor controller. 3. A microcontroller to do all logic. 4. 5V voltage regulator.
5v Voltage Regulator:
The first part of the circuit is to use a voltage regulator. This is an integrated circuit that will take the voltage from a 9v battery, and output a constant 5v. This is important because the microcontroller is powered by a constant 5v. Here is a schematic of how to connect the wires to a voltage regulator. When you are looking at the 7805 voltage regulator, the left most pin is connected to the +9 volts, and the middle pin is connected to ground. The right most pin will be a constant 5v. This 5 volts is connected to power the LED emitter, the microcontroller, and in my schematic, the H-bridge motor controller
LED detector:The LED detector circuit is relatively straight forward. It consists of an infrared LED, and an infrared detector. The infrared detector acts like a transistor. When the infrared light hits it, the detector will complete the circuit. The way this detects a black line is, first you shine both the emitter and the detector down on the floor. If the sensor is over the white floor, the infrared light will bounce off the floor, and will be picked up by the detector. The detector output will now be a high voltage. If the sensor/emitter combo is over a black line, then no light will be reflected, and the output will be a low voltage. This voltage is connected to an analog/digital converter, which is in the microcontroller, and this controller can be programmed to make the car either turn right or left. If you start the car on the right side of the tape, the car will drive forward, but will turn to the left. As the sensor crosses over the black tape, the output will be low, and the microcontroller will tell the car to turn to the right. This happens over and over again, and the car will follow the tape
There are some requirements on the parts. You don’t want to put too much voltage across an LED. I chose a 180 ohm resistor to put in series with the LED (pictured on the left in my circuit). I did not want to put 5v across my LED, so the 180 ohm resistor cuts that voltage down, and keeps the LED from being destroyed. There are some requirements for the microcontroller A/D converter also. The input voltage has to be less than 5v. The way I did this was to connect my 9v battery to the detector and played with the resistor values until I got the output voltages to what I liked. I built the circuit, and measured my outputs with a voltage meter, with the sensor over a black tape (Vnolight), and with my sensor over the white floor (Vlight). I found Vnolight to be .2v, and found Vlight to be 3.8v, after choosing a 21Kohm resistor for the detector.
Motor Controller – H-bridge:The next part of my circuit is a motor controller. I had to use an H-bridge for my motor controller, and I will explain why later. First, I am going to explain a simple motor controller. An NPN transistor can be used to control your motor. If the output pin is set high, it can be used to turn on the base of the NPN, and is basically used as a switch to power the motors. You can see on the robot circuit diagram (This is the schematic for the simple robot that just follows a robot in one direction) that the transistors I am talking about are Q1 and Q2. They are connected to GP2 and GP4 on the microcontroller through a 230 ohm resistor. The collector is connected to the positive pole of the motor, and the other pole is connected to + 5v through a 33 ohm resistor. The emitter of the transistor is connected to ground.(This schematic is for a simple line following robot using a transistor as a motor controller. It corresponds with the code that I have supplied).
This is the circuit for a simple motor controller. You see that this microcontroller has pins left open, so it has enough pins to use this kind of controller. My robot though, is using all of the pins because of the two sensing circuits, so I had to use an H-bridge. I also need to have the ability to make the motors go backwards, and forwards, as well as turn. I also needed the capability of making both motors stop. If I was just going to drive forward, then all I need is one analog input (for the sensors), and two digital outputs (one for each motor). If I want the car to stop, I put both outputs low, and if I want to turn left, I turn the right motor on, and the left one off. I do the opposite to turn right. Now for my robot, I was using 2 analog inputs and 3 digital outputs. One output disabled my H-bridge, and the other two went to each motor controller. If the right motor output was high, the motor would drive forwards, and if it was low, it would drive in reverse. With this set up, I could either make the car spin left (by putting right motor forward, and the left motor in reverse), spin right, go forward, and go backwards.
This is an integrated circuit that has two amplifying circuits in it. Here is a schematic of an H-bridge. The way this works is that if the input pin (Phase A/B) is high, then it will cause a certain polarity of the two output pins (Out1A and Out 2A), if the phase pin goes low, it will switch this polarity. This will cause a motor to either drive forward or backwards.
Pins:
1. Ground- connected to ground for the entire chip
2. Phase A- connected to microcontroller to control Right motor
3. Enable A – this has to be grounded to enable the circuit
4. Out 1A – this is connected to one pole of the motor
5. Vea – This is connected to the emitter of the transistors, and needs to be grounded
6. Out 2A – this is connected to the other pole of the motor7-12. These are the same as the first 6, and are connected the sameThe motors that we used were geared LEGO motors.Download H-bridge pdf
Microcontroller:The Microcontroller that I used was a Microchip PIC 12C672. This is an 8 pin chip that does all of the logic for the robot. It is hard to understand, but I will do my best. For my robot, I made 2 analog inputs, I used pins 7 and 6, which was AN0, and AN1. (This all has to be set in the program that is written.) I used pins 5 (GP2), 3 (GP4), and 2 (GP5) as digital outputs. I used GP2 and GP4 to control my motors, and GP5 as an enable to make the motors stop. The PIC chip has a built in analog to digital converter. The first part of the code is setting up the A/D converter, as well as setting the pins up for either analog input, or digital output. There are multiple registers in the chip, and different registers (working ram for the chip), are in two different banks. That is what the bsf STATUS,RPO command is doing. BSF means bit set, it is setting the RPO bit in the status register to one. This selects bank one. The command movlw 0×04, sets the literal value of 04 hex, or 00000100, into the working register, and the next command movwf ADCON1, moves the contents of the working register into the functional register. ADCON1, is the register that tells what pins are set up as input or outputs.
No comments:
Post a Comment