| Autonomous SerachBot Microcontroller |
|
|
| Written by Jon-Diego Cornell University | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturday, 05 April 2008 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The SearchBot is a fully functional model car that can be controlled wirelessly through the PC or microcontroller autonomously search for red balls scattered on a flat surface.{mosgoogle}
Autonomous vehicles are just now being realized in labs around the world and will soon have major military and commercial potential. The Adaptive Communications and Signals Processing (ACSP) Group of Cornell University is studying the control of autonomous vehicles in sensor network systems and have asked us to contribute a robot vehicle to their research. The end result is the SearchBot, a car that can both be controlled by a user or autonomously search for red balls. In Controlled Mode, a user inputs an angle to rotate and distance to move on a PC terminal and the vehicle, which wirelessly receives the request, moves accordingly. In Autonomous Mode, the robot utilizes an effective searching algorithm to locate red balls on the floor. Upon finding one, the SearchBot pushes it back to a central base and continues searching for others. This project utilizes a commercial robot chassis, a PDA for wireless communication and an optical camera for vision. The SearchBot is an exciting application of many different electrical engineering disciplines and illustrates the practicability of using microcontrollers to making autonomous robots.
Rationale:
Logical Structure: In order to run the SearchBot, the user turns on the PC, PDA and microcontroller. An ActiveSync connection must be made and maintained between the PC and PDA. The user runs a issues commands through a Matlab script, which is propagated through the PDA to the MCU using RS232 serial. The Mega32 processes these commands and the car responds accordingly. Controlled Mode: This mode allows a user to run a Matlab script to control the movement of the robot. An angle and distance are sent to the MCU as inputs and the car moves consequently based on its calibration. Note that it is probably preferable to adjust the car in Calibration Mode before using the car for precise movement. The high level proposal for Controlled Mode is as follows:
Figure 2: Controlled Mode {mosgoogle} Autonomous Mode: This mode allows the car to move freely on its own and sense its surrounding using an optical camera. When the user initiates Autonomous Mode, the car immediately turns 300o while scanning for red. This makes it important for the area to be completely free of red to avoid false triggers. If the target color is not found, the car moves a foot and does another vision sweep. This continues until the SearchBot locates a red object. The vehicle then locks onto the object and move towards it, scanning the camera and making dynamic adjustments to its motion. Upon reach the target, the car captures it using a catchbin attached to the front of the chassis. The robot then searches for a base identified by green. We made the base large so it is easily discovered. The SearchBot pushes the ball to the base and then moves back to release it. The process is then repeated until the user enters a new instruction. Autonomous Mode is illustrated by the following graphic:
Figure 3: Autonomous Mode
Calibration Mode: in order to convert a distance or angle input into a time to turn wheels, scaled variables are needed. We found these variables changes with battery voltage, floor surface friction and weight on the car so it is handy to have a way to change these values. A separate mode on the car is set these calibration variables and have them saved to EEPROM. Software/Hardware Tradeoffs:
Standards:
Patents and Legal Considerations:
The SearchBot includes many subsystems that must be developed individually and then integrated together. The communications portion of the project involves transferring information wirelessly from the PC to the MCU. A novel way to implement this was to utilize a PDA to serve as the middleman and thus separate communication links were written for PC/PDA and PDA/MCU connections. Moreover, the car needs a robust state machine in order to move around, search for balls and obey commands from the user. Finally, there is the challenging aspect of reading from the optical sensor and completing the fast imaging processing necessary to help maneuver the car in autonomous mode.
User Control Specifications:
MODE is the main control line and the car will move according to the following table:
Accepted input values:
PC Connection:
PDA Serial Communication:
MCU Serial Communication:
Car Control:
If the user sets MODE = 0, the car enters Controlled Mode immediately. The car takes values DISTANCE and ANGLE from the UART and calculates how long it needs to turn the servo wheels in order to move the corresponding distance and angle. Two scaling factors scaledRotate and scaledMove are used to relate user input to time; this means the car must be calibrated before use. After calculating these times, the car is first rotated by calling rotateCar() and then moved by calling moveCar(). A short 5ms delay is implemented between the two movements. If the user sets MODE = 1, all other data is ignored and the car is put into Autonomous Mode. The car first initiates the camera and looks for a red ball on the ground. If the camera finds red, it determines the median x-pos of the red values of the line with the most accepted pixels. This value ranges from 1 to 88 corresponding to the horizontal resolution and the car uses this information to move towards its target, adjusting both angle and distance traveled dynamically based the median point's distance from the center. These motion values are calculated using the following equations:
If no marble is found, the car turns 30o and scans its camera again. It continues this sweep for 300o and then moves forward 30cm. The car continues this motion indefinitely until it finds a ball. Upon reaching the ball, the car encloses it with the catchbin and pushes it to a green-colored base. To do so, the car follows the same sort of algorithm as it did to search for balls. Variables autoState and autoMode are used to remember what the car is currently doing and what it is searching for respectively. Note that any new input from the PDA will cause the car to exit Autonomous Mode and follow new user instructions. Note that there are two other modes that the autonomous car can enter. MODE = 2 makes the car find the base before it searches for balls. This is easily implemented given our state machine and makes it convenient for the user to get the vehicle in a good position to begin searching. MODE = 3 calibrates the car, which is done by saving the input values to EEPROM and updating current scaledMove and scaledRotate values.
Servo Wheels Control:
Camera Control: I2C Communication: The OV6620 image sensor is very robust and features quite a variety of settings. One of the more interesting and challenging aspects was to figure out what the settings are and determining the optimal setting for our car. I2C, a protocol originating from Philips, is used to create a two-wire bidirectional communication interface between the MCU and camera. Since Philips retains the name of I2C, Atmel calls it "two wire interface" (TWI) and makes it available on PINC.0 and PINC.1 of the Mega32. The I2C protocol has a master/slave architecture and uses two pins for communication, both of which need to be connected to a 10kohm pull-up resistor to be active. The master puts out a clock signal on SCL line and all the slaves sync up to this clock. The speed of this clock is set by the microcontroller through the formula: In order to create a fast communication link, we designed the SCL frequency to be 100kbps. In doing so, we determined that TWSR (status register) and TWBR (bit rate register) should be set to 0 and 72 respectively. On the second line, the master sends a packet of data which transmits three bytes. After an initial start bit, the MCU sends the address of the slave (which is 0xc0 in this case) as the first byte. Subsequently, the second byte declares the target register on the camera and the third byte sends the data to be stored in that register. A stop bit ends the transmission. The slave must acknowledge that the transmission is received or the packet must be resent. Camera Settings: In order to receive a decodable output, we first must establish the proper settings on the camera. Firstly, we decided that having a low resolution would not hinder the car's operation significantly so we changed the default of 356x292 to a more reasonable 88x72. This tradeoff gave us more flexibility in collecting and processing data.. The frame rate was also decreased to about 4 fps to allow for better synchronization between the microcontroller and camera. Finally, we changed the color encoding from YUV to RGB to make our image processing faster. Receiving Data: The camera has several control lines that make data collection possible. The Vsync line sends a small pulse to signal the beginning of a new frame. The Href line becomes high at the same time and stays high while valid pixel data is available. Finally, pixel data can be collected whenever the Pclk line goes jumps from low to high. Two data buses, Y and UV, pass color data to the microcontroller. The Y line passes GRGRGR... values while the UV line sends GBGBGB... values, where R, G, and B represent the red, green and blue components of the pixel respectively. Note that between each line of pixels, there is a significant downtime when no valid data is sent, conveniently giving us a large interval to do image processing. Processing Data: Since we do not have enough memory to store an entire frame or time to process data on the fly, the SearchBot compromises by storing a line of pixel data at a time and processing it during the downtime between lines. For each pixel on a line, we compare the raw data to a predetermined color, saving the x-pos of the pixel if a match occurs. For example, when we are searching for a red marble, we take pixels when the R value more than doubles both G and B. By storing an array of the x-pos of all accepted pixels and a counter of the size of the array, we can quickly find the median point of the correctly-colored pixels and determine where the marble or base is. We used while loops to determine when the clocks changed values, an algorithm that we referenced from a project by Inaki Navarro Oiza (see appendix).
Car Construction:
The SearchBot was constructed in five weeks and currently meets all of the specifications that we originally intended. As planned, each part was independently constructed and the subsystems were integrated into one final product. We found this to be an efficient and productive process in creating such a complicated system. PC/PDA/MCU Communication: The communication links of the SearchBot were one of things we considered in our project. The PC/PDA link required a Matlab script and modified open source program. The Matlab function was easily implemented due to our previous knowledge of the language. The C# open source executable proved to be slightly more challenging, both because we had to understand the functions of the program and then modify them to meet our needs. However, the most difficult aspect was sending RS232 data from the PDA to the microcontroller because embedded C++ was completely foreign to us before the project. We utilized the MSDN help and eventually successfully sent transmissions to the microcontroller. One small problem that we had was that occasionally the PDA would trigger the receive interrupt on the Mega32 when we were not sending data and therefore caused some errors in the state machine. We fixed this by setting unique start and stop bytes to bookend our data packet so that all other receptions were ignored. Overall, the PC-to-PDA communication link is stable and efficient, making it a very excellent design decision. Car Construction: The assembly of the SearchBot chassis is pretty straightforward. We bought an Acroname PPRK kit and built our car with the included pieces. We originally planned to house the prototype board with the Mega32 in the underbelly of the robot but it did not fit. We moved it to the top of the car and placed the PDA beside it. The camera was attached to a solderboard which was screwed to the chassis. Overall, all the different hardware fit snugly on the car and we felt that it was not too crowded. We mounted strips of bendable aluminum to the front of the vehicle to serve as a catchbin. A recurrent problem is that the ball often bounced out of bin. We alleviated this hindrance by making the catchbin larger. Because of this change, the ball is successfully captured more than 80% of the time. Camera: Using the camera for vision is probably the most integral and challenging element of this project. A lot of research was needed, particularly in camera terminology and computer vision. We ran into some problems early on trying to communicate with the camera using I2C. CodeVision provided some libraries that handled this protocol but we continually failed in writing to the camera. After much debugging, we discovered the problem was that the InitI2C function in the library did not work. We solved this error by eliminating it and inserting delays between writes. A further complication was that the camera had over 20 control registers and it was difficult to decipher the necessary changes to ensure proper output. Fortunately, we found another project which had similar requirements and used them as reference in deciding our setting changes. The AVRCam project is referenced in the appendix. Further tweaking of the frame rate and resolution finally yielded an acceptable data stream that was decodable. After properly configuring camera settings, we had to receive and decode pixel data. This proved to be quite difficult because of timing issues. After much debugging, we found that the most effective way to read data is to slow down the frame rate to about 4 fps. Since we only require one image to move the car for about a second, this is an acceptable tradeoff. With the raw data, we then had to extract the color channels to determine color and maneuver the car. Since we got out RGB data, we decided to set a threshold on how much larger the target channel must be compared to the other two. After extensive testing, we found an optimal solution that both maximized range and minimized false triggering. Car Control: Our car control was rather straightforward to implement but required a lot of tweaking in order to optimize motion. Controlled mode was easily implemented and works very well. Along the way, we noticed that the rate at which the wheels turned changes depending on a variety of factors (battery life, floor friction) and thus implemented a calibration mode to make it easy for the user to get accurate movements. Autonomous mode required a lot more work. Our search algorithm works well most of the time and should be able to find the ball within a 4 meter radius. However, there were problems in the way the car captured and released the ball due to the inelegance of our catchbin. We found that we got much better results if we added some pauses between movements so that the ball does not bounce around too much between the aluminum rails. Changing from a light ping pong to a heavier squash ball also helped. After much testing and fine-tuning, the SearchBot can now search and retrieve red balls effectively. Each ball is captured and pushed to a green-colored base, where it is released.
In hindsight, the SearchBot was perhaps too large of a project to tackle in such a short span of time. Almost every facet of this project was foreign to us at the beginning and it required quite a bit of research to get the robot running properly. However, the SearchBot proves to be a success and we are very pleased with its design, look and performance. The SearchBot almost perfectly matches our initial specifications and actually contains quite a few extra features. We were a little disappointed with our catchbins, which lost the ball 20% of the time, and would have made something more effective if we had more time (maybe by creating a gate using piezoelectric wiring). We would also have tried to make a more efficient searching algorithm if we did not have such severe time constraints. On the other hand, we are extremely impressed with the stability and effectiveness of our PC/PDA/MCU communication link, which has never failed and is very fast. The camera, which required tons of debugging and testing, was another success, able to find ping-pong balls from over 4 feet away on 88x72 resolution. Finally, we were very happy with the overall construction of the project, which we found to be attractive and complete. A video demonstrating the car's capabilities can be found here. Further Developments: The SearchBot project can be expanded into many different directions so that it becomes a useful research instrument. A possible improvement is in the task that it performs. An ambitious person could definitely write up another novel assignment for the SearchBot to perform using CodeVision. Since the car and PDA has both transmitting and receiving capabilites built into its coding, one could also send information from the Mega32 to a PC terminal. One exciting possibility is to send camera data to the PC to be viewed by the user. Finally, one could add other sensors (acoustic, magnetic) and have the robot act as a multi-sensing autonomous vehicle, much like what the US military is currently researching. Intellectual Property and Legal Considerations: The SearchBot, like all good engineering projects, could not be successful without referencing previous work. Designs by Youngchul Song and Bruce Lei of the ACSP group for previous autonomous vehicles were important inspirations for this project. The AVRCam project and Oiza's work provided us with helpful hints in designing and testing our camera. MSDN, Bruce Land's examples and the RAPICSharp open-source code were crucial in getting our PC/PDA/MCU communication link to succeed. These projects were all academic projects that are cited in this report and readily available online. As our project is academic in nature and is completely designed and constructed by us, we have not violated any intellectual property laws. A further legal consideration is that we are using a WLAN link that must conform to federal laws. As expected for consumer products, the Dell Axim is compliant with FCC regulations; its manual says “47 CFR Part 15, Subpart C (Section 15.247). This version is limited to channel 1 to channel 11 by specified firmware controlled in the U.S.A.” Standards: As mentioned above, our projects used several different standards. For each, we have done the necessary research to confirm that we are in fact complying with its necessary specifications.
Throughout the SearchBot project, we consciously considered the IEEE Code of Ethics when making design and implementation decisions. The Code is as follows:
As with all engineering designs, we made sure that our creation will not hurt any individual who may use or come in contact with it. Since our robot was autonomous and thus is not always under direct human control, extra precautions must be implemented so that it can be immobilized quickly if it poses danger to anyone or anything. To facilitate this, the vehicle can be turned off if the Matlab script is run with input “0.” Moreover, a power switch is easy accessible on the top of the vehicle and will turn off every component in the vehicle if flipped.
Code:
Schematic:
Parts:
Work Distribution:
References:
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."Share & Save |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Last Updated ( Saturday, 08 August 2009 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Next > |
|---|
| Automatic Feeder |
| Fry Counter |
| 42% | | Indonesia |
| 18% | | United States |
| 5.4% | | China |
| 4.5% | | Australia |
| 3.8% | | India |
| Today: | 1 |
| Yesterday: | 1 |
| This Week: | 8 |
| Last Week: | 26 |
| This Month: | 34 |
| Last Month: | 90 |
| Total: | 805 |