Skip to content

Commit 837f13d

Browse files
caengineerscaengineers
authored andcommitted
Fix logic in finishing wobble drive
1 parent d8c73e9 commit 837f13d

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

Robot2019/src/main/java/frc/robot/OI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class OI {
5555
rightSlowBtn = new JoystickButton(rightJoy, 1);
5656
rightSlowBtn.whileHeld(new SlowDrive(SlowDrive.Side.RIGHT));
5757
wobbleDriveBtn = new JoystickButton(rightJoy, 4); // TODO: confirm button with drivers
58-
wobbleDriveBtn.whileHeld(new WobbleDrive(dt));
58+
wobbleDriveBtn.whenPressed(new WobbleDrive(dt));
5959
wobbleDriveBtn.whenReleased(new ResetWobble(dt));
6060

6161
arcadeOrTankBtn = new JoystickButton(leftJoy, 4);

Robot2019/src/main/java/frc/robot/commands/ResetWobble.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ResetWobble(Drivetrain dt) {
2828
// Called once when the command executes
2929
@Override
3030
protected void initialize() {
31-
dt.setWobbleDone(false);
31+
dt.setWobbleDone(true);
3232
}
3333

3434
}

Robot2019/src/main/java/frc/robot/commands/SetArcadeOrTank.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public SetArcadeOrTank() {
88

99
}
1010

11+
@Override
1112
protected void initialize() {
1213
if (SmartDashboard.getBoolean("Arcade Drive", true)) {
1314
SmartDashboard.putBoolean("Arcade Drive", false);

Robot2019/src/main/java/frc/robot/commands/WobbleDrive.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class WobbleDrive extends Command {
1616
Drivetrain dt;
1717
Side side = Side.LEFT; // We start with left side. TODO: confirm this
1818
Timer tim;
19+
boolean leftSideDone;
20+
boolean rightSideDone;
1921
private final double wobbleTime = 0.75; // TODO: Set to actual number
2022
private final double driveSpeed = 0.5; // TODO: Set to actual number
2123
private final double encRateTolerance = 0.5; // TODO: Set to actual number
@@ -25,6 +27,8 @@ public WobbleDrive(Drivetrain dt) {
2527
// eg. requires(chassis);
2628
requires(dt);
2729
this.dt = dt;
30+
leftSideDone = false;
31+
rightSideDone = false;
2832
}
2933

3034
// Called just before this Command runs the first time
@@ -33,17 +37,19 @@ protected void initialize() {
3337
tim = new Timer();
3438
tim.reset();
3539
tim.start();
40+
dt.setWobbleDone(false);
3641
}
3742

3843
// Called repeatedly when this Command is scheduled to run
3944
@Override
4045
protected void execute() {
41-
if (dt.wobbleDone())
42-
return;
4346
if (tim.get() > wobbleTime) {
47+
boolean done = dt.getEncRate(Side.LEFT) < encRateTolerance && dt.getEncRate(Side.RIGHT) < encRateTolerance;
4448
if (side == Side.LEFT) {
49+
leftSideDone = done;
4550
side = Side.RIGHT;
4651
} else {
52+
rightSideDone = done;
4753
side = Side.LEFT;
4854
}
4955
tim.reset();
@@ -52,14 +58,12 @@ protected void execute() {
5258
} else {
5359
dt.drive(side == Side.LEFT ? driveSpeed : 0, side == Side.RIGHT ? driveSpeed : 0);
5460
}
55-
if (dt.getEncRate(Side.LEFT) < encRateTolerance && dt.getEncRate(Side.RIGHT) < encRateTolerance)
56-
dt.setWobbleDone(true);
5761
}
5862

5963
// Make this return true when this Command no longer needs to run execute()
6064
@Override
6165
protected boolean isFinished() {
62-
return false;
66+
return dt.wobbleDone() || (leftSideDone && rightSideDone);
6367
}
6468

6569
// Called once after isFinished returns true

0 commit comments

Comments
 (0)