View Single Post
  #1   Spotlight this post!  
Unread 29-01-2015, 17:20
B0sh B0sh is offline
Registered User
FRC #2078 (Robotic Wolves)
Team Role: Programmer
 
Join Date: Feb 2014
Rookie Year: 2012
Location: Louisiana
Posts: 6
B0sh is an unknown quantity at this point
Gyro not proprely reading

I know a gyro post was just made, but this problem is different from the other guy's.

The value from gyro.getAngle() is steadily increasing although the gyro is not being moved. At first it starts out at 0 and then it goes up slightly, then by the time it gets to 1 its rising very quickly.

We've tried everything: Switching the gyro to a different analog port, Switching the PWM cable, changing our code, swapping out the gyro, calibrating the gyro...

I just have no idea what the issue could be. I've read many guides and I've followed them to the tee. My question is is there any other trouble shooting things I can do?

I've posted all of my code for reference, with the gyro code commented out. (The angle reading still went up just the same though)

Code:
/**
 * FRC 2078 Robot using Mecanum Drive and Camera 
 */
public class Robot extends SampleRobot {
	Gyro gyro;
    RobotDrive robotDrive;
    Joystick stick;
    CameraServer server;

    // Channels for the wheels
    final int frontLeftChannel	= 0;
    final int rearLeftChannel	= 1;
    final int frontRightChannel	= 2;
    final int rearRightChannel	= 3;
    
    // The channel on the driver station that the joystick is connected to
    final int joystickChannel	= 0;
    
    /** 
     * Constructor for the robot
     */
    public Robot() {
        server = CameraServer.getInstance();
        server.setQuality(50);
        //the camera name (ex "cam0") can be found through the roborio web interface
        server.startAutomaticCapture("cam0");
        
        //Create Robot Drive
    	robotDrive = new RobotDrive(frontLeftChannel, rearLeftChannel, frontRightChannel, rearRightChannel);
    	robotDrive.setExpiration(0.1);
        robotDrive.setInvertedMotor(MotorType.kFrontLeft, true);	// invert the left side motors
    	robotDrive.setInvertedMotor(MotorType.kRearLeft, true);		// you may need to change or remove this to match your robot
        gyro = new Gyro(1);
        stick = new Joystick(joystickChannel);
    }
        
    /**
     * Runs the motors with Mecanum drive.
     */
    public void operatorControl() {
        robotDrive.setSafetyEnabled(true);
        gyro.reset();
        
        boolean buttonFour;
        buttonFour = stick.getRawButton(4);
        boolean buttonFive;
        buttonFive = stick.getRawButton(5);
        boolean forceTurn = false;
        
        double turn = 0;
        
        while (isOperatorControl() && isEnabled()) {
        	SmartDashboard.putNumber("Angle", gyro.getAngle());
        	buttonFour = stick.getRawButton(4);
        	buttonFive = stick.getRawButton(5);
        	
        	/*
        	if (Math.abs(gyro.getAngle()) > 1) {
        		
        	//	turn = (-gyro.getAngle()/45);
        		turn = 0;
        		
        	} else {
        	*/
        		if (buttonFour) {
        			turn = -.5;
        			forceTurn = true;
        		} else {
	        		if (buttonFive){
	        			turn = .5;
	        			forceTurn = true;
	        		} else
	        			turn = 0;
        		}
        		/*
        	}        			
//        		*/
        	
        	
        	// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
        	// This sample does not use field-oriented drive, so the gyro input is set to zero.
            
        	//positive Z turns right
        	//negative Z turns left
        	while (stick.getRawButton(4) || stick.getRawButton(5)){
               	robotDrive.mecanumDrive_Cartesian(stick.getX(), stick.getY(), turn, 0);
                SmartDashboard.putNumber("Angle", gyro.getAngle());
                Timer.delay(0.005);	// wait 5ms to avoid hogging CPU cycles
                gyro.reset();
        	}
        	
        	if (!stick.getRawButton(4) && !stick.getRawButton(5)){
        		robotDrive.mecanumDrive_Cartesian(stick.getX(), stick.getY(), turn, 0);
        		SmartDashboard.putNumber("Angle", gyro.getAngle());
        		Timer.delay(0.005);	// wait 5ms to avoid hogging CPU cycles
        	}
        	
            if (forceTurn){
            	Timer.delay(.25);
            	gyro.reset();
            	forceTurn = false;
            }
        }
    }
}
Reply With Quote