Thread: Autonomous Help
View Single Post
  #11   Spotlight this post!  
Unread 01-21-2015, 08:33 AM
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
Add parameters to your method call and it's perfect.
I think I have this right but before we wrap this up I just wanted to check a few things. Do I need < , > or ==. Also I would like to print a distance traveled to my smart DS is that just SmartDashboard.putNumber("Distance", encoder.getDistance()); or can I make a double distance = encoder.getDistance(); and just put distance in there?? Here's my code so far.
Code:
public class Robot extends IterativeRobot {
	
	RobotDrive robot;
    Joystick stick;
    Encoder encoder;	
    Gyro gyro1;
    
    static final double Kp = 0.05;
    
    public void robotInit() {
    	
    	 robot = new RobotDrive(0, 1);
         stick = new Joystick(0);
         gyro1 = new Gyro(0);
         gyro1.reset();
         gyro1.initGyro();
         Encoder encoder = new Encoder(1, 2, false, EncodingType.k4X);
         
         encoder.setDistancePerPulse(0.001);
         encoder.getDistance(); // does this belong in the init or my if loop?

    }

   
    public void autonomousPeriodic() {

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

    			break; 
    			
    			}
    		
    			Timer.delay(0.1);
    	}
    	
				while (isAutonomous() && isEnabled()) {

						double angle2 = gyro1.getAngle(); 
						
						robot.drive(-0.20, -angle2 * Kp); 
					// This can't be right lol..... at least its no longer dead code (: also in my if statement do i need < or > or ==?
						if(encoder.getDistance() > 50)  {
							robot.drive(0,0); 
							
							break;
						}
						Timer.delay(0.1);	
				}
				
    			}
Reply With Quote