Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit 144f0d8

Browse files
committed
reversable DT implementation
1 parent 41694b2 commit 144f0d8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Robot2018/src/org/usfirst/frc/team199/Robot2018/subsystems/Drivetrain.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ public class Drivetrain extends Subsystem implements DrivetrainInterface {
5252
private SmartDashboardInterface sd;
5353

5454
private boolean highGear;
55+
private boolean isInverted;
5556
private int inverted;
5657

58+
/**
59+
* Sets up velocity PID controllers. Initializes to not in high gear and to not
60+
* inverted.
61+
*/
5762
public Drivetrain(SmartDashboardInterface sd) {
5863
this.sd = sd;
5964

6065
highGear = false;
66+
67+
isInverted = false;
6168
inverted = 1;
6269

6370
// all 0s for controller construction because they all get set to right values
@@ -87,8 +94,17 @@ public Drivetrain(SmartDashboardInterface sd) {
8794
}
8895
}
8996

97+
/**
98+
* Inverts the drivetrain (forward is backward, left is right) by toggling a
99+
* motor output multiplier (between 1 and -1) and the distance encoders (between
100+
* inverted or not). The motor output multiplier is used in arcadeDrive and
101+
* tankDrive for final speed/turn and left/right outputs.
102+
*/
90103
public void reverseDT() {
91104
inverted *= -1;
105+
isInverted = !isInverted;
106+
leftEncDist.setReverseDirection(isInverted);
107+
rightEncDist.setReverseDirection(isInverted);
92108
}
93109

94110
@Override
@@ -268,7 +284,7 @@ public void arcadeDrive(double speed, double turn) {
268284
turn *= Robot.getConst("Turn Slow Ratio", 0.5);
269285
}
270286
}
271-
robotDrive.arcadeDrive(speed, turn, Robot.getBool("Square Drive Values", false));
287+
robotDrive.arcadeDrive(inverted * speed, inverted * turn, Robot.getBool("Square Drive Values", false));
272288
}
273289

274290
/**
@@ -285,7 +301,7 @@ public void tankDrive(double leftSpeed, double rightSpeed) {
285301
leftSpeed *= Robot.getConst("Speed Slow Ratio", 0.5);
286302
rightSpeed *= Robot.getConst("Speed Slow Ratio", 0.5);
287303
}
288-
robotDrive.tankDrive(leftSpeed, rightSpeed, Robot.getBool("Square Drive Values", false));
304+
robotDrive.tankDrive(inverted * leftSpeed, inverted * rightSpeed, Robot.getBool("Square Drive Values", false));
289305
}
290306

291307
/**

0 commit comments

Comments
 (0)