0% found this document useful (0 votes)
44 views10 pages

AI-in-LEGO-EV3-Maze-Driving-Robot

Uploaded by

brendsriverasy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views10 pages

AI-in-LEGO-EV3-Maze-Driving-Robot

Uploaded by

brendsriverasy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

instructables

AI in LEGO EV3 Maze-Driving Robot

by Tony--K

This is a simple, autonomous robot with some arti cial intelligence. It is designed to explore a maze and when
placed back at the entrance, to drive thru to the exit and avoid the dead ends. It is much more complicated than
my previous project, which simply drove thru the maze. Here, the robot must remember the path it has travelled,
remove dead-ends, store the new path, and then follow the new path.

My previous robot is described here: https://www.instructables.com/id/LEGO-Robot-Drives-Thru-a-Maze

The robot is built using LEGO Mindstorms EV3. The EV3 Software runs on a computer and generates a program,
which is then downloaded to a microcontroller called an EV3 Brick. The programming method is icon-based and
high-level. It’s very easy and versatile.

Supplies:

PARTS

1. LEGO Mindstorms EV3 set


2. LEGO Mindstorms EV3 ultrasonic sensor. It’s not included in the EV3 set.
3. Corrugated cardboard for the maze. Two cartons should be su cient.
4. A small piece of thin cardboard to help stabilize some corners and walls.
5. Glue and tape to connect cardboard pieces together.
6. A red greeting-card envelope to identify the exit of the maze.

TOOLS

1. Utility knife to cut the cardboard.


2. Steel ruler to aid the cutting process.

SOFTWARE

The program is here: https://github.com/Tony- le/myEV3maze

AI in LEGO EV3 Maze-Driving Robot: Page 1


https://youtu.be/ooEIZ-peI9k

Step 1: How a Maze Is Solved

M A Z E- DRIVING M E T HO D

There are several methods of navigating a maze. If you are interested in studying them, they are described very
well in the following Wikipedia article: https://en.wikipedia.org/wiki/Maze_solving_algorithm

I chose the left-hand wall-following method. The idea is that the robot will keep a wall on its left side by making the
following decisions as it goes thru the maze:

1. If it’s possible to turn left, do so.


2. Otherwise, go straight if possible.
3. If it can’t go left or straight, turn right, if possible.
4. If none of the above are possible, this must be a dead end. Turn around.

One caution is that the method could fail if the maze has a loop in it. Depending on the placement of the loop, the
robot could keep going around and around the loop. A possible solution for this problem would be for the robot to
switch to the right-hand wall-follower rule if it realized that it was going in a loop. I didn’t include this re nement in
my project.

S O LVING T HE M A Z E T O FIND A DIREC T PAT H

While driving thru the maze the robot must memorize the path it is travelling and eliminate dead-ends. It
accomplishes this by storing each turn and intersection in an array, checking for speci c combinations of turns and
intersections as it goes, and replacing the combinations that include a dead-end. The nal list of turns and
intersections is the direct path thru the maze.

The possible turns are: Left, Right, Back (at a dead-end), and Straight (which is an intersection).

AI in LEGO EV3 Maze-Driving Robot: Page 2


Combinations are replaced as follows:

"Left, Back, Left" becomes "Straight."


"Left, Back, Right" becomes "Back."
"Left, Back, Straight" becomes "Right."
"Right, Back, Left" becomes "Back."
"Straight, Back, Left" becomes "Right."
"Straight, Back, Straight" becomes "Back."

HO W T HE RO BO T HANDLES M Y M A Z E

1. When the robot starts driving it sees a space to the right and stores Straight in the list in the array.
2. Then it turns left and adds Left to the list. The list now contains: Straight, Left.
3. With a dead end, it turns around and adds Back to the list. The list now contains: Straight, Left, Back.
4. Passing the lane it used from the entrance, it adds Straight to the list. The list now contains: Straight,
Left, Back, Straight. It recognizes a combination and changes Left, Back, Straight to Right. The list
now contains Straight, Right.
5. With a dead end, it turns around and adds Back to the list. The list now contains: Straight, Right,
Back.
6. After the left turn the list contains Straight, Right, Back, Left. It recognizes a combination and
changes Right, Back, Left to Back. The list now contains Straight, Back.
7. After the next left turn the list contains Straight, Back, Left. It changes that combination to Right.
The list now contains only Right.
8. It passes a space and adds Straight to the list. The list now contains Right, Straight.
9. After the right turn the list contains Right, Straight, Right which is the direct path.

Step 2: Considerations When Programming the Robot

CO NS IDERAT IO NS FO R ANY M ICRO CO NT RO LLER

When the robot decides to turn it should either make a wide turn, or go forward a short distance before turning
and after turning go forward a short distance again without checking the sensor. The reason for the rst short
distance is that the robot shouldn’t bump into the wall after the turn, and the reason for the second short distance
is that after the robot has turned, the sensor would see the long space it had just come from, and the robot would

AI in LEGO EV3 Maze-Driving Robot: Page 3


think it should turn again, which is not the proper thing to do.

When the robot senses an intersection on the right but it’s not a right turn, I have found that it’s good to have the
robot drive forward about 10 inches (25 cm) without checking its sensors.

CO NS IDERAT IO NS S PECIFIC T O LEGO M INDS T O RM S E V3

Although LEGO Mindstorms EV3 is very versatile, it allows no more than one of each type of sensor connected to
one Brick. Two or more Bricks could be daisy-chained, but I didn’t want to buy another Brick, and so I used the
following sensors (instead of three ultrasonic sensors): infrared sensor, color sensor, and ultrasonic sensor. This
worked out well.

But the color sensor has a very short range, of about 2 inches (5 cm), which leads to a few special considerations as
described below:

1. When the color sensor detects a wall in front and the robot decides to turn right or turn around, it
should back up rst, in order to give itself enough space to turn without bumping into the wall.
2. A complicated issue occurs with some “Straight” intersections. Because of the short range of the color
sensor, the robot cannot determine whether it senses a proper “Straight” intersection or the lead-up
to a right turn. I have tried to x this issue by setting the program to store a “Straight” in the list every
time the robot senses one, and then eliminate more than one “Straight” in a row in the list. This xes
the situation where a right turn follows a “Straight” in the maze but not the situation where there is a
right turn without a “Straight” before it. I also tried setting the program to eliminate a “Straight” if it is
just before a “Right” but this doesn’t work if a right turn follows a “Straight”. I haven’t been able to
nd a solution that ts all cases, altho I suppose it would be possible for the robot to look at the
distance travelled (by reading the motor rotation sensors) and decide whether it’s a “Straight” or a
right turn. I didn’t think this complication was worth doing for the purposes of demonstrating the AI
concept in this project.
3. An advantage of the color sensor is that it distinguishes between the brown of a wall and the red of
the barrier I used at the exit, and provides an easy way for the robot to decide when it has nished
the maze.

Step 3: The Main Program

LEGO Mindstorms EV3 has a very convenient icon-based programming method. Blocks are shown at the bottom of
the display screen on the computer and can be drag-and-dropped into the programming window to build a
program. The EV3 Brick may be connected to the computer by either a USB cable, Wi-Fi or Bluetooth, and the
program may then be downloaded from the computer to the Brick.

The program consists of a main program and several “My Blocks” which are subroutines. The uploaded le contains
the entire program, which is here: https://github.com/Tony- le/myEV3maze

The steps in the main program are as follows:

1. De ne and initialize the turn-counting variable and the array.


2. Wait 5 seconds and say “Go.”
AI in LEGO EV3 Maze-Driving Robot: Page 4
3. Start a loop.
4. Drive thru the maze. When the exit is reached, the loop is exited.
5. Display on the Brick’s screen, the intersections found in the maze so far.
6. Check if the path should be shortened.
7. Display the intersections in the shortened path.
8. Loop back to step 4.
9. After the loop, drive the direct path.

The screen shot shows this main program.

Step 4: The My Blocks (Subroutines)

The Navigate My Block, which controls how the robot drives thru the maze, is shown. The print is very small and
may not be legible. But it’s a good example of how versatile and powerful are the if-statements (called Switches in
the LEGO EV3 system).

1. Arrow #1 points to a Switch that checks if the infrared sensor sees an object more than a speci c
distance away. If so, the top series of blocks is executed. If not, then control is passed to the large,
bottom series of blocks, where arrow #2 is located.
2. Arrow #2 points to a Switch that checks what color the color sensor sees. There are 3 cases: no color at
the top, red in the middle, and brown at the bottom.
3. Two arrows #3 point to Switches that check if the ultrasonic sensor sees an object more than a
speci c distance away. If so, the top series of blocks is executed. If not, then control is passed to the
bottom series of blocks.

The My Blocks for shortening the path and for driving the direct path are more complicated and would be totally
illegible, and so they aren’t included in this document.

AI in LEGO EV3 Maze-Driving Robot: Page 5


Step 5: Starting to Build the Robot: the Base

As mentioned previously, LEGO Mindstorms EV3 connected together.


allows no more than one of each type of sensor
connected to one Brick. I used the following sensors The rst step is to build the base of the robot, using
(instead of three ultrasonic sensors): infrared sensor, the parts shown. The robot base is shown upside-
color sensor, and ultrasonic sensor. down. The small L-shaped part at the back of the
robot is a support for the back. It slides as the robot
The pairs of photos below show how to build the moves. This works okay. The EV3 kit doesn’t have a
robot. The rst photo of each pair shows the parts rolling-ball-type part.
needed, and the second photo shows the same parts

Step 6: Top of the Base, 1

ThIs step and the next 2 steps are for the top of the base of the robot, the color sensor, and the cables, which are all
10 inch (26 cm) cables.

AI in LEGO EV3 Maze-Driving Robot: Page 6


Step 7: Top of the Base, 2

Step 8: Top of the Base, 3

Step 9: Infrared and Ultrasonic Sensors

Next, are the infrared sensor (on the left side of the robot) and the ultrasonic sensor (on the right). Also, the 4 pins
for attaching the Brick on top.
AI in LEGO EV3 Maze-Driving Robot: Page 7
The infrared and ultrasonic sensors are located vertically instead of the normal horizontal. This provides better
identi cation of the corners or ends of the walls.

Step 10: Cables

The cables connect to the Brick as follows:

Port B: left large motor.


Port C: right large motor.
Port 2: ultrasonic sensor.
Port 3: color sensor.
Port 4: infrared sensor.

AI in LEGO EV3 Maze-Driving Robot: Page 8


Step 11: Final Step in Building the Robot: Decoration

The wings and ns are only for decoration.

Step 12: Build a Maze

Two corrugated cardboard cartons should be in any path with a dead end. The length should be no
su cient for the maze. I made the maze walls 5 inches less than 10 inches (25 cm). These distances are
(12.5 cm) high, but 4 inches (10 cm) should work just needed for the robot to turn around.
as well if you’re short of corrugated cardboard.
Some of the corners of the maze may need to be
First, I cut around the walls of the cartons, 10 inches reinforced, Also, some straight walls need to be kept
(25 cm) from the bottom. Then I cut around the walls from bending if they include a straightened carton
5 inches from the bottom. This provides several 5-inch corner. Small pieces of thin cardboard should be
walls. Also, I cut around the bottoms of the cartons, glued to the bottom at those places, as shown.
leaving about 1 inch (2.5 cm) attached to the walls for
stability. The exit has a red barrier consisting of half a red
greeting-card envelope and a base made from 2
The various pieces can be cut and glued or taped pieces of thin cardboard, as shown.
wherever needed to form the maze. There should be
an 11 or 12 inch (30 cm) space between the side walls

AI in LEGO EV3 Maze-Driving Robot: Page 9


Step 13: The Maze

One caution is that the maze should not be large. If speci c distance from the left wall. I didn’t include
the robot’s turns are at a slight angle from the proper this. The program is complicated enough as it is, and it
one, the discrepancies add up after a few turns and is su cient for demonstrating the AI concept in this
the robot could run into the walls. I had to ddle project.
several times with the Rotations settings of the turns
in order to get a successful drive thru even the small CO NCLUDING REM ARK
maze I made.
This was a fun project and a great learning
A way around that issue is to include a path- experience. I hope you also nd it interesting.
straightening routine that would keep the robot a

AI in LEGO EV3 Maze-Driving Robot: Page 10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy