View Single Post
  #1   Spotlight this post!  
Unread 04-11-2014, 18:10
MaestroRoboto's Avatar
MaestroRoboto MaestroRoboto is offline
Registered User
AKA: Hiren Bhavsar
FLL #0020 (The Rocketeers)
Team Role: Alumni
 
Join Date: Mar 2014
Rookie Year: 2012
Location: United States
Posts: 25
MaestroRoboto has a spectacular aura aboutMaestroRoboto has a spectacular aura about
Can someone explain this code?

Could someone explain what is going on in this code?

public class Drivetrain {

Talon talon1 = new Talon(1);
Talon talon2 = new Talon(2);
Talon talon3 = new Talon(3);
Talon talon4 = new Talon(4);
Talon talon5 = new Talon(5);
Talon talon6 = new Talon(6);

DoubleSolenoid shifter = new DoubleSolenoid(1, 5, 6);

Encoder leftEncoder = new Encoder(10, 11);
Encoder rightEncoder = new Encoder(13, 14);

public Drivetrain(){
leftEncoder.start();
rightEncoder.start();
}

//DigitalInput port14 = new DigitalInput(14);
public void arcadeDrive(double moveValue, double rotateValue){
double leftMotorSpeed = 0, rightMotorSpeed = 0;

rotateValue = -rotateValue;
moveValue = limit(moveValue);
rotateValue = limit(rotateValue);

if (moveValue > 0.0) {
if (rotateValue > 0.0) {
leftMotorSpeed = moveValue - rotateValue;
rightMotorSpeed = Math.max(moveValue, rotateValue);
} else {
leftMotorSpeed = Math.max(moveValue, -rotateValue);
rightMotorSpeed = moveValue + rotateValue;
}
} else {
if (rotateValue > 0.0) {
leftMotorSpeed = -Math.max(-moveValue, rotateValue);
rightMotorSpeed = moveValue + rotateValue;
} else {
leftMotorSpeed = moveValue - rotateValue;
rightMotorSpeed = -Math.max(-moveValue, -rotateValue);
}
}

//Setting talon values
talon1.set(-rightMotorSpeed);
talon2.set(rightMotorSpeed);
talon3.set(rightMotorSpeed);
talon4.set(leftMotorSpeed);
talon5.set(-leftMotorSpeed);
talon6.set(-leftMotorSpeed);
}

protected static double limit(double num) {
if (num > 1.0) {
return 1.0;
}
if (num < -1.0) {
return -1.0;
}
return num;
}

public void highGear(){
shifter.set(DoubleSolenoid.Value.kReverse);
}

public void lowGear(){
shifter.set(DoubleSolenoid.Value.kForward);
}

public void brake(){

}

public int getRightDistance(){
//return port14.get();
return rightEncoder.get();
}

public int getLeftDistance(){
return leftEncoder.get();
}

public void resetEncoders(){
leftEncoder.reset();
rightEncoder.reset();

}
}
Reply With Quote