The Maze Runner (Final)
The Maze Runner (Final)
Prepared by:
Reem Saif Alneyadi - 100041447
Hind Saeed Amin - 100041484
Linda Taha Ismail - 100041628
Introduction
Today, advances in technology are encouraging all communities to strive to excel
in the robotics division. Therefore, Khalifa University for Science Technology and
Research decided to familiarize its freshmen students to robotics by making a
competition for the students of the Introduction to Computing course. The
mission of the robot was to follow a white line through a maze using only the
algorithm provided by students, and without the interference of anyone. The
robot is supposed to pick up a red ball placed in the maze and then find its way
out of the maze. The programming language that we were asked to use to create
an efficient code is MATLAB. All teams were provided with a Lego NXT kit to build
the robot. The team with the fastest robot would be awarded more credits.
Problem Analysis/Description
Task 1: The robot must follow a white line of width 2 cm.
Task 2: The robot should work on any maze. It should be intelligent.
Task 3: The robot must detect dead ends and find a better route.
Task 4: The robot must detect the red ball and catch it.
Task 5: The robot must start at the YELLOW area and stop when it is fully in the
GREEN area.
Task 6: Our robot must win against other competing robots to get full credit.
Robot Dimensions and Rules
As per the instructions of our lab instructors, the dimensions of the robot should
not exceed a maximum of 25 cm by 25 cm before starting its mission. However, it
can expand after the mission starts. The robot must work on its own without any
intervention. Only one NXT brick may be used, and no extra parts may be used so
that no team has an advantage over the other. The robot must be out of the maze
within 15 minutes. Also, any failures caused by the carelessness of the team
members, such as low battery of the robot, are not enough justification for a
rematch.
Work Strategy
Our team was one of the few teams with only 3 members. This placed a larger
work load on us compared to the rest of the teams in the competition. As a result
we arranged many meetings outside of class to work on the project despite our
packed schedules. We also researched a lot to learn more about what has already
been done in similar projects. Many design and code alternatives were considered
until we found the most suitable one.
Our final design is an efficient intelligent robot. We provided it with three sensors.
A color sensor for the detection of the white line, the yellow starting area and the
green finishing area. A light sensor which we calibrated to detect the red color of
the ball. An ultrasonic sensor to detect obstacles in front of the robot, this was
particularly helpful to escape dead ends. We also provided it with three motors.
Two motors were to move the wheels and one motor was used to open and close
the arm.
Sensors
1. Color sensor
We placed the color sensor facing downwards at the front of the robot. The job of
this sensor was to detect the colors under the robot which would ultimately guide
the robot on what actions to take. This is the code we wrote for the color sensor:
if strcmp(GetNXT2Color( SENSOR_3 ),'YELLOW')%if the color sensor detects
the color yellow the robot will start moving in a specific speed and a
specefic number of cycles
B.Power=50;
C.Power=50;
B.TachoLimit=360;
C.TachoLimit=360;
B.SendToNXT()
C.SendToNXT()
end
end
if (strcmp( GetNXT2Color( SENSOR_3 ), 'BLACK'))
B.Power=20;
C.Power=10;
B.TachoLimit=0;
C.TachoLimit=0;
B.SendToNXT()
C.SendToNXT()
end
2. Light Sensor
We placed the light sensor horizontally in front of the robot. We calibrated it to
detect the red color of the ball which leads the robot to take the appropriate
action based on the code provided to it. This is the code we wrote for the light
sensor:
if (GetLight( SENSOR_1 )>=400 && GetLight( SENSOR_1 )<=600)%if the lighht
sensor detects the color red which ranges from 400-600 motor A will cause the
hand of the motor to close
A.Power=20;
A.TachoLimit=120;
A.SendToNXT()
A.Stop('off')
CloseSensor(SENSOR_1)%for the light sensor to detect the red ball only
once we need to close it inside this if statement
end
3. Ultrasonic sensor
We placed the ultrasonic sensor above the slanted NXT brick. This sensor detects
any obstacles in front of it. We wrote the code in a way that when the robot is
faced by a wall it would turn right and left to check the distances in those
directions. It then chooses the path with the largest distance. This is the code we
wrote for the ultrasonic sensor:
while GetUltrasonic(SENSOR_4)<20 %while the ditance between the wall and the
is less than 20 the robot when move to the left first to check if the distance
if greater than 20, if not it will move to the right to check
B.Power=50;
B.TachoLimit=200;
C.Power=-50;
C.TachoLimit=200;
B.SendToNXT()
C.SendToNXT()
B.WaitFor()
C.WaitFor()
if GetUltrasonic(SENSOR_4)>=25 %if the distance is greater than 25 it will
exit the while loop
break;
end
C.Power=50;
B.Power=-50;
C.TachoLimit=590;
b.TachoLimit=590;
C.SendToNXT()
B.SendToNXT()
C.WaitFor()
B.WaitFor()
if GetUltrasonic(SENSOR_4)>=25
break
end
C.Power=50; % if the distance is still less than 20 it will take a
uturn from its first original place
C.TachoLimit=200;
B.Power=-50;
B.TachoLimit=200;
B.SendToNXT()
C.SendToNXT()
C.WaitFor()
B.WaitFor()
end
COM_CloseNXT all
h=COM_OpenNXT();
COM_SetDefaultNXT(h)
k=0;%k is a variable to enter the while loop, k becomes 1 when the color
sensor detects the color green
B=NXTMotor('B');
C=NXTMotor('C');
A=NXTMotor('A');
OpenLight(SENSOR_1, 'ACTIVE')
OpenUltrasonic(SENSOR_4)
OpenNXT2Color( SENSOR_3, 'FULL' )
while k==0
pause(0.01)
if strcmp(GetNXT2Color( SENSOR_3 ),'YELLOW')%if the color sensor detects
the color yellow the robot will start moving in a specific speed and a
specefic number of cycles
B.Power=50;
C.Power=50;
B.TachoLimit=360;
C.TachoLimit=360;
B.SendToNXT()
C.SendToNXT()
end
if GetUltrasonic(SENSOR_4) >=20 %if the distance between the robot and the
wall is greater than other equal to 20 is wil move in a zigzag method
depending on the color it detects whether its black or white
if (strcmp( GetNXT2Color( SENSOR_3 ), 'WHITE'))
B.Power=10;
C.Power=20;
B.TachoLimit=0;
C.TachoLimit=0;
B.SendToNXT()
C.SendToNXT()
end
if (strcmp( GetNXT2Color( SENSOR_3 ), 'BLACK'))
B.Power=20;
C.Power=10;
B.TachoLimit=0;
C.TachoLimit=0;
B.SendToNXT()
C.SendToNXT()
end
end
while GetUltrasonic(SENSOR_4)<20 %while the ditance between the wall and the
is less than 20 the robot when move to the left first to check if the distance
if greater than 20, if not it will move to the right to check
B.Power=50;
B.TachoLimit=200;
C.Power=-50;
C.TachoLimit=200;
B.SendToNXT()
C.SendToNXT()
B.WaitFor()
C.WaitFor()
if GetUltrasonic(SENSOR_4)>=25 %if the distance is greater than 25 it will
exit the while loop
break;
end
C.Power=50;
B.Power=-50;
C.TachoLimit=590;
b.TachoLimit=590;
C.SendToNXT()
B.SendToNXT()
C.WaitFor()
B.WaitFor()
if GetUltrasonic(SENSOR_4)>=25
break
end
C.Power=50; % if the distance is still less than 20 it will take a
uturn from its first original place
C.TachoLimit=200;
B.Power=-50;
B.TachoLimit=200;
B.SendToNXT()
C.SendToNXT()
C.WaitFor()
B.WaitFor()
end
end