-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from frc5024/rev_preassuer
Add REV pressure sensor
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...cs/src/main/java/io/github/frc5024/lib5k/hardware/revrobotics/sensors/PressureSensor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.github.frc5024.lib5k.hardware.revrobotics.sensors; | ||
|
||
import edu.wpi.first.hal.SimDevice; | ||
import edu.wpi.first.hal.SimDouble; | ||
import edu.wpi.first.wpilibj.AnalogInput; | ||
|
||
/** | ||
* A wrapper for the Rev Robotics Analog Pressure Sensor | ||
* | ||
* https://www.revrobotics.com/rev-11-1107/ | ||
*/ | ||
public class PressureSensor extends AnalogInput { | ||
|
||
// Simulation | ||
private SimDevice simDevice; | ||
private SimDouble simPreassure; | ||
|
||
/** | ||
* Construct a pressure sensor. | ||
* | ||
* @param channel The channel number of the sensor. 0-3 are on-board 4-7 are on | ||
* the MXP port. | ||
*/ | ||
public PressureSensor(int channel) { | ||
super(channel); | ||
|
||
// Set up simulation | ||
simDevice = SimDevice.create("RevPressureSensor", channel); | ||
if (simDevice != null) { | ||
simPreassure = simDevice.createDouble("PSI", false, 60.0); | ||
} | ||
} | ||
|
||
/** | ||
* Get the sensed air pressure in PSI | ||
* | ||
* @return PSI | ||
*/ | ||
public double getPressurePSI() { | ||
|
||
// Simulation reading | ||
if (simDevice != null) { | ||
return simPreassure.get(); | ||
} | ||
|
||
// Real reading | ||
return 250.0 * getVoltage() / 5.0 - 25.0; | ||
} | ||
|
||
} |