Skip to content

Commit

Permalink
Cleanup Pneumatic Hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
rachitkakkar committed Nov 14, 2023
1 parent 8d029a6 commit 767c158
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
40 changes: 27 additions & 13 deletions src/main/java/org/lasarobotics/hardware/Compressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package org.lasarobotics.hardware;

import org.littletonrobotics.junction.AutoLog;
import org.littletonrobotics.junction.Logger;

import edu.wpi.first.wpilibj.PneumaticsModuleType;

public class Compressor implements LoggableHardware {
public class Compressor implements LoggableHardware, AutoCloseable {
/** Compressor ID */
public static class ID {
public final String name;
Expand All @@ -28,6 +27,8 @@ public ID(String name, PneumaticsModuleType moduleType) {

@AutoLog
public static class CompressorInputs {
boolean isEnabled = false;
boolean digitalPressure = false;
double analogPressure = 0.0;
}

Expand All @@ -49,18 +50,14 @@ public Compressor(Compressor.ID id, int module) {
}

/**
* Create a Solenoid object with built-in logging
* @param id Solenoid ID
* Create a Compressor object with built-in logging
* @param id Compressor ID
*/
public Compressor(Compressor.ID id) {
this.m_id = id;
this.m_compressor = new edu.wpi.first.wpilibj.Compressor(m_id.moduleType);
}

private void logOutputs(boolean value) {
Logger.recordOutput(m_id.name + VALUE_LOG_ENTRY, value);
}

/**
* If supported by the device, returns the pressure (in PSI) read by the analog pressure sensor
* (on channel 0).
Expand All @@ -74,10 +71,30 @@ public double getPressure() {
return m_compressor.getPressure();
}

/**
* Returns the state of the pressure switch.
*
* @return True if pressure switch indicates that the system is not full, otherwise false.
*/
public boolean getPressureSwitchValue() {
return m_compressor.getPressureSwitchValue();
}

/**
* Returns whether the compressor is active or not.
*
* @return true if the compressor is on - otherwise false.
*/
public boolean isEnabled() {
return m_compressor.isEnabled();
}

/**
* Update sensor input readings
*/
private void updateInputs() {
m_inputs.isEnabled = isEnabled();
m_inputs.digitalPressure = getPressureSwitchValue();
m_inputs.analogPressure = getPressure();
}

Expand Down Expand Up @@ -105,7 +122,6 @@ public CompressorInputsAutoLogged getInputs() {
*/
public void enableDigital() {
m_compressor.enableDigital();
logOutputs(m_compressor.isEnabled());
}

/**
Expand All @@ -124,7 +140,6 @@ public void enableDigital() {
*/
public void enableAnalog(double minPressure, double maxPressure) {
m_compressor.enableAnalog(minPressure, maxPressure);
logOutputs(m_compressor.isEnabled());
}

/**
Expand All @@ -141,17 +156,16 @@ public void enableAnalog(double minPressure, double maxPressure) {
* reaches this value or the pressure switch is disconnected or indicates that the system is
* full.
*/
public void enableHybrid(double minPressure, double maxPressure) {
public void enableHybrid(double minPressure, double maxPressure) {
m_compressor.enableHybrid(minPressure, maxPressure);
logOutputs(m_compressor.isEnabled());
}

/** Disable the compressor. */
public void disable() {
m_compressor.disable();
logOutputs(m_compressor.isEnabled());
}

@Override
public void close() {
m_compressor.close();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/lasarobotics/hardware/DoubleSolenoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import edu.wpi.first.wpilibj.PneumaticsModuleType;

public class DoubleSolenoid implements LoggableHardware {
public class DoubleSolenoid implements LoggableHardware, AutoCloseable {
/** DoubleSolenoid ID */
public static class ID {
public final String name;
Expand Down Expand Up @@ -79,6 +79,7 @@ public void set(edu.wpi.first.wpilibj.DoubleSolenoid.Value value) {
logOutputs(value.name());
}

@Override
public void close() {
m_doubleSolenoid.close();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/lasarobotics/hardware/Solenoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import edu.wpi.first.wpilibj.PneumaticsModuleType;

public class Solenoid implements LoggableHardware {
public class Solenoid implements LoggableHardware, AutoCloseable {
/** Solenoid ID */
public static class ID {
public final String name;
Expand Down Expand Up @@ -87,6 +87,7 @@ public void toggle() {
logOutputs(m_solenoid.get());
}

@Override
public void close() {
m_solenoid.close();
}
Expand Down

0 comments on commit 767c158

Please sign in to comment.