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

Commit 76b2237

Browse files
committed
PIDMove works (actually for good this time)
changed some things in shiftGears fixes w/ SDInterface really quick moveController no longer sets its range based on speed (bc that made sense)
1 parent 11e2b95 commit 76b2237

7 files changed

Lines changed: 41 additions & 18 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/Robot.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public void putData(String string, PIDController controller) {
7878
public void putNumber(String string, double d) {
7979
SmartDashboard.putNumber(string, d);
8080
}
81+
82+
public void putBoolean(String string, boolean b) {
83+
SmartDashboard.putBoolean(string, b);
84+
}
85+
8186
/*
8287
* if (!SmartDashboard.containsKey("Const/" + key)) { if
8388
* (!SmartDashboard.putNumber("Const/" + key, def)) {
@@ -114,7 +119,7 @@ public void robotInit() {
114119
climberAssist = new ClimberAssist();
115120
intakeEject = new IntakeEject();
116121
lift = new Lift();
117-
dt = new Drivetrain();
122+
dt = new Drivetrain(sd);
118123
oi = new OI();
119124

120125
// auto position chooser

Robot2018/src/org/usfirst/frc/team199/Robot2018/SmartDashboardInterface.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ public interface SmartDashboardInterface {
88
public void putData(String string, PIDController controller);
99

1010
public void putNumber(String string, double d);
11+
12+
public void putBoolean(String string, boolean b);
1113
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/PIDMove.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,10 @@ public void initialize() {
151151

152152
dt.resetDistEncs();
153153
moveController.disable();
154-
// input is in inches
155-
moveController.setInputRange(-dt.getCurrentMaxSpeed(), dt.getCurrentMaxSpeed());
156154
// output in "motor units" (arcade and tank only accept values [-1, 1]
157155
moveController.setOutputRange(-1.0, 1.0);
158156
moveController.setContinuous(false);
159-
moveController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 0.1));
157+
moveController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 0.5));
160158
System.out.println("move target = " + target);
161159
moveController.setSetpoint(target);
162160

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/ShiftHighGear.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.usfirst.frc.team199.Robot2018.Robot;
44

55
import edu.wpi.first.wpilibj.command.InstantCommand;
6-
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
76

87
/**
98
* Shifts the DT to high gear.
@@ -20,7 +19,5 @@ public ShiftHighGear() {
2019
@Override
2120
protected void initialize() {
2221
Robot.dt.shiftGears(true);
23-
SmartDashboard.putBoolean("High Gear", true);
24-
Robot.dt.resetAllVelocityPIDConsts();
2522
}
2623
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/ShiftLowGear.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.usfirst.frc.team199.Robot2018.Robot;
44

55
import edu.wpi.first.wpilibj.command.InstantCommand;
6-
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
76

87
/**
98
* Shifts the DT to low gear.
@@ -20,7 +19,5 @@ public ShiftLowGear() {
2019
@Override
2120
protected void initialize() {
2221
Robot.dt.shiftGears(false);
23-
SmartDashboard.putBoolean("High Gear", false);
24-
Robot.dt.resetAllVelocityPIDConsts();
2522
}
2623
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/TeleopDrive.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ protected void initialize() {
3232
@Override
3333
protected void execute() {
3434
if (Robot.getBool("Teleop velocity PID", false)) {
35-
Robot.dt.resetVPIDInputRanges();
35+
Robot.dt.resetVPIDAndRobotDriveRanges();
3636
Robot.dt.resetAllVelocityPIDConsts();
37+
if (Robot.dt.VPIDsOnTarg()) {
38+
Robot.dt.disableVelocityPIDs();
39+
} else {
40+
Robot.dt.enableVelocityPIDs();
41+
}
3742
}
3843
Robot.dt.teleopDrive();
3944
}

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.usfirst.frc.team199.Robot2018.Robot;
1111
import org.usfirst.frc.team199.Robot2018.RobotMap;
12+
import org.usfirst.frc.team199.Robot2018.SmartDashboardInterface;
1213
import org.usfirst.frc.team199.Robot2018.autonomous.PIDSourceAverage;
1314
import org.usfirst.frc.team199.Robot2018.autonomous.VelocityPIDController;
1415
import org.usfirst.frc.team199.Robot2018.commands.TeleopDrive;
@@ -48,7 +49,15 @@ public class Drivetrain extends Subsystem implements DrivetrainInterface {
4849
private final AHRS fancyGyro = RobotMap.fancyGyro;
4950
private final DoubleSolenoid dtGear = RobotMap.dtGear;
5051

51-
public Drivetrain() {
52+
private SmartDashboardInterface sd;
53+
54+
private boolean highGear;
55+
56+
public Drivetrain(SmartDashboardInterface sd) {
57+
this.sd = sd;
58+
59+
highGear = false;
60+
5261
// all 0s for controller construction because they all get set to right values
5362
// by resetAllVelocityPIDConsts
5463
leftVelocityController = new VelocityPIDController(0, 0, 0, 0, leftEncRate, dtLeft);
@@ -73,9 +82,7 @@ public Drivetrain() {
7382
robotDrive.setMaxOutput(Robot.getConst("Max High Speed", 204));
7483
} else {
7584
robotDrive = new DifferentialDrive(dtLeft, dtRight);
76-
7785
}
78-
7986
}
8087

8188
@Override
@@ -131,6 +138,10 @@ public double getRightVPIDOutput() {
131138
return dtRight.get();
132139
}
133140

141+
public boolean VPIDsOnTarg() {
142+
return leftVelocityController.onTarget() && rightVelocityController.onTarget();
143+
}
144+
134145
/**
135146
* Returns the getRate() of the left encoder
136147
*
@@ -374,12 +385,17 @@ public double getRightEncDist() {
374385
* low gear (false, kForward)
375386
*/
376387
@Override
377-
public void shiftGears(boolean highGear) {
378-
if (highGear ^ Robot.getBool("Drivetrain Gear Shift Low", false)) {
388+
public void shiftGears(boolean shiftToHighGear) {
389+
if (shiftToHighGear ^ Robot.getBool("Drivetrain Gear Shift Low", false)) {
379390
dtGear.set(DoubleSolenoid.Value.kReverse);
391+
highGear = true;
380392
} else {
381393
dtGear.set(DoubleSolenoid.Value.kForward);
394+
highGear = false;
382395
}
396+
sd.putBoolean("High Gear", highGear);
397+
resetAllVelocityPIDConsts();
398+
resetVPIDAndRobotDriveRanges();
383399
}
384400

385401
/**
@@ -458,10 +474,13 @@ public void resetVelocityPIDkPConsts() {
458474
SmartDashboard.putNumber("VPID Right kP", newkP);
459475
}
460476

461-
public double resetVPIDInputRanges() {
477+
public double resetVPIDAndRobotDriveRanges() {
462478
double currentMaxSpd = getCurrentMaxSpeed();
463479
leftVelocityController.setInputRange(-currentMaxSpd, currentMaxSpd);
464480
rightVelocityController.setInputRange(-currentMaxSpd, currentMaxSpd);
481+
if (Robot.getBool("Teleop velocity PID", false)) {
482+
robotDrive.setMaxOutput(currentMaxSpd);
483+
}
465484
return currentMaxSpd;
466485
}
467486

@@ -472,7 +491,7 @@ public double resetVPIDInputRanges() {
472491
*/
473492
@Override
474493
public double getCurrentMaxSpeed() {
475-
if (SmartDashboard.getBoolean("High Gear", true)) {
494+
if (highGear) {
476495
return Robot.getConst("Max High Speed", 204);
477496
} else {
478497
return Robot.getConst("Max Low Speed", 84);

0 commit comments

Comments
 (0)