From 89a024a53a89d97537a8cf713d94e1527fe99972 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 5 Jul 2020 11:35:14 -0400 Subject: [PATCH] Add pressure sensor --- .../revrobotics/sensors/PressureSensor.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 hardware/revrobotics/src/main/java/io/github/frc5024/lib5k/hardware/revrobotics/sensors/PressureSensor.java diff --git a/hardware/revrobotics/src/main/java/io/github/frc5024/lib5k/hardware/revrobotics/sensors/PressureSensor.java b/hardware/revrobotics/src/main/java/io/github/frc5024/lib5k/hardware/revrobotics/sensors/PressureSensor.java new file mode 100644 index 000000000..d2ab3e31e --- /dev/null +++ b/hardware/revrobotics/src/main/java/io/github/frc5024/lib5k/hardware/revrobotics/sensors/PressureSensor.java @@ -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; + } + +} \ No newline at end of file