Here's my line sensing code:
Code:
package com.robototes.abomasnow;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
public class Main extends SimpleRobot {
Driver robot = new Driver(1,2);
LineSensorGroup lsg = new LineSensorGroup(1,2,3);
final int middle = 2;
final int left = 1;
final int right = 3;
public void autonomous() {
getWatchdog().feed();
int last = middle; //last line sensor value
while(this.isEnabled() && this.isAutonomous()) {
if(lsg.getMiddle()) {
last = middle;
} if (lsg.getLeft()) {
last = left;
} if (lsg.getRight()) {
last = right;
}
if (lsg.allAreOff()) {
if (last == left) {
robot.arcadeDrive(0.4, 0.1); //Forward and right*/
System.out.println("Left");
} else if (last == middle) {
robot.arcadeDrive(0.5, 0); /* Straight forward */
System.out.println("Forward");
} else if (last == right) {
robot.arcadeDrive(0.4, -0.1); /* forward and left */
System.out.println("Right");
}
}
if (lsg.allAreOn()) {
if (last == middle) {
robot.stop();
System.out.println("Stopping");
break;
}
}
Timer.delay(0.05);
this.getWatchdog().feed();
}
}
}
Driver is my own motor group controller, RobotDrive was too heavy for me