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

Commit 5269634

Browse files
committed
PID input/output range changes
set proper kF constants for move and turn PIDs as well fixed inputRange and outputRange for each PID controller (move, turn, leftV, rightV) setMaxOutput of robotDrive to the robot's max speed (in inches)
1 parent d1186b8 commit 5269634

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ public RobotMap() {
111111
configSPX(dtLeftSlave);
112112
dtLeft = new SpeedControllerGroup(dtLeftMaster, dtLeftSlave);
113113

114-
leftVelocityController = new VelocityPIDController(Robot.getConst("MoveLeftkP", 1),
115-
Robot.getConst("MoveLeftkI", 0), Robot.getConst("MoveLeftkD", 0), 1 / Robot.getConst("MaxSpeed", 17),
116-
leftEncRate, dtLeft);
114+
leftVelocityController = new VelocityPIDController(Robot.getConst("VelocityLeftkP", 1),
115+
Robot.getConst("VelocityLeftkI", 0), Robot.getConst("VelocityLeftkD", 0),
116+
1 / Robot.getConst("MaxSpeed", 204), leftEncRate, dtLeft);
117117
leftVelocityController.enable();
118-
leftVelocityController.setInputRange(0, Double.MAX_VALUE);
118+
leftVelocityController.setInputRange(-Robot.getConst("Max Speed", 204), Robot.getConst("Max Speed", 204));
119119
leftVelocityController.setOutputRange(-1.0, 1.0);
120120
leftVelocityController.setContinuous(false);
121-
leftVelocityController.setAbsoluteTolerance(Robot.getConst("MoveToleranceLeft", 2));
121+
leftVelocityController.setAbsoluteTolerance(Robot.getConst("VelocityToleranceLeft", 2));
122122

123123
rightEncPort1 = new DigitalInput(getPort("1RightEnc", 2));
124124
rightEncPort2 = new DigitalInput(getPort("2RightEnc", 3));
@@ -132,16 +132,17 @@ public RobotMap() {
132132
configSPX(dtRightSlave);
133133
dtRight = new SpeedControllerGroup(dtRightMaster, dtRightSlave);
134134

135-
rightVelocityController = new VelocityPIDController(Robot.getConst("MoveRightkP", 1),
136-
Robot.getConst("MoveRightkI", 0), Robot.getConst("MoveRightkD", 0), 1 / Robot.getConst("MaxSpeed", 17),
137-
rightEncRate, dtRight);
135+
rightVelocityController = new VelocityPIDController(Robot.getConst("VelocityRightkP", 1),
136+
Robot.getConst("VelocityRightkI", 0), Robot.getConst("VelocityRightkD", 0),
137+
1 / Robot.getConst("MaxSpeed", 204), rightEncRate, dtRight);
138138
rightVelocityController.enable();
139-
rightVelocityController.setInputRange(0, Double.MAX_VALUE);
139+
rightVelocityController.setInputRange(-Robot.getConst("Max Speed", 204), Robot.getConst("Max Speed", 204));
140140
rightVelocityController.setOutputRange(-1.0, 1.0);
141141
rightVelocityController.setContinuous(false);
142-
rightVelocityController.setAbsoluteTolerance(Robot.getConst("MoveToleranceRight", 2));
142+
rightVelocityController.setAbsoluteTolerance(Robot.getConst("VelocityToleranceRight", 2));
143143

144144
robotDrive = new DifferentialDrive(leftVelocityController, rightVelocityController);
145+
robotDrive.setMaxOutput(Robot.getConst("Max Speed", 204));
145146

146147
distEncAvg = new PIDSourceAverage(leftEncDist, rightEncDist);
147148
fancyGyro = new AHRS(SerialPort.Port.kMXP);

Robot2018/src/org/usfirst/frc/team199/Robot2018/autonomous/VelocityPIDController.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public VelocityPIDController(double kp, double ki, double kd, double kf, PIDSour
3737
* Sets the target speed
3838
*
3939
* @param speed
40-
* the target speed [-1, 1]
40+
* the target speed in inches/second
4141
*/
4242
@Override
4343
public void pidWrite(double output) {
@@ -48,7 +48,7 @@ public void pidWrite(double output) {
4848
* Sets the target speed
4949
*
5050
* @param speed
51-
* the target speed [-1, 1]
51+
* the target speed in inches/second
5252
*/
5353
@Override
5454
public void set(double speed) {
@@ -68,24 +68,29 @@ public double get() {
6868
}
6969

7070
/**
71+
* Invert this side of the DT (flip forwards and backwards).
7172
*
72-
* */
73+
* @param isInverted
74+
* invert this side of the DT or not
75+
*/
7376
@Override
7477
public void setInverted(boolean isInverted) {
7578
out.setInverted(isInverted);
7679
}
7780

7881
/**
82+
* Get whether or not this side of the DT is inverted.
7983
*
80-
* */
84+
* @return is this side of the DT inverted or not
85+
*/
8186
@Override
8287
public boolean getInverted() {
8388
return out.getInverted();
8489
}
8590

8691
/**
87-
*
88-
* */
92+
* Set the output to zero.
93+
*/
8994
@Override
9095
public void stopMotor() {
9196
out.stopMotor();

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ public PIDMove(double targ, DrivetrainInterface dt, PIDSourceAverage avg) {
2323
target = targ;
2424
this.dt = dt;
2525
requires(Robot.dt);
26+
double kf = 1 / (Robot.getConst("Max Speed", 204) * Robot.getConst("Default PID Update Time", 0.05));
2627
moveController = new PIDController(Robot.getConst("MovekP", 1), Robot.getConst("MovekI", 0),
27-
Robot.getConst("MovekD", 0), avg, this);
28+
Robot.getConst("MovekD", 0), kf, avg, this);
2829
}
2930

3031
// Called just before this Command runs the first time
3132
@Override
3233
public void initialize() {
3334
dt.resetDistEncs();
34-
moveController.setInputRange(0, Double.MAX_VALUE);
35+
// input is in inches
36+
moveController.setInputRange(-Double.MAX_VALUE, Double.MAX_VALUE);
37+
// output in "motor units" (arcade and tank only accept values [-1, 1]
3538
moveController.setOutputRange(-1.0, 1.0);
3639
moveController.setContinuous(false);
3740
moveController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 2));

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,23 @@ public PIDTurn(double targ, DrivetrainInterface dt, AHRS ahrs) {
2424
target = targ;
2525
this.dt = dt;
2626
requires(Robot.dt);
27+
// calculates the maximum turning speed in degrees/sec based on the max linear
28+
// speed in inches/s and the distance (inches) between sides of the DT
29+
double maxTurnSpeed = Robot.getConst("Max Speed", 204) * 360
30+
/ (Math.PI * Robot.getConst("Distance Between Wheels", 26.25));
31+
double kf = 1 / (maxTurnSpeed * Robot.getConst("Default PID Update Time", 0.05));
2732
turnController = new PIDController(Robot.getConst("TurnkP", 1), Robot.getConst("TurnkI", 0),
28-
Robot.getConst("TurnkD", 0), ahrs, this);
33+
Robot.getConst("TurnkD", 0), kf, ahrs, this);
2934
}
3035

3136
// Called just before this Command runs the first time
3237
@Override
3338
protected void initialize() {
3439
dt.resetAHRS();
3540
turnController.disable();
41+
// input is in degrees
3642
turnController.setInputRange(-180, 180);
43+
// output in "motor units" (arcade and tank only accept values [-1, 1]
3744
turnController.setOutputRange(-1.0, 1.0);
3845
turnController.setContinuous();
3946
turnController.setAbsoluteTolerance(Robot.getConst("TurnTolerance", 1));

0 commit comments

Comments
 (0)