-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathSparkMaxChecker.java
56 lines (44 loc) · 1.84 KB
/
SparkMaxChecker.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
package com.team254.lib.drivers;
import com.revrobotics.CANSparkMax;
import com.revrobotics.ControlType;
import com.team254.frc2019.subsystems.Subsystem;
import java.util.ArrayList;
public class SparkMaxChecker extends MotorChecker<CANSparkMax> {
private static class StoredSparkConfiguration {
CANSparkMax leader = null;
}
protected ArrayList<StoredSparkConfiguration> mStoredConfigurations = new ArrayList<>();
public static boolean checkMotors(Subsystem subsystem,
ArrayList<MotorConfig<CANSparkMax>> motorsToCheck,
CheckerConfig checkerConfig) {
SparkMaxChecker checker = new SparkMaxChecker();
return checker.checkMotorsImpl(subsystem, motorsToCheck, checkerConfig);
}
@Override
protected void storeConfiguration() {
// record previous configuration for all talons
for (MotorConfig<CANSparkMax> config : mMotorsToCheck) {
LazySparkMax spark = (LazySparkMax) config.mMotor;
StoredSparkConfiguration configuration = new StoredSparkConfiguration();
configuration.leader = spark.getLeader();
mStoredConfigurations.add(configuration);
spark.restoreFactoryDefaults();
}
}
@Override
protected void restoreConfiguration() {
for (int i = 0; i < mMotorsToCheck.size(); ++i) {
if (mStoredConfigurations.get(i).leader != null) {
mMotorsToCheck.get(i).mMotor.follow(mStoredConfigurations.get(i).leader);
}
}
}
@Override
protected void setMotorOutput(CANSparkMax motor, double output) {
motor.getPIDController().setReference(output, ControlType.kDutyCycle);
}
@Override
protected double getMotorCurrent(CANSparkMax motor) {
return motor.getOutputCurrent();
}
}