- Code: Select all
import josx.platform.rcx.*;
import josx.robotics.*;
//////////////////////////////////////
/**
* Line follower
*
* @author Adam Christianson
* @url http://www.terraform.com
* @version 1.0
*/
public class LineFollow {
////////////////////////////////////////////
// public methods
////////////////////////////////////////////
////////////////////////////////////////////
/**
* main method
* @throws InterruptedException
*/
public static void main(String[] args)
throws InterruptedException {
Sensor.S2.setTypeAndMode (3, 0x80);
Sensor.S2.activate();
Sensor.S2.addSensorListener (new SensorListener() {
public void stateChanged (Sensor src, int oldValue, int newValue) {
// Will be called whenever sensor value changes
// LCD.showNumber(newValue);
TimingNavigator robot = new TimingNavigator(Motor.C, Motor.A, 1.6f, 0.54f);
if (newValue > 35 ) {
robot.travel(-15);
pause(300);
robot.rotate(-45);
pause(300);
} else {
robot.forward();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
}
});
// just run until RUN button is pressed again
Button.RUN.waitForPressAndRelease();
} //main()
public static void pause(int delay)
{
try { Thread.sleep(delay); }
catch (InterruptedException ie) { }
}
}
