Skip to content

Commit 0e6fcd7

Browse files
authored
reverse voltage
1 parent a6efd1f commit 0e6fcd7

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

  • TeamCode/src/main/java/org/firstinspires/ftc/teamcode/pedroPathing

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/pedroPathing/Tuning.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -749,25 +749,28 @@ private enum State {
749749
RECORD,
750750
DONE
751751
}
752-
752+
753753
private static class BrakeRecord {
754754
double timeMs;
755755
Pose pose;
756756
double velocity;
757-
757+
758758
BrakeRecord(double timeMs, Pose pose, double velocity) {
759759
this.timeMs = timeMs;
760760
this.pose = pose;
761761
this.velocity = velocity;
762762
}
763763
}
764764

765+
private double lastDriveSign = 1.0;
766+
private static final int BRAKE_PULSE_MS = 150;
767+
765768
private State state = State.START_MOVE;
766769

767770
private final ElapsedTime timer = new ElapsedTime();
768771

769772
private int iteration = 0;
770-
773+
771774
private Vector startPosition;
772775
private double measuredVelocity;
773776

@@ -813,12 +816,14 @@ public void loop() {
813816
state = State.DONE;
814817
break;
815818
}
816-
819+
817820
double currentPower = TEST_POWERS[iteration];
818821
follower.setMaxPower(currentPower);
819822
if (iteration % 2 != 0) {
823+
lastDriveSign = -1.0;
820824
follower.setTeleOpDrive(-1, 0, 0, true);
821825
} else {
826+
lastDriveSign = 1.0;
822827
follower.setTeleOpDrive(1, 0, 0, true);
823828
}
824829

@@ -837,7 +842,8 @@ public void loop() {
837842
}
838843

839844
case APPLY_BRAKE: {
840-
stopRobot();
845+
double reversePower = -lastDriveSign * follower.constants.predictiveBrakingCoefficients.maximumBrakingPower;
846+
follower.setTeleOpDrive(reversePower, 0, 0, true);
841847

842848
timer.reset();
843849
state = State.WAIT_BRAKE_TIME;
@@ -848,9 +854,13 @@ public void loop() {
848854
double t = timer.milliseconds();
849855
Pose currentPose = follower.getPose();
850856
double currentVelocity = follower.getVelocity().getMagnitude();
851-
857+
852858
brakeData.add(new BrakeRecord(t, currentPose, currentVelocity));
853-
859+
860+
if (t >= BRAKE_PULSE_MS) {
861+
stopRobot();
862+
}
863+
854864
if (timer.milliseconds() >= BRAKE_WAIT_MS || follower.getVelocity().getMagnitude() <= .05) {
855865
state = State.RECORD;
856866
}
@@ -864,8 +874,8 @@ public void loop() {
864874
velocityToBrakingDistance.add(new double[]{measuredVelocity, brakingDistance});
865875

866876
telemetryM.debug("Test " + iteration,
867-
String.format("v=%.3f d=%.3f", measuredVelocity,
868-
brakingDistance));
877+
String.format("v=%.3f d=%.3f", measuredVelocity,
878+
brakingDistance));
869879
telemetryM.update(telemetry);
870880

871881
iteration++;
@@ -889,9 +899,9 @@ public void loop() {
889899
for (BrakeRecord record : brakeData) {
890900
Pose p = record.pose;
891901
telemetryM.debug(String.format("t=%.0f ms, x=%.2f, y=%.2f, θ=%.2f, v=%.2f",
892-
record.timeMs, p.getX(), p.getY(),
893-
p.getHeading(),
894-
record.velocity));
902+
record.timeMs, p.getX(), p.getY(),
903+
p.getHeading(),
904+
record.velocity));
895905
}
896906
telemetryM.update();
897907
break;

0 commit comments

Comments
 (0)