Skip to content

Commit 8ff7bd5

Browse files
authored
Merge pull request #17 from frc5024/rev_preassuer
Add REV pressure sensor
2 parents 3ecd657 + 89a024a commit 8ff7bd5

File tree

1 file changed

+50
-0
lines changed
  • hardware/revrobotics/src/main/java/io/github/frc5024/lib5k/hardware/revrobotics/sensors

1 file changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.github.frc5024.lib5k.hardware.revrobotics.sensors;
2+
3+
import edu.wpi.first.hal.SimDevice;
4+
import edu.wpi.first.hal.SimDouble;
5+
import edu.wpi.first.wpilibj.AnalogInput;
6+
7+
/**
8+
* A wrapper for the Rev Robotics Analog Pressure Sensor
9+
*
10+
* https://www.revrobotics.com/rev-11-1107/
11+
*/
12+
public class PressureSensor extends AnalogInput {
13+
14+
// Simulation
15+
private SimDevice simDevice;
16+
private SimDouble simPreassure;
17+
18+
/**
19+
* Construct a pressure sensor.
20+
*
21+
* @param channel The channel number of the sensor. 0-3 are on-board 4-7 are on
22+
* the MXP port.
23+
*/
24+
public PressureSensor(int channel) {
25+
super(channel);
26+
27+
// Set up simulation
28+
simDevice = SimDevice.create("RevPressureSensor", channel);
29+
if (simDevice != null) {
30+
simPreassure = simDevice.createDouble("PSI", false, 60.0);
31+
}
32+
}
33+
34+
/**
35+
* Get the sensed air pressure in PSI
36+
*
37+
* @return PSI
38+
*/
39+
public double getPressurePSI() {
40+
41+
// Simulation reading
42+
if (simDevice != null) {
43+
return simPreassure.get();
44+
}
45+
46+
// Real reading
47+
return 250.0 * getVoltage() / 5.0 - 25.0;
48+
}
49+
50+
}

0 commit comments

Comments
 (0)