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