Difference between revisions of "Czechbot"
 (→Project Files)  | 
				 (→Project Files)  | 
				||
| (29 intermediate revisions by the same user not shown) | |||
| Line 11: | Line 11: | ||
== Abstract ==  | == Abstract ==  | ||
| + | |||
| + | '''General Idea:'''  | ||
| − | Our robot...  | + | Make a robot which can find a goal in a non-cycled maze (only with dead end tracks) of black lines by going left on every intersection.  | 
| + | |||
| + | ----  | ||
| + | |||
| + | '''Thoughts:'''  | ||
| + | |||
| + | At first we tried robot only with two sensors and he did quite well. But finally we had to rewrite a source code for three sensors robot in a very short time because of troubles with implementation of two sensors ancestor. And that was the whole problem.   | ||
| + | |||
| + | ----  | ||
| + | |||
| + | '''Results:'''  | ||
| + | |||
| + | Our robot can follow the black line, he can recognize blind tracks and turn himself back to line. The only problem is with marking the intersections. Because robot hasn´t a ideal movement, there are still some inaccuracies. Theoreticaly we have some thoughts how to clean up, but we didn´t have enough of time to implement it right.  | ||
| + | So our robot can`t recognize intersections properly and that is the reason why he makes so many mistakes.  | ||
| + | |||
| + | == Project Files ==  | ||
| + | |||
| + | <source lang="java">  | ||
| + | import lejos.navigation.TachoNavigator;  | ||
| + | |||
| + | |||
| + | import lejos.nxt.*;  | ||
| + | |||
| + | @SuppressWarnings("deprecation")  | ||
| + | public class TEst {  | ||
| + | 	LightSensor left,right,middle;  | ||
| + | 	TachoNavigator navi;  | ||
| + | |||
| + | public static void main(String[] args) throws Exception {  | ||
| + | 	 TEst l=new TEst();  | ||
| + | 	 l.run();  | ||
| + |   }  | ||
| + | |||
| + | public TEst() {   | ||
| + | 	//init  | ||
| + |     right = new LightSensor(SensorPort.S3);  | ||
| + |     middle = new LightSensor(SensorPort.S2);  | ||
| + |     left = new LightSensor(SensorPort.S4);  | ||
| + |     navi = new TachoNavigator(5.6f, 11.5f, Motor.C, Motor.A);   | ||
| + | }  | ||
| + | public boolean isRightDark() {  | ||
| + | 	return right.readValue() < 50;  | ||
| + | }  | ||
| + | |||
| + | public boolean isLeftDark() {  | ||
| + | 	return left.readValue() < 50;  | ||
| + | }  | ||
| + | |||
| + | public boolean isMiddleDark() {	  | ||
| + | 	return middle.readValue() < 50;  | ||
| + | }  | ||
| + | |||
| + | public void findIntersection() {  | ||
| + | 	navi.setSpeed(120);  | ||
| + | 	navi.travel(1);  | ||
| + | 	if (isLeftDark()) {  | ||
| + | 		if (isRightDark()) {  | ||
| + | 			navi.travel(4);  | ||
| + | 			if (isMiddleDark()) {  | ||
| + | 				Sound.twoBeeps();  | ||
| + | 				navi.travel(2);  | ||
| + | 				navi.rotate(92);  | ||
| + | 			}	  | ||
| + | 			else {  | ||
| + | 				navi.travel(2);  | ||
| + | 				navi.rotate(92);  | ||
| + | 			}	  | ||
| + | 		}  | ||
| + | 		// leve T nebo leva zatacka  | ||
| + | 		else {  | ||
| + | 			navi.travel(4);  | ||
| + | 				if (isMiddleDark()) {  | ||
| + | 					Sound.twoBeeps();  | ||
| + | 					navi.travel(2);  | ||
| + | 					navi.rotate(92);  | ||
| + | 				}  | ||
| + | 				else {   | ||
| + | 					navi.travel(2);  | ||
| + | 					navi.rotate(92);  | ||
| + | 				}  | ||
| + | 		}  | ||
| + | 	}  | ||
| + | |||
| + | 	else if (isRightDark()) {  | ||
| + | 		if (isLeftDark()) {  | ||
| + | 			navi.travel(4);  | ||
| + | 			if (isMiddleDark()) {  | ||
| + | 				Sound.twoBeeps();  | ||
| + | 				navi.travel(2);  | ||
| + | 				navi.rotate(92);  | ||
| + | 			}  | ||
| + | 		}  | ||
| + | 		// pravy T nebo prava zatacka  | ||
| + | 		else {  | ||
| + | 				navi.rotate(-5);  | ||
| + | 				navi.travel(4);  | ||
| + | 				if (isMiddleDark()) {  | ||
| + | 					navi.travel(2);  | ||
| + | 					Sound.beep();  | ||
| + | 				}  | ||
| + | 				else {  | ||
| + | 					navi.travel(2);  | ||
| + | 					navi.rotate(-80);  | ||
| + | 				}  | ||
| + | 			}  | ||
| + | 	}  | ||
| + | }  | ||
| − | ==   | + | public void followLine() {  | 
| + | 	int dig = 0;  | ||
| + | 	Motor.C.setSpeed(270);  | ||
| + | 	Motor.A.setSpeed(270);  | ||
| + | 	if (middle.readValue() > 45) {  | ||
| + | 		Motor.A.stop();  | ||
| + | 		Motor.C.forward();  | ||
| + | |||
| + | 		dig = Motor.C.getTachoCount();  | ||
| + | 		if (Math.abs(dig) > 270) {  | ||
| + | 			Motor.C.rotate(-dig);  | ||
| + | 			navi.setSpeed(360);  | ||
| + | 			navi.travel(8);  | ||
| + | 			navi.rotate(185);  | ||
| + | 		}  | ||
| + | |||
| + | 	}  | ||
| + | 	else if (middle.readValue() <= 45) {  | ||
| + | 		Motor.C.stop();  | ||
| + | 		Motor.A.forward();	  | ||
| + | 		Motor.C.resetTachoCount();  | ||
| + | 	}  | ||
| + | }  | ||
| + | |||
| + | public void run() throws InterruptedException {	    | ||
| + |     while (!Button.ESCAPE.isPressed()) { 	  | ||
| + |     	followLine();  | ||
| + |     	if (isLeftDark()) {  | ||
| + |     		navi.stop();  | ||
| + |     		Motor.A.rotate(-5);  | ||
| + |     		Motor.C.rotate(5);  | ||
| + |     		findIntersection();  | ||
| + |     	}  | ||
| + |     	else if (isRightDark()) {  | ||
| + |     		navi.stop();  | ||
| + |     		Motor.A.rotate(5);  | ||
| + |     		Motor.C.rotate(-5);  | ||
| + |     		findIntersection();  | ||
| + |     	}  | ||
| + |     	LCD.drawInt(SensorPort.S3.readValue(), 4, 0, 0);  | ||
| + |     	LCD.drawInt(SensorPort.S2.readValue(), 4, 0, 1);  | ||
| + |     	LCD.drawInt(SensorPort.S4.readValue(), 4, 0, 2);  | ||
| + |     }  | ||
| + |  }	  | ||
| + | |||
| + | }  | ||
| + | |||
| + | </source>  | ||
| + | |||
| + | (illustration picture)  | ||
| + | [[Image:Czechbot.jpg]]  | ||
| − | |||
| − | |||
| − | |||
Go back to the [http://virtuallab.kar.elf.stuba.sk/robowiki/index.php?title=Summer_School_2009 List of the projects]  | Go back to the [http://virtuallab.kar.elf.stuba.sk/robowiki/index.php?title=Summer_School_2009 List of the projects]  | ||
Latest revision as of 09:39, 14 August 2009
Overview
Author(s): Pavel Kuttelwascher, Vladimír Janouš      
Country: Czech Republic                               
Date: 12.08.2009-14.8.2009                              
Activity: Centrobot Robotic Summer School 2009
Location: Vienna, Austria         	      
Hardware: LEGO Mindstorms NXT     
Abstract
General Idea:
Make a robot which can find a goal in a non-cycled maze (only with dead end tracks) of black lines by going left on every intersection.
Thoughts:
At first we tried robot only with two sensors and he did quite well. But finally we had to rewrite a source code for three sensors robot in a very short time because of troubles with implementation of two sensors ancestor. And that was the whole problem.
Results:
Our robot can follow the black line, he can recognize blind tracks and turn himself back to line. The only problem is with marking the intersections. Because robot hasn´t a ideal movement, there are still some inaccuracies. Theoreticaly we have some thoughts how to clean up, but we didn´t have enough of time to implement it right. So our robot can`t recognize intersections properly and that is the reason why he makes so many mistakes.
Project Files
import lejos.navigation.TachoNavigator;
import lejos.nxt.*;
@SuppressWarnings("deprecation")
public class TEst {
	LightSensor left,right,middle;
	TachoNavigator navi;
	
public static void main(String[] args) throws Exception {
	 TEst l=new TEst();
	 l.run();
  }
	
public TEst() { 
	//init
    right = new LightSensor(SensorPort.S3);
    middle = new LightSensor(SensorPort.S2);
    left = new LightSensor(SensorPort.S4);
    navi = new TachoNavigator(5.6f, 11.5f, Motor.C, Motor.A); 
}
  
public boolean isRightDark() {
	return right.readValue() < 50;
}
public boolean isLeftDark() {
	return left.readValue() < 50;
}
public boolean isMiddleDark() {	
	return middle.readValue() < 50;
}
public void findIntersection() {
	navi.setSpeed(120);
	navi.travel(1);
	if (isLeftDark()) {
		if (isRightDark()) {
			navi.travel(4);
			if (isMiddleDark()) {
				Sound.twoBeeps();
				navi.travel(2);
				navi.rotate(92);
			}	
			else {
				navi.travel(2);
				navi.rotate(92);
			}	
		}
		// leve T nebo leva zatacka
		else {
			navi.travel(4);
				if (isMiddleDark()) {
					Sound.twoBeeps();
					navi.travel(2);
					navi.rotate(92);
				}
				else { 
					navi.travel(2);
					navi.rotate(92);
				}
		}
	}
	
	else if (isRightDark()) {
		if (isLeftDark()) {
			navi.travel(4);
			if (isMiddleDark()) {
				Sound.twoBeeps();
				navi.travel(2);
				navi.rotate(92);
			}
		}
		// pravy T nebo prava zatacka
		else {
				navi.rotate(-5);
				navi.travel(4);
				if (isMiddleDark()) {
					navi.travel(2);
					Sound.beep();
				}
				else {
					navi.travel(2);
					navi.rotate(-80);
				}
			}
	}
}
public void followLine() {
	int dig = 0;
	Motor.C.setSpeed(270);
	Motor.A.setSpeed(270);
	if (middle.readValue() > 45) {
		Motor.A.stop();
		Motor.C.forward();
		dig = Motor.C.getTachoCount();
		if (Math.abs(dig) > 270) {
			Motor.C.rotate(-dig);
			navi.setSpeed(360);
			navi.travel(8);
			navi.rotate(185);
		}
	}
	else if (middle.readValue() <= 45) {
		Motor.C.stop();
		Motor.A.forward();	
		Motor.C.resetTachoCount();
	}
}
public void run() throws InterruptedException {	  
    while (!Button.ESCAPE.isPressed()) { 	
    	followLine();
    	if (isLeftDark()) {
    		navi.stop();
    		Motor.A.rotate(-5);
    		Motor.C.rotate(5);
    		findIntersection();
    	}
    	else if (isRightDark()) {
    		navi.stop();
    		Motor.A.rotate(5);
    		Motor.C.rotate(-5);
    		findIntersection();
    	}
    	LCD.drawInt(SensorPort.S3.readValue(), 4, 0, 0);
    	LCD.drawInt(SensorPort.S2.readValue(), 4, 0, 1);
    	LCD.drawInt(SensorPort.S4.readValue(), 4, 0, 2);
    }
 }	
}
(illustration picture)
Go back to the List of the projects
