-
Notifications
You must be signed in to change notification settings - Fork 35
/
Arm.java
80 lines (66 loc) · 2.8 KB
/
Arm.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
package com.team254.frc2019.subsystems;
import com.ctre.phoenix.motorcontrol.RemoteFeedbackDevice;
import com.ctre.phoenix.motorcontrol.RemoteSensorSource;
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
import com.team254.frc2019.Constants;
import com.team254.lib.drivers.MotorChecker;
import com.team254.lib.drivers.TalonSRXChecker;
import com.team254.lib.drivers.TalonSRXUtil;
import java.util.ArrayList;
public class Arm extends ServoMotorSubsystem {
private static Arm mInstance;
public synchronized static Arm getInstance() {
if (mInstance == null) {
mInstance = new Arm(Constants.kArmConstants);
}
return mInstance;
}
private Arm(final ServoMotorSubsystemConstants constants) {
super(constants);
TalonSRXUtil.checkError(mMaster.configRemoteFeedbackFilter(Constants.kCanifierArmId,
RemoteSensorSource.CANifier_Quadrature,
0, Constants.kLongCANTimeoutMs),
"Could not set arm encoder!!!: ");
TalonSRXUtil.checkError(mMaster.configSelectedFeedbackSensor(
RemoteFeedbackDevice.RemoteSensor0, 0, Constants.kLongCANTimeoutMs),
"Could not detect arm encoder: ");
}
// Syntactic sugar.
public synchronized double getAngle() {
return getPosition();
}
public synchronized void setSetpointThrust(double units) {
mMaster.configMotionCruiseVelocity(Constants.kArmCruiseVelocityForThrust);
super.setSetpointMotionMagic(units);
}
@Override
public synchronized void setSetpointMotionMagic(double units) {
mMaster.configMotionCruiseVelocity(Constants.kArmConstants.kCruiseVelocity);
super.setSetpointMotionMagic(units);
}
@Override
public synchronized void setSetpointMotionMagic(double units, double feedforward_v) {
mMaster.configMotionCruiseVelocity(Constants.kArmConstants.kCruiseVelocity);
super.setSetpointMotionMagic(units, feedforward_v);
}
@Override
public boolean checkSystem() {
return TalonSRXChecker.checkMotors(this,
new ArrayList<MotorChecker.MotorConfig<TalonSRX>>() {
private static final long serialVersionUID = 3069865439600365807L;
{
add(new MotorChecker.MotorConfig<>("master", mMaster));
}
}, new MotorChecker.CheckerConfig() {
{
mRunOutputPercentage = 0.5;
mRunTimeSec = 0.5;
mCurrentFloor = 0.1;
mRPMFloor = 90;
mCurrentEpsilon = 2.0;
mRPMEpsilon = 200;
mRPMSupplier = () -> mMaster.getSelectedSensorVelocity();
}
});
}
}