From d328dcd7f37dd123985db3f361623c6216c7da93 Mon Sep 17 00:00:00 2001 From: Caleb Xavier Berger Date: Thu, 31 Jan 2019 19:10:30 -0500 Subject: [PATCH 1/6] First draft of pressure sensor class --- .../frc/robot/sensors/PressureSensor.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/frc/robot/sensors/PressureSensor.java diff --git a/src/main/java/frc/robot/sensors/PressureSensor.java b/src/main/java/frc/robot/sensors/PressureSensor.java new file mode 100644 index 0000000..0fb1f0f --- /dev/null +++ b/src/main/java/frc/robot/sensors/PressureSensor.java @@ -0,0 +1,20 @@ +package frc.robot.sensors; + +import edu.wpi.first.wpilibj.AnalogInput; + +public class PressureSensor { + private AnalogInput ai; + private static final double VCC = 5.0; + + private PressureSensor(int inputPin) { + this.ai = new AnalogInput(inputPin); + } + + private double getVoltageOut() { + return ai.getVoltage(); + } + + public double getPressure() { + return (250 * (this.getVoltageOut() / VCC)) - 25; + } +} From c4f70ef81dd49f211982aa3c563e30baea3a5f04 Mon Sep 17 00:00:00 2001 From: Caleb Xavier Berger Date: Thu, 31 Jan 2019 19:31:52 -0500 Subject: [PATCH 2/6] Add some doc comments --- src/main/java/frc/robot/sensors/PressureSensor.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/frc/robot/sensors/PressureSensor.java b/src/main/java/frc/robot/sensors/PressureSensor.java index 0fb1f0f..e05547f 100644 --- a/src/main/java/frc/robot/sensors/PressureSensor.java +++ b/src/main/java/frc/robot/sensors/PressureSensor.java @@ -4,6 +4,9 @@ public class PressureSensor { private AnalogInput ai; + /** + * The voltage into the sensor. + */ private static final double VCC = 5.0; private PressureSensor(int inputPin) { @@ -14,6 +17,12 @@ 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; } From eb0219c5e0d854dc8517f8c1e9f505d2e01f6046 Mon Sep 17 00:00:00 2001 From: Caleb Xavier Berger Date: Thu, 31 Jan 2019 19:32:21 -0500 Subject: [PATCH 3/6] Make constructor public This is consistent with last year's sensor classes - a subsystem will later instantiate the sensor for itself as a private field. In this case, where we are likely to only have one, it may make more sense to use the singleton pattern as in NavX and PDP. --- src/main/java/frc/robot/sensors/PressureSensor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/sensors/PressureSensor.java b/src/main/java/frc/robot/sensors/PressureSensor.java index e05547f..cd269be 100644 --- a/src/main/java/frc/robot/sensors/PressureSensor.java +++ b/src/main/java/frc/robot/sensors/PressureSensor.java @@ -9,7 +9,7 @@ public class PressureSensor { */ private static final double VCC = 5.0; - private PressureSensor(int inputPin) { + public PressureSensor(int inputPin) { this.ai = new AnalogInput(inputPin); } From 833ef431e1c30c9616d65ded8baaed23c33ad4c0 Mon Sep 17 00:00:00 2001 From: Caleb Berger Date: Sat, 2 Feb 2019 13:32:49 -0500 Subject: [PATCH 4/6] Make PressureSensor a singleton --- src/main/java/frc/robot/RobotMap.java | 2 ++ src/main/java/frc/robot/sensors/PressureSensor.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/frc/robot/RobotMap.java b/src/main/java/frc/robot/RobotMap.java index 831b606..223ba38 100644 --- a/src/main/java/frc/robot/RobotMap.java +++ b/src/main/java/frc/robot/RobotMap.java @@ -40,4 +40,6 @@ public class DRIVETRAIN { public static final int LEFT_JOY = 0; public static final int RIGHT_JOY = 1; + + public static final int PRESSURE_SENSOR_PORT = 0; } diff --git a/src/main/java/frc/robot/sensors/PressureSensor.java b/src/main/java/frc/robot/sensors/PressureSensor.java index cd269be..91cc922 100644 --- a/src/main/java/frc/robot/sensors/PressureSensor.java +++ b/src/main/java/frc/robot/sensors/PressureSensor.java @@ -1,8 +1,11 @@ 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. @@ -26,4 +29,8 @@ private double getVoltageOut() { public double getPressure() { return (250 * (this.getVoltageOut() / VCC)) - 25; } + + public static PressureSensor getInstance() { + return INSTANCE; + } } From a187e15da3f30afee6d51c4d8f2bf49caf441df0 Mon Sep 17 00:00:00 2001 From: Caleb Berger Date: Sat, 2 Feb 2019 14:21:01 -0500 Subject: [PATCH 5/6] Read out pressure to SmartDashboard --- src/main/java/frc/robot/Robot.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index f833e94..d2fcdd0 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -5,6 +5,7 @@ import edu.wpi.first.wpilibj.command.Scheduler; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import frc.robot.sensors.PressureSensor; import frc.robot.subsystems.Drivetrain; /** @@ -31,7 +32,7 @@ public void robotInit() { // chooser.addOption("My Auto", new MyAutoCommand()); SmartDashboard.putData("Auto mode", chooser); - String[] displays = new String[]{"Display Drivetrain data?", "Display navX data?"}; + String[] displays = new String[]{"Display Drivetrain data?", "Display navX data?", "Display pressure?"}; for (String display : displays) { if (!SmartDashboard.containsKey(display)) { SmartDashboard.putBoolean(display, false); @@ -50,6 +51,9 @@ public void robotInit() { */ @Override public void robotPeriodic() { + if (SmartDashboard.getBoolean("Display pressure?", false)) { + SmartDashboard.putNumber("Pnuematic pressure", PressureSensor.getInstance().getPressure()); + } } /** From 62692d67dafc0b127723a7357b4e51ea1349c67c Mon Sep 17 00:00:00 2001 From: Caleb Berger Date: Sat, 2 Feb 2019 14:24:40 -0500 Subject: [PATCH 6/6] Start the compressor in robotInit --- src/main/java/frc/robot/Robot.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index d2fcdd0..fd1e4ac 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -1,5 +1,6 @@ package frc.robot; +import edu.wpi.first.wpilibj.Compressor; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Scheduler; @@ -28,6 +29,8 @@ public void robotInit() { // HACK: Singletons don't like working unless they're grabbed before use. OI.getInstance(); Drivetrain.getInstance(); + // Start compressor + new Compressor().start(); // chooser.setDefaultOption("Default Auto", new ExampleCommand()); // chooser.addOption("My Auto", new MyAutoCommand()); SmartDashboard.putData("Auto mode", chooser);