【正文】
measure whether there is something beside the robot and the distance of between the object and the robot, if there is. The diode shine the fix quantify of infrared ray. The nearer the object beside the sensor and the diode, the sensor can resave more quantify of infrared ray, and the resistance of the sensor is little. So the output of this unit is higher. So the output voltage is changing because of the distance between the robot and the object. We need A/D conversion, and then send to the MCU. Luckily, in the chip Atmega 128 there is an 8way A/D converter. The sensors’ unit is connected to the SCM directly. The diodes are connected to the SCM by Port E. the sensors are connected to the SCM by Port F, because the A/D converter Pins is Ports F. We use some units inside the SCM, the timer/counter, the A/D converter for example. I wish to analyze these units. Some basic functions, such as I./O, is ignored. There is an 8way 10bit A/D converter in the SCM. The ADC Pins is the second function of Port F. The Register ADMUX controls the mode of A/D conversion, such as the reference voltage of the A/D converter (bit 7 and bit 6), the format of the result (bit 5), and which way the converter choose. The Register ADSCR controls the stance, such as A/D enable (bit 7), A/D interrupt enable (bit 3), A/D start conversion controller (bit 6), and so on. The robot system uses three timers. Timer 0 and Timer 2 are used as PWM. Timer 1 is used to create timer interrupt. Timer 0 and Timer 2 are 8 bit timers. Timer 1 is a 16 bit timer. Now I like to analyze the 3 functions of the robot. The first function is line tracer. We use the three sensors under the robot. The black track is about 2cm width. At a certain position the middle sensor can feel the black trade. The left and right ones can’t. In this position, the robot is parallel to the trade. So we should let the robot go front. Look at Cell 1 in Graph 1. Perhaps the speeds of the two wheels are not the same. For example, the right wheel is run faster then the left one. Then the right sensor moves to the black trade. The robot should turn right. Look at Cell 2. If the robot goes to the round track, turns to right for example. The right sensor can fell the black trade too. Then the robot should turn to right. In a sentence, when the left/right sensor feel the trade, the robot should goes to the left/right. As we know, the direction of the wheel is controlled by H Bridge. The speed is controlled by PWM. The two wheels go front in full speed, the robot will go front. Some mates said that when the left wheel goes and the right one stops, the robot will turn right surround the right wheel. It’s sure. And this method creates the wonderful turns in the ophidian trade, because the radius of the round way is the same to the radius of robot. But there is a more sudden turn in the other side. I’m afraid the robot can’t turn such the sudden way. When turn to right, the left wheel goes front in full speed and the right one goes back in a low speed (PWM is 70). Timer 0 and Timer 2 act as the PWM controllers. The Timer 1 makes the interrupt. We use Timer1’s pare interruption. In the function main, we initialize the basic I/O ports, the timers and the interrupt of Timer 1. Then go to a dead loop. In this loop, we check the three variables: LeftSensor, CenterSensor and RightSonsor. They remember the status of the three sensors. In the interrupt function, we light the diodes and check the feedbacks of the sensors. And then remember them to the three variables: LeftSensor, CenterSensor and RightSonsor. This mission of line tracer is a little simple. But I found that it can’t always turn rightly on the sudden turn. I cut the time of interrupt, and it’s OK. The second function is keep away from the roadblock on the trade. I use the front sensor (on the robot) only. The program is update from Mission 1. At the interruption fun