Difference between revisions of "Maze"

From RoboWiki
Jump to: navigation, search
(Conclusion:)
(Improvements)
 
(36 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= Project: Maze =
 
= Project: Maze =
 
== Overview ==
 
== Overview ==
 
+
[[Image:ivan_daniel_robot1.jpg|thumb|Maze following robot|400px|right|The maze following robot]]
 
'''Authors: ''' Daniel Slenders, Ivan Gavran <BR>
 
'''Authors: ''' Daniel Slenders, Ivan Gavran <BR>
 
'''Countries: ''' Belgium, Croatia <BR>
 
'''Countries: ''' Belgium, Croatia <BR>
Line 23: Line 23:
  
 
== Improvements==
 
== Improvements==
First improvement of this maze-solving robot is finding path with no dead-ends. Robot would once find the way out remembering crossroads (complete algorithm is described in and every other time it would pass the maze ignoring dead-ends''[detailed view]'') .
+
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 [[Media: detailed-View.txt|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.
 
Further improvememnts are to be made in robot's speed and elegance of movements.
  
==Conclusion: ==
+
==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).
 
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. Therefore, we find our project relatively successful.
+
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 ==
 
== Project Files ==
 +
 +
<source lang="java">
 +
 +
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();
 +
}
 +
}
 +
}
 +
}
 +
 +
 +
</source>
 +
 +
 
{| style="color:green;background-color:#ffffcc;" cellpadding="2" cellspacing="0" border="1"
 
{| style="color:green;background-color:#ffffcc;" cellpadding="2" cellspacing="0" border="1"
 
| '''Description''' || '''Download'''
 
| '''Description''' || '''Download'''
 
|-
 
|-
 
| Project sourcecode || [[Media: SourceCode.txt]]
 
| Project sourcecode || [[Media: SourceCode.txt]]
 +
|-
 +
| Project detailed view|| [[Media: detailed-view.txt]]
 
|-
 
|-
 
|}
 
|}
 
Go back to the [[Summer_School_2010#Projects|List of the projects]]
 
Go back to the [[Summer_School_2010#Projects|List of the projects]]
 
[[Category:Projects]]
 
[[Category:Projects]]

Latest revision as of 13:38, 9 July 2010

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