Czechbot

From RoboWiki
Revision as of 01:16, 14 August 2009 by Robot (talk | contribs) (Project Files)
Jump to: navigation, search

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 blind 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, it 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

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(6);
			if (isMiddleDark()) {
				Sound.twoBeeps();
				navi.rotate(90);
			}	
			else navi.rotate(90);
		}
		// leve T nebo leva zatacka
		else {
			navi.travel(6);
				if (isMiddleDark()) {
					Sound.twoBeeps();
					navi.rotate(90);
				}
				else navi.rotate(90);
		}
	}
	
	else if (isRightDark()) {
		if (isLeftDark()) {
			navi.travel(6);
			if (isMiddleDark()) {
				Sound.twoBeeps();
				navi.rotate(90);
			}
		}
		// pravy T nebo prava zatacka
		else {
				navi.rotate(-5);
				navi.travel(6);
				if (isMiddleDark()) {
					Sound.beep();
				}
				else navi.rotate(-80);
			}
	}
}

public void followLine() {
	int dig = 0;
	Motor.C.setSpeed(300);
	Motor.A.setSpeed(300);
	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(6);
			navi.rotate(180);
		}

	}
	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);
    }
 }	

}

Ye, our robot looks quite similar but he don´t have a head (like us)... :p

Czechbot.jpg

Some thoughts about intersection recognition (the problem was the upper line):

public boolean isMiddleDark() {
        navi.rotate(-15);
        for (int i=0;i<31;i+=5) {
             navi.rotate(i);
             if (middle.readValue() < 50) {
                  navi.rotate(-i+15);
                  return true;
             }
        }
        navi.rotate(-15);
	return false;
}


Go back to the List of the projects