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

Commit ec14fe7

Browse files
Try to fix PIDMove
but it still no workie :(
1 parent cf78034 commit ec14fe7

1 file changed

Lines changed: 35 additions & 27 deletions

File tree

  • Robot2018/src/org/usfirst/frc/team199/Robot2018/commands

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,39 @@ public PIDMove(double target, double[] point, DrivetrainInterface dt, SmartDashb
5858
if (Robot.dt != null) {
5959
requires(Robot.dt);
6060
}
61-
double kf = 1 / (dt.getCurrentMaxSpeed() * sd.getConst("Default PID Update Time", 0.05));
62-
63-
System.out.println("proposed p = " + (dt.getPIDMoveConstant() / dt.getCurrentMaxSpeed()));
64-
65-
moveController = new PIDController(sd.getConst("MovekP", 0.1), sd.getConst("MovekI", 0),
66-
sd.getConst("MovekD", 0), kf, avg, this) {
67-
/**
68-
* Move Velocity: V = sqrt(8TGd) / (R*m) where T = max torque of wheels G = gear
69-
* ratio d = distance remaining R = radius of wheels m = mass
70-
*/
71-
// @Override
72-
// protected double calculateFeedForward() {
73-
// double originalFF = super.calculateFeedForward();
74-
// double feedForwardConst = dt.getPIDMoveConstant();
75-
// double error = getError();
76-
// return (Math.signum(error) * feedForwardConst * Math.sqrt(Math.abs(error)) +
77-
// originalFF)
78-
// / dt.getCurrentMaxSpeed();
79-
// }
80-
81-
@Override
82-
protected double getContinuousError(double error) {
83-
return Math.signum(error) * Math.sqrt(Math.abs(super.getContinuousError(error)));
84-
}
85-
};
61+
62+
double maxSpeed = dt.getCurrentMaxSpeed();
63+
64+
System.out.println("proposed p = " + (dt.getPIDMoveConstant() / maxSpeed));
65+
66+
double r = Robot.getConst("DistancePidR", 3.0);
67+
double kP = r / Robot.rmap.getDrivetrainTimeConstant() / maxSpeed;
68+
double kI = 0;
69+
double kD = r / maxSpeed;
70+
double kF = 1 / (maxSpeed * sd.getConst("Default PID Update Time", 0.05)) / maxSpeed;
71+
72+
moveController = new PIDController(kP, kI, kD, kF, avg, this);
73+
// {
74+
/**
75+
* Move Velocity: V = sqrt(8TGd) / (R*m) where T = max torque of wheels G = gear
76+
* ratio d = distance remaining R = radius of wheels m = mass
77+
*/
78+
// @Override
79+
// protected double calculateFeedForward() {
80+
// double originalFF = super.calculateFeedForward();
81+
// double feedForwardConst = dt.getPIDMoveConstant();
82+
// double error = getError();
83+
// return (Math.signum(error) * feedForwardConst * Math.sqrt(Math.abs(error)) +
84+
// originalFF)
85+
// / dt.getCurrentMaxSpeed();
86+
// }
87+
88+
// @Override
89+
// protected double getContinuousError(double error) {
90+
// return Math.signum(error) *
91+
// Math.sqrt(Math.abs(super.getContinuousError(error)));
92+
// }
93+
// };
8694
sd.putData("Move PID", moveController);
8795
}
8896

@@ -144,7 +152,7 @@ public void initialize() {
144152
dt.resetDistEncs();
145153
moveController.disable();
146154
// input is in inches
147-
moveController.setInputRange(-Robot.getConst("Max High Speed", 204), Robot.getConst("Max High Speed", 204));
155+
moveController.setInputRange(-dt.getCurrentMaxSpeed(), dt.getCurrentMaxSpeed());
148156
// output in "motor units" (arcade and tank only accept values [-1, 1]
149157
moveController.setOutputRange(-1.0, 1.0);
150158
moveController.setContinuous(false);
@@ -153,7 +161,7 @@ public void initialize() {
153161
moveController.setSetpoint(target);
154162

155163
moveController.enable();
156-
dt.enableVelocityPIDs();
164+
// dt.enableVelocityPIDs();
157165
}
158166

159167
/**

0 commit comments

Comments
 (0)