This year our team was finally able to track shapes with the vision tape. During the build season we were able to track 1 target perfectly, but when we added the other 3 targets the robot freaked out and would track right. It would track the two side targets switching between them. We've looked at the code multiple times and couldn't figure out why it wasn't able to lock onto the center. Would someone be able to look at our code to lead us in the right direction on why we aren't able to track multiple targets at once. Your help is greatly appreciated. Thanks in advance.
This is part of our teleop mode where when you press a button it calls a method to find the targets and tells the Drive Team when its ready to shoot.
Code:
else if (stickShooter.getRawButton(2)) {
readyToShoot = "Not ready to shoot";
//[%Initialize to Shoot]
if (centered< 15)//Change #
{
direction = cameraDirection(isBlueLED == true);
}
readyToShoot = "Ready to Shoot";
printUserMessage(output, 1, 1, dsBlank);
printUserMessage(output, 2, 1, dsBlank);
printUserMessage(output, 3, 1, dsBlank);
printUserMessage(output, 4, 1, dsBlank);
printUserMessage(output, 5, 1, dsBlank);
printUserMessage(output, 6, 1, dsBlank);
printUserMessage(output, 1, 1, mode);
printUserMessage(output, 2, 1, readyToShoot);
output.updateLCD();
/* Was using tankDrive but gave errors when ran the code. Also tried myDrive but robot wouldn't move. We have watchDog. May we need to disable it when it tracks?
* if (direction == 1) { // myDrive.drive(0.50, 1.0);
*
* turretJag.set(direction * .65); //BEFORE USING TURRET } else
* if (direction == -1) { myDrive.drive(0.50, -1.0); } else {
* //myDrive.drive(0.0, 0.0); turretJag.set(0); }
*/
turretJag.set(direction * .65); //BEFORE USING TURRET
direction = 0;
} else {
direction = 0;
turretJag.set(0.0);
}
//[%Camera]
public int cameraDirection(boolean ledIsBlue) {
//printAll();
output.updateLCD();
BinaryImage bImg;
int lowestSquare = 0;
int lowSquareIndex = 0;
int cameraDirection = 0; //is it right
System.out.println("It Worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
try {
ColorImage img = camera.getImage();
//System.out.println("Got IMAGE!!!!");
if (ledIsBlue) {
bImg = img.thresholdHSL(126, 155, 0, 255, 150, 255);
//BLUE
System.out.println("IS BLUE");
} else {
bImg = img.thresholdHSL(85, 128, 0, 255, 150, 255);
//GREEN
}
ParticleAnalysisReport[] reports = bImg.getOrderedParticleAnalysisReports(4);//Was 1
if (reports.length > 0) {
//System.out.println("REPORTS > 0");
for (int i = 0; i < reports.length; i++) {
if (reports[i].imageHeight > minSquareHeight && reports[i].center_mass_y > lowestSquare) {
lowestSquare = reports[i].center_mass_y;
lowSquareIndex = i;
System.out.println("Target: " + i + " " + reports[i].center_mass_x + "," + reports[i].center_mass_y);
}
}
}
if (reports[lowSquareIndex].center_mass_x < 0.9 * (WIDTH / 2)) {
//Was reports[lowSquareIndex]. instead of 0
System.out.println("LEFT");
centered = 0;
direction = -1;
} else if (reports[lowSquareIndex].center_mass_x > 1.1 * (WIDTH / 2)) {
//.center_mass_y before
//Was reports[lowSquareIndex]. instead of 0
System.out.println("RIGHT");
centered = 0;
direction = 1;
} else if ((reports[lowSquareIndex].center_mass_x > 0.9 * (WIDTH / 2)) && (reports[lowSquareIndex].center_mass_x < 1.1 * (WIDTH / 2))) {
//Was reports[lowSquareIndex]. instead of 0
System.out.println("BATMAN");
centered += 1;
direction = 0;
} else {
System.out.println("NO TARGET");
centered = 0;
direction = 0;
}
img.free();
bImg.free();
System.out.println("FREED IMAGES");
} catch (AxisCameraException ex) {
System.out.println("Axis Camera Exception");
} catch (NIVisionException ex) {
System.out.println("NI Vision Exception");
}
output.updateLCD();
return direction;
}