-
Notifications
You must be signed in to change notification settings - Fork 1
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 #6 from BHSSFRC/feature/pressure-sensitive
Add pressure sensor
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,36 @@ | ||
package frc.robot.sensors; | ||
|
||
import edu.wpi.first.wpilibj.AnalogInput; | ||
import frc.robot.RobotMap; | ||
|
||
public class PressureSensor { | ||
private static final PressureSensor INSTANCE = new PressureSensor(RobotMap.PRESSURE_SENSOR_PORT); | ||
|
||
private AnalogInput ai; | ||
/** | ||
* The voltage into the sensor. | ||
*/ | ||
private static final double VCC = 5.0; | ||
|
||
public PressureSensor(int inputPin) { | ||
this.ai = new AnalogInput(inputPin); | ||
} | ||
|
||
private double getVoltageOut() { | ||
return ai.getVoltage(); | ||
} | ||
|
||
/** | ||
* Return the pressure, in PSI. Has a tolerance of 1.5% according to REV. | ||
* | ||
* @return Measured pressure, in PSI. | ||
* @see "http://www.revrobotics.com/content/docs/REV-11-1107-DS.pdf" | ||
*/ | ||
public double getPressure() { | ||
return (250 * (this.getVoltageOut() / VCC)) - 25; | ||
} | ||
|
||
public static PressureSensor getInstance() { | ||
return INSTANCE; | ||
} | ||
} |