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

Commit 305b8e3

Browse files
committed
added encoder rate getters and implemented maximum velocity when ending on the pid commands
1 parent 230af70 commit 305b8e3

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ protected void execute() {
7676
*/
7777
@Override
7878
protected boolean isFinished() {
79-
return moveController.onTarget();
79+
return moveController.onTarget()
80+
&& Math.abs(dt.getLeftEncRate()) <= Robot.getConst("Maximum Velocity When Stop", 1)
81+
&& Math.abs(dt.getRightEncRate()) <= Robot.getConst("Maximum Velocity When Stop", 1);
8082
}
8183

8284
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ protected void execute() {
8484
*/
8585
@Override
8686
protected boolean isFinished() {
87-
return turnController.onTarget();
87+
return turnController.onTarget()
88+
&& Math.abs(dt.getLeftEncRate()) <= Robot.getConst("Maximum Velocity When Stop", 1)
89+
&& Math.abs(dt.getRightEncRate()) <= Robot.getConst("Maximum Velocity When Stop", 1);
8890
}
8991

9092
/**

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class Drivetrain extends Subsystem implements DrivetrainInterface {
3434
private final WPI_VictorSPX dtRightSlave = RobotMap.dtRightSlave;
3535
private final Encoder leftEncDist = RobotMap.leftEncDist;
3636
private final Encoder rightEncDist = RobotMap.rightEncDist;
37+
private final Encoder leftEncRate = RobotMap.leftEncRate;
38+
private final Encoder rightEncRate = RobotMap.rightEncRate;
3739
private final PIDSourceAverage distEncAvg = RobotMap.distEncAvg;
3840
private final SpeedControllerGroup dtLeft = RobotMap.dtLeft;
3941
private final SpeedControllerGroup dtRight = RobotMap.dtRight;
@@ -49,6 +51,24 @@ public void initDefaultCommand() {
4951
setDefaultCommand(new TeleopDrive());
5052
}
5153

54+
/**
55+
* Returns the getRate() of the left encoder
56+
*
57+
* @return the rate of the left encoder
58+
*/
59+
public double getLeftEncRate() {
60+
return leftEncRate.getRate();
61+
}
62+
63+
/**
64+
* Returns the getRate() of the right encoder
65+
*
66+
* @return the rate of the right encoder
67+
*/
68+
public double getRightEncRate() {
69+
return rightEncRate.getRate();
70+
}
71+
5272
/**
5373
* Sets the left side of the drivetrain to use the talons' pids to run at the
5474
* specified speed.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ public interface DrivetrainInterface {
44

55
public void initDefaultCommand();
66

7+
/**
8+
* Returns the getRate() of the left encoder
9+
*
10+
* @return the rate of the left encoder
11+
*/
12+
public double getLeftEncRate();
13+
14+
/**
15+
* Returns the getRate() of the right encoder
16+
*
17+
* @return the rate of the right encoder
18+
*/
19+
public double getRightEncRate();
20+
721
/**
822
* Drives based on joystick input and SmartDashboard values
923
*/

0 commit comments

Comments
 (0)