View Single Post
  #5   Spotlight this post!  
Unread 13-02-2015, 10:42
Rakusan2 Rakusan2 is offline
Registered User
AKA: Tomas Rakusan
FRC #3571 (Milton Mustangs)
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2011
Location: Milton, ON, Canada
Posts: 22
Rakusan2 is an unknown quantity at this point
Re: Encoders and rpm

If you only want to keep the motors in sync and would not mind not knowing the rpm then you can try something like what I have bellow.

PS: I have not yet tried this code so you might want to play with the initial motor values and by how much they are changed

Code:
	Encoder leftEncoder = new Encoder(0,1), rightEncoder = new Encoder(2,3);
	Timer time = new Timer();
	Talon motor1 = new Talon(0), motor2 = new Talon(1);
	public void autonomousInit(){
		time.start();
		leftEncoder.reset();
		rightEncoder.reset();
	}
	public void autonomousPeriodic() {
    		if(time.get() < 5){
    			double left=0.8 , right=0.8;
    			int dif = leftEncoder.get()-rightEncoder.get();
    			if (dif>0){
    				left-=0.1;
    				right+=0.1;
    			}
    			else if(dif<0){
    				left+=0.1;
    				right-=0.1;
    			}
    			motor1.set(left);
    			motor2.set(right);
    		}
	}
Reply With Quote