[hal, wpilib] Incorporate pneumatic control type into wpilibc/j (#3728)

This commit is contained in:
Thad House
2021-11-23 20:32:02 -08:00
committed by GitHub
parent 9aba2b7583
commit b156db400d
35 changed files with 693 additions and 216 deletions

View File

@@ -43,7 +43,7 @@ public class Compressor implements Sendable, AutoCloseable {
allocatedCompressor = true;
m_module.setClosedLoopControl(true);
m_module.enableCompressorDigital();
HAL.report(tResourceType.kResourceType_Compressor, module + 1);
SendableRegistry.addLW(this, "Compressor", module);
@@ -82,9 +82,12 @@ public class Compressor implements Sendable, AutoCloseable {
* <p>Use the method in cases where you would like to manually stop and start the compressor for
* applications such as conserving battery or making sure that the compressor motor doesn't start
* during critical operations.
*
* @deprecated Use enableDigital() instead.
*/
@Deprecated(since = "2022", forRemoval = true)
public void start() {
setClosedLoopControl(true);
enableDigital();
}
/**
@@ -93,9 +96,12 @@ public class Compressor implements Sendable, AutoCloseable {
* <p>Use the method in cases where you would like to manually stop and start the compressor for
* applications such as conserving battery or making sure that the compressor motor doesn't start
* during critical operations.
*
* @deprecated Use disable() instead.
*/
@Deprecated(since = "2022", forRemoval = true)
public void stop() {
setClosedLoopControl(false);
disable();
}
/**
@@ -121,33 +127,56 @@ public class Compressor implements Sendable, AutoCloseable {
*
* @return current consumed by the compressor in amps
*/
public double getCompressorCurrent() {
public double getCurrent() {
return m_module.getCompressorCurrent();
}
/**
* Set the PCM in closed loop control mode.
*
* @param on if true sets the compressor to be in closed loop control mode (default)
*/
public void setClosedLoopControl(boolean on) {
m_module.setClosedLoopControl(on);
/** Disable the compressor. */
public void disable() {
m_module.disableCompressor();
}
/** Enable compressor closed loop control using digital input. */
public void enableDigital() {
m_module.enableCompressorDigital();
}
/**
* Gets the current operating mode of the PCM.
* Enable compressor closed loop control using analog input.
*
* <p>On CTRE PCM, this will enable digital control.
*
* @param minAnalogVoltage The minimum voltage to enable compressor
* @param maxAnalogVoltage The maximum voltage to disable compressor
*/
public void enableAnalog(double minAnalogVoltage, double maxAnalogVoltage) {
m_module.enableCompressorAnalog(minAnalogVoltage, maxAnalogVoltage);
}
/**
* Enable compressor closed loop control using hybrid input.
*
* <p>On CTRE PCM, this will enable digital control.
*
* @param minAnalogVoltage The minimum voltage to enable compressor
* @param maxAnalogVoltage The maximum voltage to disable compressor
*/
public void enableHybrid(double minAnalogVoltage, double maxAnalogVoltage) {
m_module.enableCompressorHybrid(minAnalogVoltage, maxAnalogVoltage);
}
/**
* Gets the current operating mode of the Compressor.
*
* @return true if compressor is operating on closed-loop mode
*/
public boolean getClosedLoopControl() {
return m_module.getClosedLoopControl();
public CompressorConfigType getConfigType() {
return m_module.getCompressorConfigType();
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Compressor");
builder.addBooleanProperty(
"Closed Loop Control", this::getClosedLoopControl, this::setClosedLoopControl);
builder.addBooleanProperty("Enabled", this::enabled, null);
builder.addBooleanProperty("Pressure switch", this::getPressureSwitchValue, null);
}

View File

@@ -0,0 +1,43 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.REVPHJNI;
public enum CompressorConfigType {
Disabled(REVPHJNI.COMPRESSOR_CONFIG_TYPE_DISABLED),
Digital(REVPHJNI.COMPRESSOR_CONFIG_TYPE_DIGITAL),
Analog(REVPHJNI.COMPRESSOR_CONFIG_TYPE_ANALOG),
Hybrid(REVPHJNI.COMPRESSOR_CONFIG_TYPE_HYBRID);
public final int value;
CompressorConfigType(int value) {
this.value = value;
}
/**
* Gets a type from an int value.
*
* @param value int value
* @return type
*/
public static CompressorConfigType fromValue(int value) {
switch (value) {
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_HYBRID:
return Hybrid;
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_ANALOG:
return Analog;
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_DIGITAL:
return Digital;
default:
return Disabled;
}
}
public int getValue() {
return value;
}
}

View File

@@ -92,13 +92,8 @@ public class PneumaticHub implements PneumaticsBase {
}
@Override
public void setClosedLoopControl(boolean enabled) {
REVPHJNI.setClosedLoopControl(m_handle, enabled);
}
@Override
public boolean getClosedLoopControl() {
return REVPHJNI.getClosedLoopControl(m_handle);
public CompressorConfigType getCompressorConfigType() {
return CompressorConfigType.fromValue(REVPHJNI.getCompressorConfig(m_handle));
}
@Override
@@ -200,4 +195,24 @@ public class PneumaticHub implements PneumaticsBase {
// TODO Get this working
return 0;
}
@Override
public void disableCompressor() {
REVPHJNI.setClosedLoopControlDisabled(m_handle);
}
@Override
public void enableCompressorDigital() {
REVPHJNI.setClosedLoopControlDigital(m_handle);
}
@Override
public void enableCompressorAnalog(double minAnalogVoltage, double maxAnalogVoltage) {
REVPHJNI.setClosedLoopControlAnalog(m_handle, minAnalogVoltage, maxAnalogVoltage);
}
@Override
public void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage) {
REVPHJNI.setClosedLoopControlHybrid(m_handle, minAnalogVoltage, maxAnalogVoltage);
}
}

View File

@@ -86,9 +86,15 @@ public interface PneumaticsBase extends AutoCloseable {
double getCompressorCurrent();
void setClosedLoopControl(boolean on);
void disableCompressor();
boolean getClosedLoopControl();
void enableCompressorDigital();
void enableCompressorAnalog(double minAnalogVoltage, double maxAnalogVoltage);
void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage);
CompressorConfigType getCompressorConfigType();
/**
* Check if a solenoid channel is valid.

View File

@@ -91,16 +91,6 @@ public class PneumaticsControlModule implements PneumaticsBase {
return CTREPCMJNI.getCompressor(m_handle);
}
@Override
public void setClosedLoopControl(boolean enabled) {
CTREPCMJNI.setClosedLoopControl(m_handle, enabled);
}
@Override
public boolean getClosedLoopControl() {
return CTREPCMJNI.getClosedLoopControl(m_handle);
}
@Override
public boolean getPressureSwitch() {
return CTREPCMJNI.getPressureSwitch(m_handle);
@@ -233,4 +223,31 @@ public class PneumaticsControlModule implements PneumaticsBase {
m_dataStore.m_compressorReserved = false;
}
}
@Override
public void disableCompressor() {
CTREPCMJNI.setClosedLoopControl(m_handle, false);
}
@Override
public void enableCompressorDigital() {
CTREPCMJNI.setClosedLoopControl(m_handle, true);
}
@Override
public void enableCompressorAnalog(double minAnalogVoltage, double maxAnalogVoltage) {
CTREPCMJNI.setClosedLoopControl(m_handle, false);
}
@Override
public void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage) {
CTREPCMJNI.setClosedLoopControl(m_handle, false);
}
@Override
public CompressorConfigType getCompressorConfigType() {
return CTREPCMJNI.getClosedLoopControl(m_handle)
? CompressorConfigType.Digital
: CompressorConfigType.Disabled;
}
}

View File

@@ -144,28 +144,28 @@ public class REVPHSim {
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerClosedLoopEnabledCallback(
public CallbackStore registerCompressorConfigTypeCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerClosedLoopEnabledCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelClosedLoopEnabledCallback);
int uid = REVPHDataJNI.registerCompressorConfigTypeCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorConfigTypeCallback);
}
/**
* Check whether the closed loop compressor control is active.
*
* @return true if active
* @return config type
*/
public boolean getClosedLoopEnabled() {
return REVPHDataJNI.getClosedLoopEnabled(m_index);
public int getCompressorConfigType() {
return REVPHDataJNI.getCompressorConfigType(m_index);
}
/**
* Turn on/off the closed loop control of the compressor.
*
* @param closedLoopEnabled whether the control loop is active
* @param compressorConfigType compressor config type
*/
public void setClosedLoopEnabled(boolean closedLoopEnabled) {
REVPHDataJNI.setClosedLoopEnabled(m_index, closedLoopEnabled);
public void setCompressorConfigType(int compressorConfigType) {
REVPHDataJNI.setCompressorConfigType(m_index, compressorConfigType);
}
/**