-
Notifications
You must be signed in to change notification settings - Fork 35
/
CarriageCanifier.java
118 lines (99 loc) · 4.11 KB
/
CarriageCanifier.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
package com.team254.frc2019.subsystems;
import com.ctre.phoenix.CANifier;
import com.ctre.phoenix.CANifierStatusFrame;
import com.ctre.phoenix.CANifier.PinValues;
import com.team254.frc2019.Constants;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class CarriageCanifier extends Subsystem {
private static CarriageCanifier mInstance;
private CANifier mCanifierArm, mCanifierWrist;
private PeriodicInputs mPeriodicInputs;
private PeriodicOutputs mPeriodicOutputs;
private boolean mOutputsChanged;
private CarriageCanifier() {
mCanifierArm = new CANifier(Constants.kCanifierArmId);
mCanifierWrist = new CANifier(Constants.kCanifierWristId);
mCanifierArm.setStatusFramePeriod(CANifierStatusFrame.Status_2_General, 2, Constants.kLongCANTimeoutMs);
mCanifierWrist.setStatusFramePeriod(CANifierStatusFrame.Status_2_General, 2, Constants.kLongCANTimeoutMs);
mPeriodicInputs = new PeriodicInputs();
mPeriodicOutputs = new PeriodicOutputs();
// Force a first update.
mOutputsChanged = true;
}
public synchronized static CarriageCanifier getInstance() {
if (mInstance == null) {
mInstance = new CarriageCanifier();
}
return mInstance;
}
public synchronized void setLEDColor(double red, double green, double blue) {
if (red != mPeriodicOutputs.r_ ||
green != mPeriodicOutputs.g_ ||
blue != mPeriodicOutputs.b_) {
mPeriodicOutputs.r_ = red;
mPeriodicOutputs.g_ = green;
mPeriodicOutputs.b_ = blue;
mOutputsChanged = true;
}
}
@Override
public synchronized void readPeriodicInputs() {
mPeriodicInputs.has_ball_ = mCanifierWrist.getGeneralInput(CANifier.GeneralPin.LIMF);
PinValues pinValues = new PinValues();
mCanifierArm.getGeneralInputs(pinValues);
mPeriodicInputs.low_pressure_channel_ = pinValues.QUAD_IDX; // black wire, out1
mPeriodicInputs.high_pressure_channel_ = pinValues.SCL; // white wire, out2
}
@Override
public synchronized void writePeriodicOutputs() {
// A: Green
// B: Red
// C: Blue
if (mOutputsChanged) {
mCanifierWrist.setLEDOutput(mPeriodicOutputs.g_, CANifier.LEDChannel.LEDChannelA);
mCanifierWrist.setLEDOutput(mPeriodicOutputs.r_, CANifier.LEDChannel.LEDChannelB);
mCanifierWrist.setLEDOutput(mPeriodicOutputs.b_, CANifier.LEDChannel.LEDChannelC);
mOutputsChanged = false;
}
}
@Override
public boolean checkSystem() {
return false;
}
@Override
public synchronized void outputTelemetry() {
SmartDashboard.putBoolean("HasBall:", mPeriodicInputs.has_ball_);
SmartDashboard.putBoolean("LowPressureSensor:", mPeriodicInputs.low_pressure_channel_);
SmartDashboard.putBoolean("HighPressureSensor:", mPeriodicInputs.high_pressure_channel_);
}
public synchronized boolean hasBall() {
return mPeriodicInputs.has_ball_;
}
public synchronized boolean getLowPressureSensor() {
return mPeriodicInputs.low_pressure_channel_;
}
public synchronized boolean getHighPressureSensor() {
return mPeriodicInputs.high_pressure_channel_;
}
@Override
public void stop() {
mPeriodicOutputs = new PeriodicOutputs();
mOutputsChanged = true;
writePeriodicOutputs();
}
@Override
public synchronized void zeroSensors() {
mCanifierWrist.setQuadraturePosition(0, 0);
mCanifierArm.setQuadraturePosition(0, 0);
}
private static class PeriodicInputs {
public boolean has_ball_; // Q12 Banner photoelectric sensor on the end effector
public boolean low_pressure_channel_; // "lower" (more negative) threshold on the ProSense QPS digital pressure sensor
public boolean high_pressure_channel_; // "higher" (closer to 0) threshold on the ProSense QPS digital pressure sensor
}
private static class PeriodicOutputs {
public double r_;
public double g_;
public double b_;
}
}