Thread: Autonomous Help
View Single Post
  #15   Spotlight this post!  
Unread 21-01-2015, 08:56
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by notmattlythgoe View Post
Yes you can, but you are going to want to make sure that you put the distance variable in the second loop so it gets updated when you are driving.

Another thing I forgot to have you do is reset the encoder prior to the second loop. You can do this in the same place you reset the gyro.
Code:
encoder.reset();
I think this is perfect now I am very excited to test this.
Code:
public void autonomousPeriodic() {

    	gyro1.reset();
		
    	while(isAutonomous() && isEnabled())  {
    		
    		double angle = gyro1.getAngle();
    		double distance = encoder.getDistance();
    		
    		SmartDashboard.putNumber("Angle", angle);
    		SmartDashboard.putNumber("Distance", distance);
    		
    		robot.drive(-0.25, 1);
    		
    		if(angle > 150) {
    			
    			robot.drive(0,0);
    			gyro1.reset();
    			encoder.reset();
    			
    			Timer.delay(1.00);

    			break; 
    			
    			}
    		
    			Timer.delay(0.1);
    	}
    	
				while (isAutonomous() && isEnabled()) {
					
					double distance2 = encoder.getDistance();

					double angle2 = gyro1.getAngle(); 
						
					robot.drive(-0.20, -angle2 * Kp); 
					
						if(distance2 > 50)  {
							robot.drive(0,0); 
							
							break;
						}
						Timer.delay(0.1);	
				}
				
    			}
Reply With Quote