/
Drive.java
292 lines (282 loc) · 9.66 KB
/
Drive.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot.subsystems;
import java.util.function.DoubleSupplier;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMax.FaultID;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
//import edu.wpi.first.math.filter.SlewRateLimiter;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
//import frc.robot.Constants.DriveConstants;
public class Drive extends SubsystemBase {
Shooter m_Shooter = new Shooter();
CANSparkMax frontRight = new CANSparkMax(2, MotorType.kBrushless);
CANSparkMax middleRight = new CANSparkMax(3, MotorType.kBrushless);
CANSparkMax backRight = new CANSparkMax(4, MotorType.kBrushless);
CANSparkMax frontLeft = new CANSparkMax(5, MotorType.kBrushless);
CANSparkMax middleLeft = new CANSparkMax(6, MotorType.kBrushless);
CANSparkMax backLeft = new CANSparkMax(7, MotorType.kBrushless);
/** Right Drive Group*/
MotorControllerGroup rightGroup = new MotorControllerGroup(
frontRight, middleRight, backRight
);
/*MotorControllerGroup rightGroup = new MotorControllerGroup(
new WPI_VictorSPX(DriveConstants.krightDriveMotorPort),
new WPI_VictorSPX(DriveConstants.krightBackDriveMotorPort));
/** Left Drive Group */
MotorControllerGroup leftGroup = new MotorControllerGroup(frontLeft, middleLeft, backLeft);
/*MotorControllerGroup leftGroup =
new MotorControllerGroup(
new WPI_VictorSPX(DriveConstants.kleftDriveMotorPort),
new WPI_VictorSPX(DriveConstants.kleftBackDriveMotorPort));
/** DriveTrain */
DifferentialDrive drive = new DifferentialDrive(rightGroup, leftGroup);
Timer autoTimer = new Timer();
boolean InvertMyDrive;
// SlewRateLimiter filter = new SlewRateLimiter(.5, 0.5, 0.5);
/** Creates a new Drive. */
public Drive() {
// restores to defaults
frontLeft.restoreFactoryDefaults();
middleLeft.restoreFactoryDefaults();
backLeft.restoreFactoryDefaults();
frontRight.restoreFactoryDefaults();
middleRight.restoreFactoryDefaults();
backRight.restoreFactoryDefaults();
// return motor voltage
frontLeft.getBusVoltage();
middleLeft.getBusVoltage();
backLeft.getBusVoltage();
frontRight.getBusVoltage();
middleRight.getBusVoltage();
backRight.getBusVoltage();
// return motor tempmpre
frontLeft.getMotorTemperature();
frontLeft.getMotorTemperature();
middleLeft.getMotorTemperature();
backLeft.getMotorTemperature();
frontRight.getMotorTemperature();
middleRight.getMotorTemperature();
backLeft.getMotorTemperature();
// return motor amp
frontLeft.getOutputCurrent();
middleLeft.getOutputCurrent();
backLeft.getOutputCurrent();
frontRight.getOutputCurrent();
middleRight.getOutputCurrent();
backRight.getOutputCurrent();
// inversions
rightGroup.setInverted(true);
leftGroup.setInverted(false);
if(InvertMyDrive = false)
{
rightGroup.setInverted(true);
leftGroup.setInverted(false);
}
else
{
rightGroup.setInverted(false);
leftGroup.setInverted(true);
}
// filter.calculate(0);
// setts currentlimit
frontLeft.setSmartCurrentLimit(60);
middleLeft.setSmartCurrentLimit(60);
backLeft.setSmartCurrentLimit(60);
frontRight.setSmartCurrentLimit(60);
middleRight.setSmartCurrentLimit(60);
backRight.setSmartCurrentLimit(60);
//burns flash
frontLeft.burnFlash();
middleLeft.burnFlash();
backLeft.burnFlash();
frontRight.burnFlash();
middleRight.burnFlash();
backRight.burnFlash();
//checks for faultsa
frontLeft.getFault(FaultID.kOvercurrent);
frontLeft.getFaults();
middleLeft.getFault(FaultID.kOvercurrent);
middleLeft.getFaults();
backLeft.getFault(FaultID.kOvercurrent);
backLeft.getFaults();
frontRight.getFault(FaultID.kOvercurrent);
frontRight.getFaults();
middleRight.getFault(FaultID.kOvercurrent);
middleRight.getFaults();
backRight.getFault(FaultID.kOvercurrent);
backRight.getFaults();
}
/** Arcade Drive
* @param fwd commanded forward movement
* @param rot commanded rotation
* @return arcadeDriveCommand
*/
public CommandBase arcadeDriveCommand(DoubleSupplier fwd, DoubleSupplier rot) {
return run(() -> drive.arcadeDrive((fwd.getAsDouble()), (rot.getAsDouble()))).withName("arcadedrive");
}
/** Auto Blue Alliance Station 1 */
public CommandBase LeftBlue(){
return runOnce(() -> autoTimer.reset()).withName("autoStarted")
.andThen(
//run(() -> m_Shooter.FwdShoot())
)
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(1)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(3)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, -0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(2)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop())
).withName("autoEnd");
}
/** Auto Blue Alliance Station 3 */
public CommandBase rightBlue(){
return runOnce(()-> autoTimer.reset())
.andThen(
//run(()-> m_Shooter.FwdShoot())
)
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(1)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(3)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, -0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(2)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop())
).withName("autoEnd");
}
/** Auto Red Alliance Station 1 */
public CommandBase leftRed(){
return runOnce(()-> autoTimer.reset())
.andThen(
//run(()-> m_Shooter.FwdShoot())
)
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(1)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(3)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, -0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(2)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop())
).withName("autoEnd");
}
/** Auto Red Alliance Station 3 */
public CommandBase rightRed(){
return runOnce(()-> autoTimer.reset())
.andThen(
//run(()-> m_Shooter.FwdShoot())
)
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(1)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(3)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, -0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0.5, 0)),
run(() -> autoTimer.hasElapsed(2)),
run(() -> autoTimer.stop()))
.andThen(
run(() -> autoTimer.start()),
run(() -> drive.arcadeDrive(0, 0.5)),
run(() -> autoTimer.hasElapsed(0.5)),
run(() -> autoTimer.stop())
).withName("autoEnd");
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
//public Object InvertMyDrive(boolean b) {
// return null;
// }
}