Maze

From RoboWiki
Jump to: navigation, search

Project: Maze

Overview

The maze following robot

Authors: Daniel Slenders, Ivan Gavran
Countries: Belgium, Croatia
Date: 09.07.2010
Activity: R.U.R. - Summer School 2010

Abstract

This robot is capable of following a line and finding its way out of a maze. Our robot consists of two sensors. One to detect a line and one to detect crossroads.

Hardware Design: Our robot is a very simple Lego robot with two lightsensors and two servomotors (for the wheels).

Software Design: We wrote the program in Java. The program consists of three methods.

The first method is the callibration. This one determines which value corresponds to white and which one to black.

The second method is the linefollower. It uses one sensor to detect the line and steers the robot so that it keeps bumping into the line.

The third method is the mazefollower. By turning right at every crossroads it will find the exit. The method detects if there is just a line (then it uses the second method), if there is a crossroad (then it turns right) or if there is a dead end (then it turns 180 degrees.

Improvements

First improvement of this maze-solving robot is finding path with no dead-ends. Robot would once find the way out remembering crossroads and every other time it would pass the maze ignoring dead-ends (complete algorithm is described in detailedView.txt). Another possibiliy is to map complete maze and then use Dijkstra's algorihm to find the shortest way (values should be time needed to pass a way, rather than lengths) Further improvememnts are to be made in robot's speed and elegance of movements.

Conclusion

Our goal, set at the beginning of the project, was to create a robot that could find a way out of a labyrinth - not the optimal one, but good approximation (without dead-ends). We did not succeed completely. However, our robot finds a way out and we have described complete algorithm that removes paths with dead-ends. This all was made with minimal technical requirements. Another unsolved problem is how to increase the speed of our robot without disordering steering. Our robot still moves very slowly. Even with this robot - Theseus would still need Ariadne's help to survive.

Therefore, we find our project halfly successful.

Project Files

package atrox;
import lejos.nxt.*;

public class Maze {

	LightSensor left = new LightSensor(SensorPort.S1);
	LightSensor mid = new LightSensor(SensorPort.S2);
	LightSensor right = new LightSensor(SensorPort.S3);
	
	int numberOfSensors;
	
	int white;
	int black;
	
	public static void main(String[] args) {
		Maze maze = new Maze();
		try {
			maze.run();
		} catch (InterruptedException e) {} 
	}
	
	public Maze() {
		/* ... */
	}
	
	public void run() throws InterruptedException{
		numberOfSensors = 1;
		
		callibrate();
		followMaze();
	}
	
	public void callibrate(){
		int first = 0;
		int second = 0;
		
		while (!Button.ESCAPE.isPressed()){
			first = left.readValue();
			second = right.readValue();
			
			LCD.clearDisplay();
			System.out.println("White");
			System.out.println("Left:" + first);
			System.out.println("Right" + second);
			
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {}
		}
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {}
		
		white = second;
		
		while (!Button.ESCAPE.isPressed()){
			first = left.readValue();
			second = right.readValue();
			
			LCD.clearDisplay();
			System.out.println("Black");
			System.out.println("Left:" + first);
			System.out.println("Right" + second);
			
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {}
		}
		
		black = second;
	}
	
	public void followLine(){
		int rightValue = right.readValue();
		int leftValue = left.readValue();
		
		if(numberOfSensors == 1){
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {}
			
			rightValue = right.readValue();
			leftValue = left.readValue();
		
			LCD.clearDisplay();
			System.out.println("Following line");
			System.out.println("Left:" + leftValue);
			System.out.println("Right" + rightValue);
			
			int value = left.readValue();
			
			if(value >= white){
				Motor.C.backward();
				
				System.out.println("Steer left");
				
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {}
				
				Motor.C.forward();
			}
			else if(value <= (black + 5)){
				Motor.A.backward();
				
				System.out.println("Steer right");
				
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {}
				
				Motor.A.forward();
			}
		}
	}
	
	public void followMaze(){
		Motor.A.forward();
		Motor.C.forward();
		
		Motor.A.setSpeed(50);
		Motor.C.setSpeed(50);
		
		while(true){
			int rightValue = right.readValue();
			int leftValue = left.readValue();
			
			LCD.clearDisplay();

			if(rightValue <= (black + 5)){
				Motor.A.backward();
				
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {}
				
				while(left.readValue() >= white){
					leftValue = left.readValue();
					rightValue = right.readValue();
					
					LCD.clearDisplay();	
					System.out.println("Turning right");
					System.out.println("Left:" + leftValue);
					System.out.println("Right" + rightValue);
					
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {}
				}
				
				Motor.A.forward();
			}
			else if(leftValue <= (black + 5) && rightValue >= white){
				followLine();
			}
			else if(leftValue >= white && rightValue >= white){
				LCD.clearDisplay();
				System.out.println("Dead end turn");
				System.out.println("Left:" + leftValue);
				System.out.println("Right" + rightValue);
				
				Motor.C.backward();
				
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {}
				
				Motor.C.forward();
			}
		}
	}
}


Description Download
Project sourcecode Media: SourceCode.txt
Project detailed view Media: detailed-view.txt

Go back to the List of the projects