-
Notifications
You must be signed in to change notification settings - Fork 35
/
LazySparkMax.java
42 lines (35 loc) · 1.11 KB
/
LazySparkMax.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
package com.team254.lib.drivers;
import com.revrobotics.CANError;
import com.revrobotics.CANSparkMax;
import com.revrobotics.ControlType;
/**
* This class is a thin wrapper around the CANTalon that reduces CAN bus / CPU
* overhead by skipping duplicate set commands.
*/
public class LazySparkMax extends CANSparkMax {
protected double mLastSet = Double.NaN;
protected ControlType mLastControlType = null;
// Set if is a follower
protected CANSparkMax mLeader = null;
public LazySparkMax(int deviceNumber) {
super(deviceNumber, MotorType.kBrushless);
}
public CANSparkMax getLeader() {
return mLeader;
}
@Override
public CANError follow(final CANSparkMax leader) {
mLeader = leader;
return super.follow(leader);
}
/**
* wrapper method to mimic TalonSRX set method
*/
public void set(ControlType type, double setpoint) {
if (setpoint != mLastSet || type != mLastControlType) {
mLastSet = setpoint;
mLastControlType = type;
super.getPIDController().setReference(setpoint, type);
}
}
}