Final Report – Maze runner

Team members:

------Shu YANG-----

------Zhen Zan -----


It is fun to control a ball by hand to escape from a maze. What’s more, you can control it by a Joystick. For something even better, the ball can get out of the maze by itself. The project is wireless, instant and controllable. The Joystick is one of the most direct way to control the maze. Roll the Joystick to control the direction of the maze to let the ball out. When you want to get rid of using hand, the camera will take instant photos and give feedback to the computer. The computer will control the maze board automatedly.


Baseline Goal Baseline1: Make the basic frame for the 10’*10’ maze Baseline2: Use the motor to control the maze move in four directions Baseline3: Use Joystick to control the maze to let the ball out Reach Goals Reach1: Use Solid works to build a competitive frame Reach2: Identify the path of the maze through the camera Reach3: Program the best way then re-plan the path again if necessary Reach4: Optimize the algorithm

Overall Timeline

Week1(11/01-11/08): Construct the frame of the maze, then use motors to let the maze incline in four directions;

Week2(11/08-11/15): Use Joystick to control the angle of inclination in four directions;

Week3(11/15-11/23): Use the camera to analyze the various maze and identify the path;

Week4(11/23-11/29): Program to let the maze self-modify the ball and find the shortest way;

Week5(12/2-12/6): Optimize the whole project;

1, Mechanical

We build a draft of the model ( Fig 1.1) and decide on how to control the motor. As is shown in the picture, there are two motors on the two side of the maze. Two frames link the motor and the axis to let the maze move. So we build a draft in the SolidWorks. We select MDF (1”/4) as the material because MDF is solid and the thickness of the material fit appropriately the gear on the stepper motor. We then use the laser cutting to cut the frame of the whole frame. The motor was fixed by a square hole ( Fig 1.2) and a hexagon ( Fig 1.3). At first, we only use two motors to control two directions respectively. Unfortunately, the box is too heavy to be controlled and then we do some improvements. First, we use two motors to help it have more power to incline the box. What is more, we dig out several holes to reduce the weight of the frame like a whole square (Fig 1.4) being cut out in the inner box. About the camera fixed with the raspberry pi, stands (Fig 1.5) are needed to combine to the box because of flexible adjustments. Elastics are needed (Fig 1.6) to bound the camera chip to the stands. Because the light effect which influences the camera to do some analysis, the dark slide is needed. Fig 1.7 and Fig 1.8 are the overview of the maze frame: .

2, Hardware

We chose stepper motors and motor driver A4988. And the schematic is in Fig 2.1 and the real circuit is in Fig 2.2. During the experiment, we observe that the motor cannot be easily driven because of one 12V to supply cannot help the drivers to meet the requirements so we use to power supply to solve the problem and the motors can run in normal. In the baseline, we need to use the joystick to control the motors to incline in two directions. We link the mbed LPC1768 to the raspberry pi via USB. And the breadboard layout is in picture. The motors are linked to the I/O on raspberry pi.

3, Software

For software part, we need to analyze the maze path first. Take a overview picture of the maze (Fig 3.1), using raspberry pi camera module. The resolution, iso, framerate can be set by picamera. After that, we could use OpenCV to detach the path from the whole maze. Basically, read the image from memory, the picture are in the form of NumPy array. Transfer the array to the HSV space, and take the mask of determined color, in this case, blue. While in reality, due to the hood of the whole maze, the picture a in a very dark situation, so the blue is very close to black. Also the ball color should take in to consideration to the path mask. Then we add all those color to make a mask of the maze. In the motor control, we need the position of the ball as a feedback, so also take a mask of the ball color only, then determine the coordinate. As we can seen from the picture below, the is not a single ball, the axis of motor is also the same color of the ball. So we judge the real position by how large the black area is. Now we know the maze matrix and the ball matrix. Usually the size of the maze is by the resolution of the camera. While we can not analyze the maze by a large size, we figure out to resize the maze using inter cubic method. To have a better matrix, take the real size of the maze as the new size of the matrix.


      [[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

      [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],

      [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

      [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

      [1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

      [1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],

      [0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],

      [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0],

     [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],

     [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0],

     [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],

     [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],

     [1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

     [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

     [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],dtype=uint8)

As shown above, 1 stands for obstacle, 0 stands for path. Then we could also get the coordinate of the ball. For the algorithm of the path, we use BFS(Breadth-First Search).

BFS is a node searching algorithm. From the start, it will search through all possible conjunction node, put it in a list, then take every node, find all their next nodes. This algorithm could search through all nodes until reach the destination. In the picture above, the sequence is V1 to V8.

In the maze, we choose a start node, like [0][0] in python. This is the top left corner. The end node is the bottom right corner, [15][15]. The algorithm would search the up direction of the node, which is the bound, a un-reachable node, then to the right node, which is the path, then add the node to this list. Search four directions of the node in list, till reach the end node. After find the end node, we could take inverse of all the methods to reach this point as the solution to this maze. If the list is empty somehow and still not get to the end point, then this maze has no solution. The advantage of this algorithm is it always find the shortest way from start to the end.

Since we have the solution of the maze, we need to control the motors corresponding to the methods. In raspberry pi, there is a package called GPIO.RPI, which allow to input or output control signal like direction and steps. From the hardware part, we use four step motors to incline the maze. Two outer motors controls left and right, inner motors controls up and down. For control part, we choose to use 100Hz signal as the step control, and we control the motor pairs with same step signal as well as opposite control signal.
The baseline control is to control by joystick. First we need to connect the joystick to MBED, because the raspberry pi do not have general analog input port. Then program the MBED to serial communicate with RPI, board rate 9600. Then use python to read the serial port /dev/ttyACM0 form RPI. Then control the motor corresponded.

The reach goal is to auto control the motor, to incline the maze making the ball roll from start to the end. For every step control, after several measurements, about 110 steps for 100Hz could generate the best incline angel. Every time the maze incline, it needs to incline in the opposite direction to keep the whole maze in a flat plane. The incline sequences is equal to the solution of the maze. For a better control with calibration, take new ball coordination every time the maze goes back to horizontal plane. Recalculate the path for this maze, until the ball hit the end. This could make the process more accurate.

Built With

Share this project: