Thread: Tracking Issues
View Single Post
  #1   Spotlight this post!  
Unread 18-02-2012, 22:06
questionsigotem questionsigotem is offline
Registered User
FRC #1647
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2009
Location: New Jersey
Posts: 14
questionsigotem is an unknown quantity at this point
Tracking Issues

We're having troubles getting our tracking to well track... We had it working fine when it was one target but now with multiple targets in the same screen it's being difficult.

So our code looks like this: below.

Is there anything that stands out that could be the issue that were just not seeing? Could it possibly be the "or" statements messing with us?
Any help is greatly appreciated. Thank you.


Code:
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.camera.*;
import edu.wpi.first.wpilibj.image.*;

    AxisCamera camera;
    
    public void robotInit() {
		camera = AxisCamera.getInstance();
		camera.writeResolution(AxisCamera.ResolutionT.k320x240);
		camera.writeCompression(30);
		camera.writeBrightness(0);
    }
    
    public void autonomous() {
        while(isAutonomous()){
            //direction = cameraDirection(true);
            System.out.println("In Auto");
            try {
                ColorImage img = camera.getImage();
            } catch (AxisCameraException ex) {
                ex.printStackTrace();
            } catch (NIVisionException ex) {
                ex.printStackTrace();
            }
            
            }
        }

    public void operatorControl() {
        
               
        while (isOperatorControl()) {
                    //TURRET CODE::::DJKFLS:JFLK 
       if ((turretPot.getVoltage() <= 1.64) && (atTurretLeftLimit == false)){
            turretJag.set(0);
            atTurretLeftLimit = true;
            atTurretRightLimit = false;
            }
        else if (turretPot.getVoltage() >= 4.07 && atTurretRightLimit == false){
            turretJag.set(0.0);
            atTurretLeftLimit = false;
            atTurretRightLimit = true;
        }
        else if (atTurretLeftLimit == true &&(stickShooter.getAxis(Joystick.AxisType.kZ) < 0.0 && stickShooter.getRawButton(4) == true)|| direction < 0.0){
            turretJag.set(0.0);
            atTurretLeftLimit = false;
        }
        else if (atTurretRightLimit == true && (stickShooter.getAxis(Joystick.AxisType.kZ) > 0.0 && stickShooter.getRawButton(4) == true) || direction > 0.0){
            turretJag.set (0.0);
            atTurretRightLimit = false;
        } 
        else if (stickShooter.getRawButton(4)){
            turretJag.set(stickShooter.getAxis(Joystick.AxisType.kZ));
        }else if (centerPressed == true){
            //Center turret
            if(turretPot.getVoltage() < 2.81){
                turretJag.set(1.0);
            }else if (turretPot.getVoltage() > 2.91){
                turretJag.set(-1.0);
            }else{
                turretJag.set(0.0);
                centerPressed = false;
            }
        }
        else if (stickShooter.getRawButton(2)){
            direction = cameraDirection(isBlueLED == true);
            if (turretBroken == true){
                //use wheels drive
            }
            else {
                
                turretJag.set(direction * .65);
            }
        }
        else {
            direction = 0;
            turretJag.set(0.0);
        }
 
                } // end of opperator control

        
    public int cameraDirection(boolean ledIsBlue)
	    {
		BinaryImage bImg;
		int lowestSquare = 0;
		int lowSquareIndex = 0;
		int cameraDirection = 0;
                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);

			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;
						}
					}
				}

			if (reports[lowSquareIndex].center_mass_x < 0.9 * (WIDTH / 2))
				{
				System.out.println("LEFT");
				cameraDirection = -1;
				} else if (reports[lowSquareIndex].center_mass_y > 1.1 * (WIDTH / 2))
				{
				System.out.println("RIGHT");
				cameraDirection = 1;
				} else
				{
				System.out.println("CENTER");
				cameraDirection = 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");
			}
		return cameraDirection;
	    }

} //end of class
Reply With Quote