1818import edu .wpi .first .wpilibj .Encoder ;
1919import edu .wpi .first .wpilibj .PIDController ;
2020import edu .wpi .first .wpilibj .PIDOutput ;
21- import edu .wpi .first .wpilibj .PIDSource ;
22- import edu .wpi .first .wpilibj .PIDSourceType ;
2321import edu .wpi .first .wpilibj .SpeedControllerGroup ;
2422import edu .wpi .first .wpilibj .command .Subsystem ;
2523import edu .wpi .first .wpilibj .drive .DifferentialDrive ;
2624
27- public class Drivetrain extends Subsystem implements PIDOutput , PIDSource , DrivetrainInterface {
25+ public class Drivetrain extends Subsystem implements PIDOutput , DrivetrainInterface {
2826 // Put methods for controlling this subsystem
2927 // here. Call these from Commands.
3028
@@ -34,24 +32,31 @@ public class Drivetrain extends Subsystem implements PIDOutput, PIDSource, Drive
3432 private final SpeedControllerGroup dtRight = RobotMap .dtRight ;
3533 private final DifferentialDrive robotDrive = RobotMap .robotDrive ;
3634 private final PIDController turnController = RobotMap .turnController ;
37- private final PIDController moveController = RobotMap .moveController ;
35+ // private final PIDController moveController = RobotMap.moveController;
36+ private final PIDController moveLeftController = RobotMap .moveLeftController ;
37+ private final PIDController moveRightController = RobotMap .moveRightController ;
3838
3939 private final AHRS ahrs = RobotMap .ahrs ;
4040 private final AnalogGyro dtGyro = RobotMap .dtGyro ;
4141 private final DoubleSolenoid dtGear = RobotMap .dtGear ;
4242
43- private double pidOut = 0 ;
43+ private double anglePidOut = 0 ;
44+ private double leftPidOut = 0 ;
45+ private double rightPidOut = 0 ;
4446
4547 public void initDefaultCommand () {
4648 setDefaultCommand (new TeleopDrive ());
4749 }
48-
50+
4951 /**
5052 * Updates the PIDControllers' PIDConstants based on SmartDashboard values
5153 */
5254 public void updatePidConstants () {
5355 turnController .setPID (Robot .getConst ("TurnkP" , 1 ), Robot .getConst ("TurnkI" , 0 ), Robot .getConst ("TurnkD" , 0 ));
54- moveController .setPID (Robot .getConst ("MovekP" , 1 ), Robot .getConst ("MovekI" , 0 ), Robot .getConst ("MovekD" , 0 ));
56+ moveLeftController .setPID (Robot .getConst ("MoveLeftkP" , 1 ), Robot .getConst ("MoveLeftkI" , 0 ),
57+ Robot .getConst ("MoveLeftkD" , 0 ));
58+ moveRightController .setPID (Robot .getConst ("MoveRightkP" , 1 ), Robot .getConst ("MoveRightkI" , 0 ),
59+ Robot .getConst ("MoveRightkD" , 0 ));
5560 }
5661
5762 /**
@@ -235,24 +240,36 @@ public void setTurnSetpoint(double set) {
235240 * Enable the movePID PIDController used for moving
236241 */
237242 public void enableMovePid () {
238- moveController .enable ();
243+ moveLeftController .enable ();
244+ moveRightController .enable ();
239245 }
240246
241247 /**
242248 * Disables the movePID PIDController used for moving
243249 */
244250 public void disableMovePid () {
245- moveController .disable ();
251+ moveLeftController .disable ();
252+ moveRightController .enable ();
246253 }
247254
248255 /**
249- * Sets the setPoint of the movePID PIDController
256+ * Sets the setPoint of the moveLeftPID PIDController
250257 *
251258 * @param set
252259 * The value to set the setPoint at
253260 */
254- public void setMoveSetpoint (double set ) {
255- moveController .setSetpoint (set );
261+ public void setMoveSetpointLeft (double set ) {
262+ moveLeftController .setSetpoint (set );
263+ }
264+
265+ /**
266+ * Sets the setPoint of the moveRightPID PIDController
267+ *
268+ * @param set
269+ * The value to set the setPoint at
270+ */
271+ public void setMoveSetpointRight (double set ) {
272+ moveRightController .setSetpoint (set );
256273 }
257274
258275 /**
@@ -280,15 +297,45 @@ public void setDistancePerPulseRight(double dist) {
280297 *
281298 * @return The value that is written by PIDControllers
282299 */
283- public double getPidOut () {
284- return pidOut ;
300+ public double getAnglePidOut () {
301+ return anglePidOut ;
302+ }
303+
304+ /**
305+ * Returns the value that leftdrive should be set to according to PIDControllers
306+ *
307+ * @return The value that is written by PIDControllers
308+ */
309+ public double getLeftPidOut () {
310+ return leftPidOut ;
311+ }
312+
313+ /**
314+ * Returns the value that rightdrive should be set to according to PIDControllers
315+ *
316+ * @return The value that is written by PIDControllers
317+ */
318+ public double getRightPidOut () {
319+ return rightPidOut ;
285320 }
286321
287- @ Override
288- public double pidGet () {
289- return average (leftEnc .getDistance (), rightEnc .getDistance ());
322+ /**
323+ * Returns the distance that the left encoder reads
324+ *
325+ * @return How much the left encoder has travelled
326+ */
327+ public double getLeftEnc () {
328+ return leftEnc .getDistance ();
290329 }
291330
331+ /**
332+ * Returns the distance that the right encoder reads
333+ *
334+ * @return How much the right encoder has travelled
335+ */
336+ public double getRightEnc () {
337+ return rightEnc .getDistance ();
338+ }
292339 // public boolean onTargetLeft() {
293340 // return moveLeftController.onTarget();
294341 // }
@@ -298,7 +345,27 @@ public double pidGet() {
298345
299346 @ Override
300347 public void pidWrite (double output ) {
301- pidOut = output ;
348+ anglePidOut = output ;
349+ }
350+
351+ /**
352+ * Sets the leftPidOutput
353+ *
354+ * @param output
355+ * The value to set the output to
356+ */
357+ public void pidLeftWrite (double output ) {
358+ leftPidOut = output ;
359+ }
360+
361+ /**
362+ * Sets the rightPidOutput
363+ *
364+ * @param output
365+ * The value to set the output to
366+ */
367+ public void pidRightWrite (double output ) {
368+ rightPidOut = output ;
302369 }
303370
304371 /**
@@ -324,20 +391,13 @@ public boolean onTurnTarg() {
324391 }
325392
326393 /**
327- * Returns whether the moveController PIDController senses that it's on target
394+ * Returns whether the moveLeftController and moveRightController PIDController
395+ * sense that their on target
328396 *
329- * @return Whether the moveController PIDController is on target
397+ * @return Whether the moveController PIDControllers are on target
330398 */
331399 public boolean onDriveTarg () {
332- return moveController .onTarget ();
400+ return moveLeftController . onTarget () && moveRightController .onTarget ();
333401 }
334402
335- @ Override
336- public void setPIDSourceType (PIDSourceType pidSource ) {
337- }
338-
339- @ Override
340- public PIDSourceType getPIDSourceType () {
341- return PIDSourceType .kDisplacement ;
342- }
343403}
0 commit comments