Professional Documents
Culture Documents
The candidate conrms that the work submitted is their own and the appropriate credit has been given where reference has been made to the work of others. I understand that failure to attribute material which is obtained from another source may be considered as plagiarism.
Summary
To be able to do a simple function as to follow a line and avoid obstacles is an incredibly simple task for a human being but in order for a robot to do the same task is a little bit more challenging. This project uses the Lego Mindstorms RCX brick to show the best way to follow a line and avoid obstacles with what we believe to be the most efficient code.
Acknowledgements We would like to thank Jianqiang Ou (Jim) for all of his help and assistance with the creation of our code and for all previous help on past assignments.
Contents Summary Acknowledgments 1) Clarify Objectives a. Objectives b. Minimum requirements c. Deliverables d. Project Schedule i. Initial Schedule ii. Revised Schedule 2) Hardware: Limitations [Identify Constraints] a. Introduction b. RCX Brick c. Motors d. Sensors 3) [Establish User Requirements] a. Introduction b. Initial approach i. Initial thoughts ii. Final Concept
4) [Establish Functions] a. Situations i. Line Follow ii. Obstacle Detection iii. Avoiding the Obstacle iv. Stop on Green 5) Evaluation [Establish Design Specifications] 6) [Generate Alternatives] a. First Design problems b. Solution 7) Design Model a. Flowchart b. In-Line Function Table 8) Testing and Evaluation 9) [Refine and Optimize Design] 10) [Design Communication/Document Design] 11) Code
b. Revised Schedule Activity Initial Design Secondary Design Coding Report Write-up Final Additions to the robot Proof-read and re-evaluate Start March 4, 2014 March 17, 2014 March 18, 2014 March 25, 014 March 25, 2014 March 26, 2014 Finish March 6, 2014 March 18, 2014 March 25, 2014 March 26, 2014 March 25, 2014 March 27, 2014
B) Our solution for the many design errors was to build LineBot instead as it was a lot more reliable and can easily carry out the tasks that are required to be done. The simplistic design allows for easier modification additions to the design. We also replaced the antenna design and opted out to just a very basic touch sensor for easy obstacle detection. Our final modification was to add a secondary light sensor on the side to detect the can and allow it to circumnavigate the can with a great amount of accuracy.
This was just a matter of trial and error to see how long to let the robot go in reverse and turn so that it wasnt too far from the can that it cant read the red can and not too close that the robot would get stuck, so basically we were searching for the Goldilocks location from the can. Once the Values were perfected the program ran smoothly.
B) Scan Can The side light sensor constantly reads the value of the red can and as long as the light sensors readings are within the range of the accepted red value then the robot keeps turning by allowing only motor A to run at full speed while motor c is barely moving to allow for a very smooth and consistent turning speed. While this is going on, Sensor 1 is counting each time it passed the black line for 2 full circles around the can, so once the amount of times it has passed the line is equal to 5 then it stops the ScanCan task and it resumes linefollow to complete the track. Detect Green Finally to let the robot know it has completed its task it must stop on the green square. This happens by first setting a range of the different green variables and then it starts testing if the value detected is actually the color green or if it is just an light sensor fluctuation or an anomaly. This is done by starting to due 10 different scans consecutively and if all ten scans still read green this means it has actually arrived at true green. The robot then plays a sound and ends all tasks.
At first runt the robot continually was hitting the can on an angle which made it difficult to go around the bot. After continual trial and error it was turning and the perfect angle to circumnavigate the can.
Code
// linebot_modified.nqc // line tracking tracking algorithm // sensor and motors #define EYE SENSOR_2 #define LEFT OUT_A #define RIGHT OUT_C // constants #define GREEN1 29 #define GREEN2 30 #define LINE_THRESHOLD 24 #define TURN_SPEED 7 #define INITIAL_TIME 4 int direction, time, eye; int green = 0; int black = 0;
task main() { SetSensor(EYE, SENSOR_LIGHT); SetSensor(SENSOR_3, SENSOR_LIGHT); SetSensor(SENSOR_1, SENSOR_TOUCH); start line_follow; start detect_can; start detect_green; } task line_follow() { direction = 1; time = INITIAL_TIME; // start driving OnFwd(LEFT+RIGHT); while(true) { // read the sensor value eye = EYE; if (eye > LINE_THRESHOLD) { ClearTimer(0); if (direction == 1) { SetPower(RIGHT+LEFT, TURN_SPEED); Rev(LEFT); } else {
while(true) { // have we found the line? if (EYE < LINE_THRESHOLD) { time = INITIAL_TIME; break; } if (Timer(0) > time) { // try the other direction direction = -direction; time = 2*time; break; } } SetPower(RIGHT+LEFT, 7); Fwd(RIGHT+LEFT); } } } task detect_can() { until (SENSOR_1 == 1); stop line_follow; OnRev(OUT_A); Wait(100); start ScanCan; } task ScanCan() { while (true) { //OnFwd(OUT_A+OUT_C); if(SENSOR_3 >= 30 && SENSOR_3 <= 36){ SetPower(OUT_A, 7); OnFwd(OUT_A); Off(OUT_C); } if(SENSOR_3 >= 37) { OnFwd(OUT_C); Off(OUT_A); } if(SENSOR_2 <= 29) { black += 1; Wait(100); } if(black >= 5) { Off(OUT_A+OUT_C); Wait(100); OnRev(OUT_A+OUT_C); Wait(20);
OnFwd(OUT_C); Wait(130); //\Off(OUT_A+OUT_C); start line_follow; stop ScanCan; } } } task detect_green() { while(true){ //Detects green if(SENSOR_2 >= GREEN1 && SENSOR_2 <=GREEN2) { green += 1; Wait(1); }else{ green = 0; } //Once green has been truly detected robot plays a noise and stops all task and motors if(green >= 10) { PlaySound(2); Wait(100); Off(OUT_A+OUT_C); StopAllTasks(); } } }