You are on page 1of 13

By: Cyril Iskander, Karolos Mishreky, Markos Gerges BE 1200 Sec004 March, 2014

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

Step 1: Main Goals and requirements


A) Objectives The main Goal of this Project is to Run through the track and avoid Obstacles using the RCX brick as its Base. The code that we will be using is the NQC coding, which is similar to the well-known programing language of C++. Our overall Objective is to easily navigate the track and make smooth turns and easily detect the Obstacle and navigate around it. B) Minimum requirements Follow the Line Detect the Obstacle Navigate around the Obstacle Continue line follow Stop on green C) Deliverables a. Lego Mindstorms robot with properly functioning code b. Final Design Project report c. Team Website : hosted at http://KMCengineering.weebly.com D) Project Schedule The project schedule was constructed to originally be only during class time, but as the deadline approached we changed the schedule to be after class hours as well. a. Initial Schedule Activity Initial robot Design Begin writing Code Testing and write up report Proof read report Final Adjustments Start March 4,2014 March 17, 2014 March 20, 2014 March 26, 2014 March 26, 2014 Finish March 6,2014 March 20, 2014 March 25, 2014 March 26, 2014 March 27, 2014

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

Step 2: Identify Constraints


A) Introduction The RCX Bot by Lego Mindstorms has many limitations and constraints that only allow for very specific commands and capabilities. In this project my group and I were able to see first hand many of the limitations that the RCX bot presents. B) The RCX Brick By itself has an issue with power consumption and the fact that if it has low battery power it will affect the robots ability to read the light or the red colour of the obstacle. C) The motors are very hard to calibrate to the desired speed and strength at which is just a matter of guess and check. For example, if the design built is a little bit heavy the motors will stop completely. D) The sensors on the robot have a very sensitive reaction to its ability to scan for the line depending on the lighting it is surrounded by and it can cause the range of certain colors to different.

Step 3: Establishing User Requirements


A) The main objective of this project is that once the robot is activated it will run completely by itself, so the only user requirement is to point the robot in the right direction and press the run button on the RCX Brick. B) Our group had an Initial plan and a secondary plan that required much less on the User a. Initial thoughts At first, we thought that we could first have the user place the robot on the Green spot so that it could first establish the variable for green. Then the User would place the robot on the white Board to collect the Data of that color variable, and finally place the robot on black so it would collect the variable and then start running the track. b. Final Concept Our final concept is a lot more efficient because the user just has to put the robot on the line and press the run button on the RCX brick.

Step 4: Establish Functions


A) Situations a. The first function that the robot must accomplish is to follow the line on the track. The value of the black has already been stored in the code on the robot so it can use the light sensor and read the line variables and as long as the line variables are within range the robot can successfully follow the line. b. The second function that the RCX robot must be able to do is the obstacle detection. For our robot we used a basic touch sensor that with read when the robot comes in contact with the red can. This event triggers the obstacle avoiding task. c. The third function is to go circumnavigate around the red paint can. The RCX robot has been outfitted with a secondary light sensor on the side to detect the value of the color red and constantly read for the value and turn accordingly until it has done a full circle once around the can. d. The final task that must be accomplished is for the RCX Brick to stop on green square on the track. When the light sensor gets to the green square and reads the predetermined variable it will end all tasks and stop.

Step 5: Establish Design Specifications


The design must include a light sensor in order to detect the line for the line follow task to be able to run. It must have a method of detecting the obstacle to signal when the tasks should switch from line follow to the circumnavigating of the obstacle. It must also be able to constantly read the obstruction in its path so it must have a sensor to rotate on the side or already be on the side for constant reading. The RCX Brick has many different wheel attachments, so there is a selection of different methods of the robot to move along the track.

Step 6: Generate Alternatives


A) Our initial design for the robot was very complex and it was moving too fast with the larger wheels even if we were to lower the power output from the motor. This made it hard for our version of line follow program to work. It also had a very difficult time with constantly getting the swivel stuck and it would stop turning which made it impossible for it to run the task, because it was a crucial part of the tasks for the RCX Brick to be able to move with a higher level of mobility to be able to circumnavigate the paint can. Also the initial design was to use the BugBot antenna to be able to detect the paint can and circumnavigate the obstacle, but this proved to be a difficult task for coding so it was the clear choice to change the entire design due to its many issues. Our initial design:

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.

Step 7: Design Model


A) Flowchart and in-line Function Table at : http://kmcengineering.weebly.com/midterm.html

Step 8: Testing and Evaluation


Line Following Values for color has already been stored in the robot in between different ranges and values for the black line only so that the RCX can only follow the line and when it cannot read the line value it sweeps the track till it detects the value and continues. Obstacle Circumnavigation A) Obstacle detection The touch sensor must change its values from 0 to 1 in order for the line follow task to stop and that is followed by the robot reversing and then starts the Scan Can task. Evaluation No problems at all, the first trials were a complete success and no further changes were done to the line following code.

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.

100% success on first trial. No issues to report.

Step 9: Refine and Optimize Design


The only design change we made to improve the design is adding the circular wheel on the end of the touch sensor to make it smaller than the original bumper because is smaller and looks more aesthetically pleasing. Other than that no further Changes were made to the final design of which the code has been specified.

Step 10: Design Communication/Document Design

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 {

SetPower(RIGHT+LEFT, TURN_SPEED); Rev(RIGHT); }

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(); } } }

You might also like