SPQLrobotics
23-03-2016, 17:23
Our team, 5941, has struggled to get autonomous working. This is our code for autonomous:
public void autonomousInit() {
autoState = -1;
t.start();
lastTime = t.get();
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
switch (autoSelected) {
case "doNothing":
break;
default:
case defaultAuto:
LowBarAuton();
//encoderAuto();
break;
// case "spybot":
// SpyBotAuton();
// break;
// case "rampWithStuff":
// RampAuton();
// break;
}
}
public void LowBarAuton() {
switch (autoState){
default:
lastTime = t.get();
autoState = 0;
end1.set(0.5);
end2.set(0.5);
break;
case 0:
pneumatic.set(-0.75);
if ( t.get() - lastTime > 2){
autoState = 1;
lastTime = t.get();
}
break;
case 1:
pneumatic.set(0.0);
leftSide.set(0.4);
rightSide.set(-0.4);
if ( t.get() - lastTime > 5){
autoState = 2;
lastTime = t.get();
}
break;
case 2:
rightSide.set(0.0);
leftSide.set(0.0);
autoSelected = "doNothing";
break;
}
}
public void encoderAuto(){
pneumatic.set(-0.75);
Timer.delay(2.0);
pneumatic.set(0.0);
if (encLeft.getDistance() < 4 && encRight.getDistance() > -4 && !forwardDone){
leftSide.set(0.4);
rightSide.set(-0.4);
} else if (encLeft.getDistance() >= 4 && encRight.getDistance() <= -4 && !forwardDone) {
forwardDone = true;
leftSide.set(0.0);
rightSide.set(0.0);
encLeft.reset();
encRight.reset();
Timer.delay(1.0);
}else if (encLeft.getDistance() > -4 && encRight.getDistance() < 4 && !backwardDone && forwardDone) {
leftSide.set(-0.4);
rightSide.set(0.4);
}else if (encLeft.getDistance() <= -4 && encRight.getDistance() >= 4 && !backwardDone && forwardDone) {
backwardDone = true;
leftSide.set(0);
rightSide.set(0);
autoSelected = "doNothing";
}
}
The LowBarAuton() is supposed to drive under the low bar, then back up to the other side so that as soon as teleop starts we can clear that defense. It is using timers.
encoderAuto() is attempting to do the same thing as LowBarAuton(), only using encoders instead of timers. Neither have worked.
I also am attaching the full code, in the event that this code is not enough. Help would be appreciated.
public void autonomousInit() {
autoState = -1;
t.start();
lastTime = t.get();
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
switch (autoSelected) {
case "doNothing":
break;
default:
case defaultAuto:
LowBarAuton();
//encoderAuto();
break;
// case "spybot":
// SpyBotAuton();
// break;
// case "rampWithStuff":
// RampAuton();
// break;
}
}
public void LowBarAuton() {
switch (autoState){
default:
lastTime = t.get();
autoState = 0;
end1.set(0.5);
end2.set(0.5);
break;
case 0:
pneumatic.set(-0.75);
if ( t.get() - lastTime > 2){
autoState = 1;
lastTime = t.get();
}
break;
case 1:
pneumatic.set(0.0);
leftSide.set(0.4);
rightSide.set(-0.4);
if ( t.get() - lastTime > 5){
autoState = 2;
lastTime = t.get();
}
break;
case 2:
rightSide.set(0.0);
leftSide.set(0.0);
autoSelected = "doNothing";
break;
}
}
public void encoderAuto(){
pneumatic.set(-0.75);
Timer.delay(2.0);
pneumatic.set(0.0);
if (encLeft.getDistance() < 4 && encRight.getDistance() > -4 && !forwardDone){
leftSide.set(0.4);
rightSide.set(-0.4);
} else if (encLeft.getDistance() >= 4 && encRight.getDistance() <= -4 && !forwardDone) {
forwardDone = true;
leftSide.set(0.0);
rightSide.set(0.0);
encLeft.reset();
encRight.reset();
Timer.delay(1.0);
}else if (encLeft.getDistance() > -4 && encRight.getDistance() < 4 && !backwardDone && forwardDone) {
leftSide.set(-0.4);
rightSide.set(0.4);
}else if (encLeft.getDistance() <= -4 && encRight.getDistance() >= 4 && !backwardDone && forwardDone) {
backwardDone = true;
leftSide.set(0);
rightSide.set(0);
autoSelected = "doNothing";
}
}
The LowBarAuton() is supposed to drive under the low bar, then back up to the other side so that as soon as teleop starts we can clear that defense. It is using timers.
encoderAuto() is attempting to do the same thing as LowBarAuton(), only using encoders instead of timers. Neither have worked.
I also am attaching the full code, in the event that this code is not enough. Help would be appreciated.