View Full Version : On Java an Line Sensing.
james7132
15-01-2011, 02:25
I don't know if I'm missing the obvious or not, but I can't seem to find a way to implement one of those three line sensors within our robot's program. Anyone tried this out yet?
Patrick Chiang
15-01-2011, 02:57
If the example code they gave us is correct, they're just 3 digital inputs. You place them next to each other and determine which once have "input". If it's showing true, then it you basically assume that the line is under that particular sensor. Using this information, you can determine whether the line is on your left, your right, or if you're right on it.
However, you might want to wait for someone who's actually tried them out to give you an expert opinion. I don't even know what they look like this year because we've been busy designing all week.
bakketti
15-01-2011, 12:20
We got line tracking up and running last night. We didn't use the line tracker example in Netbeans but our code is similar. You pretty much need to access the three digital inputs with the DigitalInput get() method. Just like the example.
1chess2u
05-02-2011, 09:25
If the example code they gave us is correct, they're just 3 digital inputs. You place them next to each other and determine which once have "input". If it's showing true, then it you basically assume that the line is under that particular sensor. Using this information, you can determine whether the line is on your left, your right, or if you're right on it.
However, you might want to wait for someone who's actually tried them out to give you an expert opinion. I don't even know what they look like this year because we've been busy designing all week.
Where is this code?
bakketti
05-02-2011, 12:06
Its a little tricky. Start a new project and find the "Samples" folder. In this folder you will see a "FRC Java" folder. The line tracking sample is in there.
pigpc1993
10-02-2011, 13:19
My team has got our code working. If you guys need help drop us an email.
wasatchrobotics@gmail.com
Robototes2412
10-02-2011, 13:47
Here's my line sensing 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
pigpc1993
10-02-2011, 22:05
If you want some additional help read this.
http://decibel.ni.com/content/servlet/JiveServlet/download/14730-3-26962/%5BFRC%202011%5D%20Line%20Following%20Tutorial.pdf
It talks about labview but it can really be applied to any language. A digital input, which the photoswitch is, returns either a true or false depending up what it is calibrated too. True if its the line, false if it isn't.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.