|
7 | 7 |
|
8 | 8 | package org.usfirst.frc.team199.Robot2018; |
9 | 9 |
|
| 10 | +import org.usfirst.frc.team199.Robot2018.autonomous.PIDSourceAverage; |
| 11 | +import org.usfirst.frc.team199.Robot2018.autonomous.VelocityPIDController; |
| 12 | + |
10 | 13 | import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX; |
11 | 14 | import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX; |
12 | 15 | import com.kauailabs.navx.frc.AHRS; |
13 | 16 |
|
14 | 17 | import edu.wpi.first.wpilibj.AnalogGyro; |
| 18 | +import edu.wpi.first.wpilibj.DigitalInput; |
| 19 | +import edu.wpi.first.wpilibj.DigitalSource; |
15 | 20 | import edu.wpi.first.wpilibj.DoubleSolenoid; |
16 | 21 | import edu.wpi.first.wpilibj.Encoder; |
17 | | -import edu.wpi.first.wpilibj.PIDController; |
| 22 | +import edu.wpi.first.wpilibj.PIDSourceType; |
18 | 23 | import edu.wpi.first.wpilibj.SerialPort; |
19 | 24 | import edu.wpi.first.wpilibj.SpeedControllerGroup; |
20 | 25 | import edu.wpi.first.wpilibj.drive.DifferentialDrive; |
|
27 | 32 | * floating around. |
28 | 33 | */ |
29 | 34 | public class RobotMap { |
30 | | - // For example to map the left and right motors, you could define the |
31 | | - // following variables to use with your drivetrain subsystem. |
32 | | - // public static int leftMotor = 1; |
33 | | - // public static int rightMotor = 2; |
34 | | - |
35 | | - // If you are using multiple modules, make sure to define both the port |
36 | | - // number and the module. For example you with a rangefinder: |
37 | | - // public static int rangefinderPort = 1; |
38 | | - // public static int rangefinderModule = 1; |
39 | | - |
40 | | - public static Encoder leftEnc; |
| 35 | + public static DigitalSource leftEncPort1; |
| 36 | + public static DigitalSource leftEncPort2; |
| 37 | + public static Encoder leftEncDist; |
| 38 | + public static Encoder leftEncRate; |
41 | 39 | public static WPI_TalonSRX dtLeftDrive; |
42 | 40 | public static WPI_VictorSPX dtLeftSlave; |
43 | 41 | public static SpeedControllerGroup dtLeft; |
| 42 | + public static VelocityPIDController leftVelocityController; |
44 | 43 |
|
45 | | - public static Encoder rightEnc; |
| 44 | + public static DigitalSource rightEncPort1; |
| 45 | + public static DigitalSource rightEncPort2; |
| 46 | + public static Encoder rightEncDist; |
| 47 | + public static Encoder rightEncRate; |
46 | 48 | public static WPI_TalonSRX dtRightDrive; |
47 | 49 | public static WPI_VictorSPX dtRightSlave; |
48 | 50 | public static SpeedControllerGroup dtRight; |
| 51 | + public static VelocityPIDController rightVelocityController; |
| 52 | + |
49 | 53 | public static DifferentialDrive robotDrive; |
50 | | - public static PIDController turnController; |
51 | | - // public static PIDController moveController; |
52 | | - public static PIDController moveLeftController; |
53 | | - public static PIDController moveRightController; |
| 54 | + public static PIDSourceAverage distEncAvg; |
54 | 55 |
|
55 | | - public static AHRS ahrs; |
| 56 | + public static AHRS fancyGyro; |
56 | 57 | public static AnalogGyro dtGyro; |
57 | 58 | public static DoubleSolenoid dtGear; |
58 | 59 |
|
@@ -88,61 +89,52 @@ private void configSPX(WPI_VictorSPX mc) { |
88 | 89 |
|
89 | 90 | public RobotMap() { |
90 | 91 |
|
91 | | - leftEnc = new Encoder(getPort("1LeftEnc", 0), getPort("2LeftEnc", 1)); |
| 92 | + leftEncPort1 = new DigitalInput(getPort("1LeftEnc", 0)); |
| 93 | + leftEncPort2 = new DigitalInput(getPort("2LeftEnc", 1)); |
| 94 | + leftEncDist = new Encoder(leftEncPort1, leftEncPort2); |
| 95 | + leftEncDist.setPIDSourceType(PIDSourceType.kDisplacement); |
| 96 | + leftEncRate = new Encoder(leftEncPort1, leftEncPort2); |
| 97 | + leftEncRate.setPIDSourceType(PIDSourceType.kRate); |
92 | 98 | dtLeftDrive = new WPI_TalonSRX(getPort("LeftTalonSRXDrive", 0)); |
93 | 99 | configSRX(dtLeftDrive); |
94 | 100 | dtLeftSlave = new WPI_VictorSPX(getPort("LeftTalonSPXSlave", 1)); |
95 | 101 | configSPX(dtLeftSlave); |
96 | 102 | dtLeft = new SpeedControllerGroup(dtLeftDrive, dtLeftSlave); |
97 | 103 |
|
98 | | - rightEnc = new Encoder(getPort("1RightEnc", 2), getPort("2RightEnc", 3)); |
| 104 | + leftVelocityController = new VelocityPIDController(Robot.getConst("MoveLeftkP", 1), |
| 105 | + Robot.getConst("MoveLeftkI", 0), Robot.getConst("MoveLeftkD", 0), leftEncRate, dtLeft); |
| 106 | + leftVelocityController.enable(); |
| 107 | + leftVelocityController.setInputRange(0, Double.MAX_VALUE); |
| 108 | + leftVelocityController.setOutputRange(-1.0, 1.0); |
| 109 | + leftVelocityController.setContinuous(false); |
| 110 | + leftVelocityController.setAbsoluteTolerance(Robot.getConst("ConstMoveToleranceLeft", 2)); |
| 111 | + |
| 112 | + rightEncPort1 = new DigitalInput(getPort("1RightEnc", 2)); |
| 113 | + rightEncPort2 = new DigitalInput(getPort("2RightEnc", 3)); |
| 114 | + rightEncDist = new Encoder(leftEncPort1, leftEncPort2); |
| 115 | + rightEncDist.setPIDSourceType(PIDSourceType.kDisplacement); |
| 116 | + rightEncRate = new Encoder(leftEncPort1, leftEncPort2); |
| 117 | + rightEncRate.setPIDSourceType(PIDSourceType.kRate); |
99 | 118 | dtRightDrive = new WPI_TalonSRX(getPort("RightTalonSRXDrive", 2)); |
100 | 119 | configSRX(dtRightDrive); |
101 | 120 | dtRightSlave = new WPI_VictorSPX(getPort("RightTalonSPXSlave", 3)); |
102 | 121 | configSPX(dtRightSlave); |
103 | 122 | dtRight = new SpeedControllerGroup(dtRightDrive, dtRightSlave); |
104 | 123 |
|
105 | | - robotDrive = new DifferentialDrive(dtLeft, dtRight); |
106 | | - |
107 | | - // moveController = new PIDController(Robot.getConst("MovekP", 1), |
108 | | - // Robot.getConst("MovekI", 0), |
109 | | - // Robot.getConst("MovekD", 0), Robot.dt, Robot.dt); |
110 | | - // moveController.disable(); |
111 | | - // moveController.setInputRange(0, Double.MAX_VALUE); |
112 | | - // moveController.setOutputRange(-1.0, 1.0); |
113 | | - // moveController.setContinuous(false); |
114 | | - // moveController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 2)); |
115 | | - |
116 | | - |
117 | | - ahrs = new AHRS(SerialPort.Port.kMXP); |
| 124 | + rightVelocityController = new VelocityPIDController(Robot.getConst("ConstMoveRightkP", 1), |
| 125 | + Robot.getConst("ConstMoveRightkI", 0), Robot.getConst("ConstMoveRightkD", 0), rightEncRate, dtRight); |
| 126 | + rightVelocityController.enable(); |
| 127 | + rightVelocityController.setInputRange(0, Double.MAX_VALUE); |
| 128 | + rightVelocityController.setOutputRange(-1.0, 1.0); |
| 129 | + rightVelocityController.setContinuous(false); |
| 130 | + rightVelocityController.setAbsoluteTolerance(Robot.getConst("ConstMoveToleranceRight", 2)); |
| 131 | + |
| 132 | + robotDrive = new DifferentialDrive(leftVelocityController, rightVelocityController); |
| 133 | + |
| 134 | + distEncAvg = new PIDSourceAverage(leftEncDist, rightEncDist); |
| 135 | + fancyGyro = new AHRS(SerialPort.Port.kMXP); |
118 | 136 | dtGyro = new AnalogGyro(getPort("Gyro", 0)); |
119 | 137 | dtGear = new DoubleSolenoid(getPort("1dtGearSolenoid", 0), getPort("2dtGearSolenoid", 1)); |
120 | | - |
121 | | - } |
122 | | - |
123 | | - public void initPIDControllers() { |
124 | | - turnController = new PIDController(Robot.getConst("TurnkP", 1), Robot.getConst("TurnkI", 0), |
125 | | - Robot.getConst("TurnkD", 0), ahrs, Robot.dt); |
126 | | - turnController.disable(); |
127 | | - turnController.setInputRange(-180, 180); |
128 | | - turnController.setOutputRange(-1.0, 1.0); |
129 | | - turnController.setContinuous(); |
130 | | - turnController.setAbsoluteTolerance(Robot.getConst("TurnTolerance", 1)); |
131 | | - |
132 | | - moveLeftController = new PIDController(Robot.getConst("MoveLeftkP", 1), Robot.getConst("MoveLeftkI", 0), |
133 | | - Robot.getConst("MoveLeftkD", 0), Robot.ld, Robot.ld); |
134 | | - moveLeftController.disable(); |
135 | | - moveLeftController.setInputRange(0, Double.MAX_VALUE); |
136 | | - moveLeftController.setOutputRange(-1.0, 1.0); |
137 | | - moveLeftController.setContinuous(false); |
138 | | - moveLeftController.setAbsoluteTolerance(Robot.getConst("ConstMoveToleranceLeft", 2)); |
139 | | - moveRightController = new PIDController(Robot.getConst("ConstMoveRightkP", 1), |
140 | | - Robot.getConst("ConstMoveRightkI", 0), Robot.getConst("ConstMoveRightkD", 0), Robot.rd, Robot.rd); |
141 | | - moveRightController.disable(); |
142 | | - moveRightController.setInputRange(0, Double.MAX_VALUE); |
143 | | - moveRightController.setOutputRange(-1.0, 1.0); |
144 | | - moveRightController.setContinuous(false); |
145 | | - moveRightController.setAbsoluteTolerance(Robot.getConst("ConstMoveToleranceRight", 2)); |
146 | 138 | } |
147 | 139 |
|
148 | 140 | /** |
|
0 commit comments