Skip to content

Commit 5f50f6b

Browse files
committed
Start v4.11.0: It was deemed too messy to modify MonitorCompresssor to support REV PH along with CTRE PCM. Writing a new generic class for both would take more time and testing than we wanted to spend at this time. So new class MonitorCompressorPH was created to handle REV PH.
1 parent ea5aeb3 commit 5f50f6b

6 files changed

Lines changed: 203 additions & 7 deletions

File tree

User Dictionary.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ drivebase
4343
watchdogs
4444
wpilib
4545
odometry
46-
pneumatic
46+
pneumaticpneumatics

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LibraryVersion=4.10.0
1+
LibraryVersion=4.11.0
22
archivesGroup = com.github.ORF-4450
33
archivesBaseName = RobotLib
44
jsonFileName = robotlib.json

src/main/java/Team4450/Lib/LibraryVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class LibraryVersion
4747
* of the Jitpack compile when requested and will be automatically made available via JitPack.
4848
*/
4949

50-
public static final String version = "4.10.0 (01.31.2025) WPILib=" + WPILibVersion.Version;
50+
public static final String version = "4.11.0 (02.18.2025) WPILib=" + WPILibVersion.Version;
5151

5252
// Private constructor means this class can't be instantiated.
5353
private LibraryVersion()

src/main/java/Team4450/Lib/MonitorCompressor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import edu.wpi.first.wpilibj.Compressor;
1313

1414
/**
15-
* Compressor monitoring task.
15+
* Compressor monitoring task. For CTRE PCM only.
1616
* Runs as a separate thread from our MyRobot class. Runs until our
1717
* program is terminated from the RoboRio. Displays compressor on/off
1818
* LED on DS. Can also monitor an air pressure sensor and report the
1919
* pressure to the DS. Assumes compressor is plugged into the first
2020
* PCM, device id 0.
21-
* Note: for 2022 only CTRE PCM is supported at this time. REV Pneumatic
22-
* Hub will be added later.
21+
2322
*/
2423

2524
public class MonitorCompressor extends Thread implements Sendable
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
2+
package Team4450.Lib;
3+
4+
import edu.wpi.first.util.sendable.Sendable;
5+
import edu.wpi.first.util.sendable.SendableBuilder;
6+
import edu.wpi.first.util.sendable.SendableRegistry;
7+
import edu.wpi.first.wpilibj.DriverStation;
8+
import edu.wpi.first.wpilibj.PneumaticsModuleType;
9+
import edu.wpi.first.wpilibj.Timer;
10+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
11+
import edu.wpi.first.wpilibj.Compressor;
12+
13+
/**
14+
* Compressor monitoring task. For REV Pneumatics Hub only.
15+
* Runs as a separate thread from our MyRobot class. Runs until our
16+
* program is terminated from the RoboRio. Displays compressor on/off
17+
* LED on DS. Can also monitor an air pressure sensor and report the
18+
* pressure to the DS. Assumes compressor is plugged into the first
19+
* PH, device id 1.
20+
*/
21+
22+
public class MonitorCompressorPH extends Thread implements Sendable
23+
{
24+
private final Compressor compressor;
25+
private double delay = 2.0, lowPressureThreshold = 0.0, correction = 0.0;
26+
private boolean lowPressureAlarm = false, ledState = false, compressorState;
27+
private int loopCount;
28+
29+
/**
30+
* Static reference to the internal MonitorCompressorPH instance created by
31+
* getInstance() calls on this class. Must call a getInstance() before using.
32+
*/
33+
public static MonitorCompressorPH INSTANCE;
34+
35+
// Create single instance of this class and return that single instance to any callers.
36+
// This is the singleton class model. You don't use new, you use getInstance. After that
37+
// you can use the returned instance reference in a variable in your code or use the
38+
// INSTANCE variable above to access the members of this class. Assumes robot will have
39+
// only one compressor.
40+
41+
/**
42+
* Get a reference to global MonitorCompressorPH Thread object. Monitors compressor on/off
43+
* and sets DS LED named Compressor accordingly. Also monitors pressure on analog I/O port.
44+
* Pressure is displayed on DS gauge called AirPressure. Can also do an alarm LED called
45+
* LowPressure if you set the low pressure threshold.
46+
* @param compressor Reference to a Compressor object of type REVPH.
47+
* @return Reference to global MonitorCompressorPH object.
48+
*/
49+
50+
public static MonitorCompressorPH getInstance(Compressor compressor)
51+
{
52+
Util.consoleLog();
53+
54+
if (INSTANCE == null) INSTANCE = new MonitorCompressorPH(compressor);
55+
56+
return INSTANCE;
57+
}
58+
59+
private MonitorCompressorPH(Compressor compressor)
60+
{
61+
Util.consoleLog();
62+
63+
this.compressor = compressor;
64+
65+
this.setName("MonitorCompressorPH");
66+
67+
SmartDashboard.putBoolean("LowPressure", false);
68+
69+
SendableRegistry.addLW(this, "MonitorCompressorPH", 1);
70+
}
71+
72+
/**
73+
* If monitoring pressure, return the current pressure from port 0.
74+
* @return Current pressure in PSI.
75+
*/
76+
public double getPressure()
77+
{
78+
Double pressure = compressor.getPressure();
79+
80+
if (Double.isNaN(pressure)) pressure = 0.0;
81+
82+
return pressure + correction;
83+
}
84+
85+
/**
86+
* Return the pressure sensor current voltage on port 0.
87+
* @return Sensor voltage.
88+
*/
89+
public double getVoltage()
90+
{
91+
return compressor.getAnalogVoltage();
92+
}
93+
94+
/**
95+
* Set the delay of the sampling loop. Longer delay works when only monitoring compressor on/off.
96+
* Shorter delay may be appropriate when monitoring pressure.
97+
* @param seconds Delay in second between samples. Minimum .5 second. Defaults to 2 seconds.
98+
*/
99+
public void setDelay(double seconds)
100+
{
101+
if (delay < 0.5) delay = 0.5;
102+
103+
delay = seconds;
104+
}
105+
106+
/**
107+
* Set correction value to be added to the pressure to make it
108+
* match the gauge.
109+
* @param psi Correction value in PSI.
110+
*/
111+
public void setCorrection(double psi)
112+
{
113+
correction = psi;
114+
}
115+
116+
/**
117+
* Enable low pressure alarm LED on DS by setting pressure at which
118+
* alarm will trigger. Expects LED to be named LowPressure.
119+
* @param psi The low pressure in PSI.
120+
*/
121+
public void SetLowPressureAlarm(double psi)
122+
{
123+
if (psi < 0) psi = 0;
124+
125+
lowPressureThreshold = psi;
126+
}
127+
128+
/**
129+
* Start monitoring. Called by Thread.start().
130+
*/
131+
public void run()
132+
{
133+
boolean saveState = false;
134+
double pressure;
135+
136+
try
137+
{
138+
Util.consoleLog();
139+
140+
while (!isInterrupted())
141+
{
142+
compressorState = compressor.isEnabled();
143+
144+
if (compressorState != saveState)
145+
{
146+
saveState = compressorState;
147+
SmartDashboard.putBoolean("Compressor", saveState);
148+
Util.consoleLog("compressor on=%b", saveState);
149+
}
150+
151+
pressure = getPressure();
152+
153+
154+
SmartDashboard.putNumber("AirPressure", (int) pressure);
155+
156+
if (lowPressureThreshold > 0)
157+
{
158+
if (pressure <= lowPressureThreshold)
159+
{
160+
if (!lowPressureAlarm) DriverStation.reportError(String.format("low air pressure alarm: %dpsi", (int) pressure), false);
161+
162+
lowPressureAlarm = true;
163+
}
164+
else
165+
{
166+
if (lowPressureAlarm) DriverStation.reportError("low air pressure alarm cleared", false);
167+
168+
lowPressureAlarm = false;
169+
}
170+
171+
if (lowPressureAlarm)
172+
ledState = !ledState;
173+
else
174+
ledState = false;
175+
176+
SmartDashboard.putBoolean("LowPressure", ledState);
177+
178+
loopCount++;
179+
}
180+
181+
Timer.delay(delay);
182+
}
183+
}
184+
catch (Throwable e) {Util.logException(e);}
185+
}
186+
187+
@Override
188+
public void initSendable( SendableBuilder builder )
189+
{
190+
builder.setSmartDashboardType("MonitorCompressorPH");
191+
builder.addBooleanProperty(".controllable", () -> false, null);
192+
builder.addDoubleProperty("PSI", this::getPressure, null);
193+
builder.addBooleanProperty("On", () -> compressorState, null);
194+
builder.addBooleanProperty("Alarm", () -> lowPressureAlarm, null);
195+
builder.addDoubleProperty("Loop", () -> loopCount, null);
196+
}
197+
}

src/main/resources/overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<body>
44
<h1 style="font-family: arial">FRC Team 4450 Robot Control Program Utility Library</h1>
55
<p style="font-family: arial">Provides utility classes and functions for FRC robot control programs.</p>
6-
<p style="font-family: arial">Version 4.10.0 (January 31 2025)</p>
6+
<p style="font-family: arial">Version 4.11.0 (February 18 2025)</p>
77
</body>

0 commit comments

Comments
 (0)