Well, having done some extensive tracing and finally copying the Target.java and the TrackerDashboard.java files to my project, then copying the following code into the Teleop section:
Code:
ColorImage image = null;
try {
if (cam.freshImage()) {
image = cam.getImage();
Thread.yield();
Target[] targets = Target.findCircularTargets(image);
Thread.yield();
if (targets.length == 0 || targets[0].m_score < kScoreThreshold) {
System.out.println("No target found");
Target[] newTargets = new Target[targets.length + 1];
newTargets[0] = new Target();
newTargets[0].m_majorRadius = 0;
newTargets[0].m_minorRadius = 0;
newTargets[0].m_score = 0;
for (int i = 0; i < targets.length; i++) {
newTargets[i + 1] = targets[i];
}
trackerDashboard.updateVisionDashboard(0.0, gyro.getAngle(), 0.0, 0.0, newTargets);
} else {
System.out.println(targets[0]);
System.out.println("Target Angle: " + targets[0].getHorizontalAngle());
turnController.setSetpoint(gyroAngle + targets[0].getHorizontalAngle());
trackerDashboard.updateVisionDashboard(0.0, gyro.getAngle(), 0.0, targets[0].m_xPos / targets[0].m_xMax, targets);
}
}
} catch (NIVisionException ex) {
ex.printStackTrace();
} catch (AxisCameraException ex) {
ex.printStackTrace();
} finally {
try {
if (image != null) {
image.free();
}
} catch (NIVisionException ex) {
}
I've gone through and figured out (mostly) what this code does, but I don't understand what the line
Code:
turnController.setSetpoint(gyroAngle + targets[0].getHorizontalAngle());
does. In the original file, turnController is:
Code:
PIDController turnController = new PIDController(.08, 0.0, 0.5, gyro, new PIDOutput() {
public void pidWrite(double output) {
drive.arcadeDrive(0, output);
}
}, .005);
but I have no clue what PIDController does. Any help?
EDIT: I know the targeting part probably won't end up in TeleOp, but for now it can stay.