[wpilib] Add Pneumatics sim classes (#4033)

This commit is contained in:
Starlight220
2022-05-22 17:21:40 +03:00
committed by GitHub
parent 046c2c8972
commit 816aa4e465
15 changed files with 946 additions and 546 deletions

View File

@@ -6,17 +6,15 @@ package edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.hal.simulation.CTREPCMDataJNI;
import edu.wpi.first.hal.simulation.NotifyCallback;
import edu.wpi.first.wpilibj.PneumaticsBase;
import edu.wpi.first.wpilibj.PneumaticsControlModule;
import edu.wpi.first.wpilibj.SensorUtil;
/** Class to control a simulated Pneumatic Control Module (PCM). */
@SuppressWarnings("AbbreviationAsWordInName")
public class CTREPCMSim {
private final int m_index;
public class CTREPCMSim extends PneumaticsBaseSim {
/** Constructs for the default PCM. */
public CTREPCMSim() {
m_index = SensorUtil.getDefaultCTREPCMModule();
super(SensorUtil.getDefaultCTREPCMModule());
}
/**
@@ -25,129 +23,16 @@ public class CTREPCMSim {
* @param module module number
*/
public CTREPCMSim(int module) {
m_index = module;
super(module);
}
/**
* Constructs from a Compressor object.
* Constructs from a PneumaticsControlModule object.
*
* @param module PCM module to simulate
*/
public CTREPCMSim(PneumaticsBase module) {
m_index = module.getModuleNumber();
}
/**
* Register a callback to be run when the solenoid output on a channel changes.
*
* @param channel the channel to monitor
* @param callback the callback
* @param initialNotify should the callback be run with the initial value
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerSolenoidOutputCallback(
int channel, NotifyCallback callback, boolean initialNotify) {
int uid =
CTREPCMDataJNI.registerSolenoidOutputCallback(m_index, channel, callback, initialNotify);
return new CallbackStore(m_index, channel, uid, CTREPCMDataJNI::cancelSolenoidOutputCallback);
}
/**
* Check the solenoid output on a specific channel.
*
* @param channel the channel to check
* @return the solenoid output
*/
public boolean getSolenoidOutput(int channel) {
return CTREPCMDataJNI.getSolenoidOutput(m_index, channel);
}
/**
* Change the solenoid output on a specific channel.
*
* @param channel the channel to check
* @param solenoidOutput the new solenoid output
*/
public void setSolenoidOutput(int channel, boolean solenoidOutput) {
CTREPCMDataJNI.setSolenoidOutput(m_index, channel, solenoidOutput);
}
/**
* Register a callback to be run when the compressor is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelInitializedCallback);
}
/**
* Check whether the compressor has been initialized.
*
* @return true if initialized
*/
public boolean getInitialized() {
return CTREPCMDataJNI.getInitialized(m_index);
}
/**
* Define whether the compressor has been initialized.
*
* @param initialized whether the compressor is initialized
*/
public void setInitialized(boolean initialized) {
CTREPCMDataJNI.setInitialized(m_index, initialized);
}
/**
* Register a callback to be run when the compressor activates.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerCompressorOnCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerCompressorOnCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelCompressorOnCallback);
}
/**
* Check if the compressor is on.
*
* @return true if the compressor is active
*/
public boolean getCompressorOn() {
return CTREPCMDataJNI.getCompressorOn(m_index);
}
/**
* Set whether the compressor is active.
*
* @param compressorOn the new value
*/
public void setCompressorOn(boolean compressorOn) {
CTREPCMDataJNI.setCompressorOn(m_index, compressorOn);
}
/**
* Register a callback to be run whenever the closed loop state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the initial value
* @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(
NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerClosedLoopEnabledCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelClosedLoopEnabledCallback);
public CTREPCMSim(PneumaticsControlModule module) {
super(module);
}
/**
@@ -169,70 +54,105 @@ public class CTREPCMSim {
}
/**
* Register a callback to be run whenever the pressure switch value changes.
* Register a callback to be run whenever the closed loop state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the initial value
* @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(
NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerClosedLoopEnabledCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelClosedLoopEnabledCallback);
}
@Override
public boolean getInitialized() {
return CTREPCMDataJNI.getInitialized(m_index);
}
@Override
public void setInitialized(boolean initialized) {
CTREPCMDataJNI.setInitialized(m_index, initialized);
}
@Override
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelInitializedCallback);
}
@Override
public boolean getCompressorOn() {
return CTREPCMDataJNI.getCompressorOn(m_index);
}
@Override
public void setCompressorOn(boolean compressorOn) {
CTREPCMDataJNI.setCompressorOn(m_index, compressorOn);
}
@Override
public CallbackStore registerCompressorOnCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerCompressorOnCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelCompressorOnCallback);
}
@Override
public boolean getSolenoidOutput(int channel) {
return CTREPCMDataJNI.getSolenoidOutput(m_index, channel);
}
@Override
public void setSolenoidOutput(int channel, boolean solenoidOutput) {
CTREPCMDataJNI.setSolenoidOutput(m_index, channel, solenoidOutput);
}
@Override
public CallbackStore registerSolenoidOutputCallback(
int channel, NotifyCallback callback, boolean initialNotify) {
int uid =
CTREPCMDataJNI.registerSolenoidOutputCallback(m_index, channel, callback, initialNotify);
return new CallbackStore(m_index, channel, uid, CTREPCMDataJNI::cancelSolenoidOutputCallback);
}
@Override
public boolean getPressureSwitch() {
return CTREPCMDataJNI.getPressureSwitch(m_index);
}
@Override
public void setPressureSwitch(boolean pressureSwitch) {
CTREPCMDataJNI.setPressureSwitch(m_index, pressureSwitch);
}
@Override
public CallbackStore registerPressureSwitchCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerPressureSwitchCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelPressureSwitchCallback);
}
/**
* Check the value of the pressure switch.
*
* @return the pressure switch value
*/
public boolean getPressureSwitch() {
return CTREPCMDataJNI.getPressureSwitch(m_index);
@Override
public double getCompressorCurrent() {
return CTREPCMDataJNI.getCompressorCurrent(m_index);
}
/**
* Set the value of the pressure switch.
*
* @param pressureSwitch the new value
*/
public void setPressureSwitch(boolean pressureSwitch) {
CTREPCMDataJNI.setPressureSwitch(m_index, pressureSwitch);
@Override
public void setCompressorCurrent(double compressorCurrent) {
CTREPCMDataJNI.setCompressorCurrent(m_index, compressorCurrent);
}
/**
* Register a callback to be run whenever the compressor current changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
@Override
public CallbackStore registerCompressorCurrentCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = CTREPCMDataJNI.registerCompressorCurrentCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, CTREPCMDataJNI::cancelCompressorCurrentCallback);
}
/**
* Read the compressor current.
*
* @return the current of the compressor connected to this module
*/
public double getCompressorCurrent() {
return CTREPCMDataJNI.getCompressorCurrent(m_index);
}
/**
* Set the compressor current.
*
* @param compressorCurrent the new compressor current
*/
public void setCompressorCurrent(double compressorCurrent) {
CTREPCMDataJNI.setCompressorCurrent(m_index, compressorCurrent);
}
/** Reset all simulation data for this object. */
@Override
public void resetData() {
CTREPCMDataJNI.resetData(m_index);
}

View File

@@ -0,0 +1,88 @@
// 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.simulation;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsBase;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
/** Class to control a simulated {@link edu.wpi.first.wpilibj.DoubleSolenoid}. */
public class DoubleSolenoidSim {
private final PneumaticsBaseSim m_module;
private final int m_fwd;
private final int m_rev;
/**
* Constructs for a solenoid on the given pneumatics module.
*
* @param moduleSim the PCM the solenoid is connected to.
* @param fwd the forward solenoid channel.
* @param rev the reverse solenoid channel.
*/
public DoubleSolenoidSim(PneumaticsBaseSim moduleSim, int fwd, int rev) {
m_module = moduleSim;
m_fwd = fwd;
m_rev = rev;
}
/**
* Constructs for a solenoid on a pneumatics module of the given type and ID.
*
* @param module the CAN ID of the pneumatics module the solenoid is connected to.
* @param moduleType the module type (PH or PCM)
* @param fwd the forward solenoid channel.
* @param rev the reverse solenoid channel.
*/
public DoubleSolenoidSim(int module, PneumaticsModuleType moduleType, int fwd, int rev) {
this(PneumaticsBaseSim.getForType(module, moduleType), fwd, rev);
}
/**
* Constructs for a solenoid on a pneumatics module of the given type and default ID.
*
* @param moduleType the module type (PH or PCM)
* @param fwd the forward solenoid channel.
* @param rev the reverse solenoid channel.
*/
public DoubleSolenoidSim(PneumaticsModuleType moduleType, int fwd, int rev) {
this(PneumaticsBase.getDefaultForType(moduleType), moduleType, fwd, rev);
}
/**
* Check the value of the double solenoid output.
*
* @return the output value of the double solenoid.
*/
public DoubleSolenoid.Value get() {
boolean fwdState = m_module.getSolenoidOutput(m_fwd);
boolean revState = m_module.getSolenoidOutput(m_rev);
if (fwdState && !revState) {
return DoubleSolenoid.Value.kForward;
} else if (!fwdState && revState) {
return DoubleSolenoid.Value.kReverse;
} else {
return DoubleSolenoid.Value.kOff;
}
}
/**
* Set the value of the double solenoid output.
*
* @param value The value to set (Off, Forward, Reverse)
*/
public void set(final DoubleSolenoid.Value value) {
m_module.setSolenoidOutput(m_fwd, value == DoubleSolenoid.Value.kForward);
m_module.setSolenoidOutput(m_rev, value == DoubleSolenoid.Value.kReverse);
}
/**
* Get the wrapped {@link PneumaticsBaseSim} object.
*
* @return the wrapped {@link PneumaticsBaseSim} object.
*/
public PneumaticsBaseSim getModuleSim() {
return m_module;
}
}

View File

@@ -0,0 +1,171 @@
// 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.simulation;
import edu.wpi.first.hal.simulation.NotifyCallback;
import edu.wpi.first.wpilibj.PneumaticsBase;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
/** Common base class for pneumatics module simulation classes. */
public abstract class PneumaticsBaseSim {
protected final int m_index;
/**
* Get a module sim for a specific type.
*
* @param module the module number / CAN ID.
* @param type the module type.
* @return the module object.
*/
public static PneumaticsBaseSim getForType(int module, PneumaticsModuleType type) {
switch (type) {
case CTREPCM:
return new CTREPCMSim(module);
case REVPH:
return new REVPHSim(module);
default:
throw new IllegalArgumentException("Unknown module type");
}
}
protected PneumaticsBaseSim(int index) {
m_index = index;
}
protected PneumaticsBaseSim(PneumaticsBase module) {
this(module.getModuleNumber());
}
/**
* Check whether the PCM/PH has been initialized.
*
* @return true if initialized
*/
public abstract boolean getInitialized();
/**
* Define whether the PCM/PH has been initialized.
*
* @param initialized true for initialized
*/
public abstract void setInitialized(boolean initialized);
/**
* Register a callback to be run when the PCM/PH is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public abstract CallbackStore registerInitializedCallback(
NotifyCallback callback, boolean initialNotify);
/**
* Check if the compressor is on.
*
* @return true if the compressor is active
*/
public abstract boolean getCompressorOn();
/**
* Set whether the compressor is active.
*
* @param compressorOn the new value
*/
public abstract void setCompressorOn(boolean compressorOn);
/**
* Register a callback to be run when the compressor activates.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public abstract CallbackStore registerCompressorOnCallback(
NotifyCallback callback, boolean initialNotify);
/**
* Check the solenoid output on a specific channel.
*
* @param channel the channel to check
* @return the solenoid output
*/
public abstract boolean getSolenoidOutput(int channel);
/**
* Change the solenoid output on a specific channel.
*
* @param channel the channel to check
* @param solenoidOutput the new solenoid output
*/
public abstract void setSolenoidOutput(int channel, boolean solenoidOutput);
/**
* Register a callback to be run when the solenoid output on a channel changes.
*
* @param channel the channel to monitor
* @param callback the callback
* @param initialNotify should the callback be run with the initial value
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public abstract CallbackStore registerSolenoidOutputCallback(
int channel, NotifyCallback callback, boolean initialNotify);
/**
* Check the value of the pressure switch.
*
* @return the pressure switch value
*/
public abstract boolean getPressureSwitch();
/**
* Set the value of the pressure switch.
*
* @param pressureSwitch the new value
*/
public abstract void setPressureSwitch(boolean pressureSwitch);
/**
* Register a callback to be run whenever the pressure switch value changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the initial value
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public abstract CallbackStore registerPressureSwitchCallback(
NotifyCallback callback, boolean initialNotify);
/**
* Read the compressor current.
*
* @return the current of the compressor connected to this module
*/
public abstract double getCompressorCurrent();
/**
* Set the compressor current.
*
* @param compressorCurrent the new compressor current
*/
public abstract void setCompressorCurrent(double compressorCurrent);
/**
* Register a callback to be run whenever the compressor current changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public abstract CallbackStore registerCompressorCurrentCallback(
NotifyCallback callback, boolean initialNotify);
/** Reset all simulation data for this object. */
public abstract void resetData();
}

View File

@@ -6,17 +6,15 @@ package edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.hal.simulation.NotifyCallback;
import edu.wpi.first.hal.simulation.REVPHDataJNI;
import edu.wpi.first.wpilibj.PneumaticsBase;
import edu.wpi.first.wpilibj.PneumaticHub;
import edu.wpi.first.wpilibj.SensorUtil;
/** Class to control a simulated PneumaticHub (PH). */
@SuppressWarnings("AbbreviationAsWordInName")
public class REVPHSim {
private final int m_index;
public class REVPHSim extends PneumaticsBaseSim {
/** Constructs for the default PH. */
public REVPHSim() {
m_index = SensorUtil.getDefaultREVPHModule();
super(SensorUtil.getDefaultREVPHModule());
}
/**
@@ -25,129 +23,16 @@ public class REVPHSim {
* @param module module number
*/
public REVPHSim(int module) {
m_index = module;
super(module);
}
/**
* Constructs from a Compressor object.
* Constructs from a PneumaticHum object.
*
* @param module PCM module to simulate
*/
public REVPHSim(PneumaticsBase module) {
m_index = module.getModuleNumber();
}
/**
* Register a callback to be run when the solenoid output on a channel changes.
*
* @param channel the channel to monitor
* @param callback the callback
* @param initialNotify should the callback be run with the initial value
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerSolenoidOutputCallback(
int channel, NotifyCallback callback, boolean initialNotify) {
int uid =
REVPHDataJNI.registerSolenoidOutputCallback(m_index, channel, callback, initialNotify);
return new CallbackStore(m_index, channel, uid, REVPHDataJNI::cancelSolenoidOutputCallback);
}
/**
* Check the solenoid output on a specific channel.
*
* @param channel the channel to check
* @return the solenoid output
*/
public boolean getSolenoidOutput(int channel) {
return REVPHDataJNI.getSolenoidOutput(m_index, channel);
}
/**
* Change the solenoid output on a specific channel.
*
* @param channel the channel to check
* @param solenoidOutput the new solenoid output
*/
public void setSolenoidOutput(int channel, boolean solenoidOutput) {
REVPHDataJNI.setSolenoidOutput(m_index, channel, solenoidOutput);
}
/**
* Register a callback to be run when the compressor is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelInitializedCallback);
}
/**
* Check whether the compressor has been initialized.
*
* @return true if initialized
*/
public boolean getInitialized() {
return REVPHDataJNI.getInitialized(m_index);
}
/**
* Define whether the compressor has been initialized.
*
* @param initialized whether the compressor is initialized
*/
public void setInitialized(boolean initialized) {
REVPHDataJNI.setInitialized(m_index, initialized);
}
/**
* Register a callback to be run when the compressor activates.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerCompressorOnCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerCompressorOnCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorOnCallback);
}
/**
* Check if the compressor is on.
*
* @return true if the compressor is active
*/
public boolean getCompressorOn() {
return REVPHDataJNI.getCompressorOn(m_index);
}
/**
* Set whether the compressor is active.
*
* @param compressorOn the new value
*/
public void setCompressorOn(boolean compressorOn) {
REVPHDataJNI.setCompressorOn(m_index, compressorOn);
}
/**
* Register a callback to be run whenever the closed loop state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the initial value
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerCompressorConfigTypeCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerCompressorConfigTypeCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorConfigTypeCallback);
public REVPHSim(PneumaticHub module) {
super(module);
}
/**
@@ -169,70 +54,105 @@ public class REVPHSim {
}
/**
* Register a callback to be run whenever the pressure switch value changes.
* Register a callback to be run whenever the closed loop state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the initial value
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerCompressorConfigTypeCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerCompressorConfigTypeCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorConfigTypeCallback);
}
@Override
public boolean getInitialized() {
return REVPHDataJNI.getInitialized(m_index);
}
@Override
public void setInitialized(boolean initialized) {
REVPHDataJNI.setInitialized(m_index, initialized);
}
@Override
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelInitializedCallback);
}
@Override
public boolean getCompressorOn() {
return REVPHDataJNI.getCompressorOn(m_index);
}
@Override
public void setCompressorOn(boolean compressorOn) {
REVPHDataJNI.setCompressorOn(m_index, compressorOn);
}
@Override
public CallbackStore registerCompressorOnCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerCompressorOnCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorOnCallback);
}
@Override
public boolean getSolenoidOutput(int channel) {
return REVPHDataJNI.getSolenoidOutput(m_index, channel);
}
@Override
public void setSolenoidOutput(int channel, boolean solenoidOutput) {
REVPHDataJNI.setSolenoidOutput(m_index, channel, solenoidOutput);
}
@Override
public CallbackStore registerSolenoidOutputCallback(
int channel, NotifyCallback callback, boolean initialNotify) {
int uid =
REVPHDataJNI.registerSolenoidOutputCallback(m_index, channel, callback, initialNotify);
return new CallbackStore(m_index, channel, uid, REVPHDataJNI::cancelSolenoidOutputCallback);
}
@Override
public boolean getPressureSwitch() {
return REVPHDataJNI.getPressureSwitch(m_index);
}
@Override
public void setPressureSwitch(boolean pressureSwitch) {
REVPHDataJNI.setPressureSwitch(m_index, pressureSwitch);
}
@Override
public CallbackStore registerPressureSwitchCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerPressureSwitchCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelPressureSwitchCallback);
}
/**
* Check the value of the pressure switch.
*
* @return the pressure switch value
*/
public boolean getPressureSwitch() {
return REVPHDataJNI.getPressureSwitch(m_index);
@Override
public double getCompressorCurrent() {
return REVPHDataJNI.getCompressorCurrent(m_index);
}
/**
* Set the value of the pressure switch.
*
* @param pressureSwitch the new value
*/
public void setPressureSwitch(boolean pressureSwitch) {
REVPHDataJNI.setPressureSwitch(m_index, pressureSwitch);
@Override
public void setCompressorCurrent(double compressorCurrent) {
REVPHDataJNI.setCompressorCurrent(m_index, compressorCurrent);
}
/**
* Register a callback to be run whenever the compressor current changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
@Override
public CallbackStore registerCompressorCurrentCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerCompressorCurrentCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorCurrentCallback);
}
/**
* Read the compressor current.
*
* @return the current of the compressor connected to this module
*/
public double getCompressorCurrent() {
return REVPHDataJNI.getCompressorCurrent(m_index);
}
/**
* Set the compressor current.
*
* @param compressorCurrent the new compressor current
*/
public void setCompressorCurrent(double compressorCurrent) {
REVPHDataJNI.setCompressorCurrent(m_index, compressorCurrent);
}
/** Reset all simulation data for this object. */
@Override
public void resetData() {
REVPHDataJNI.resetData(m_index);
}

View File

@@ -0,0 +1,86 @@
// 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.simulation;
import edu.wpi.first.hal.simulation.NotifyCallback;
import edu.wpi.first.wpilibj.PneumaticsBase;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
/** Class to control a simulated {@link edu.wpi.first.wpilibj.Solenoid}. */
public class SolenoidSim {
private final PneumaticsBaseSim m_module;
private final int m_channel;
/**
* Constructs for a solenoid on the given pneumatics module.
*
* @param moduleSim the PCM the solenoid is connected to.
* @param channel the solenoid channel.
*/
public SolenoidSim(PneumaticsBaseSim moduleSim, int channel) {
m_module = moduleSim;
m_channel = channel;
}
/**
* Constructs for a solenoid on a pneumatics module of the given type and ID.
*
* @param module the CAN ID of the pneumatics module the solenoid is connected to.
* @param moduleType the module type (PH or PCM)
* @param channel the solenoid channel.
*/
public SolenoidSim(int module, PneumaticsModuleType moduleType, int channel) {
this(PneumaticsBaseSim.getForType(module, moduleType), channel);
}
/**
* Constructs for a solenoid on a pneumatics module of the given type and default ID.
*
* @param moduleType the module type (PH or PCM)
* @param channel the solenoid channel.
*/
public SolenoidSim(PneumaticsModuleType moduleType, int channel) {
this(PneumaticsBase.getDefaultForType(moduleType), moduleType, channel);
}
/**
* Check the solenoid output.
*
* @return the solenoid output
*/
public boolean getOutput() {
return m_module.getSolenoidOutput(m_channel);
}
/**
* Change the solenoid output.
*
* @param output the new solenoid output
*/
public void setOutput(boolean output) {
m_module.setSolenoidOutput(m_channel, output);
}
/**
* Register a callback to be run when the output of this solenoid has changed.
*
* @param callback the callback
* @param initialNotify should the callback be run with the initial value
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerOutputCallback(NotifyCallback callback, boolean initialNotify) {
return m_module.registerSolenoidOutputCallback(m_channel, callback, initialNotify);
}
/**
* Get the wrapped {@link PneumaticsBaseSim} object.
*
* @return the wrapped {@link PneumaticsBaseSim} object.
*/
public PneumaticsBaseSim getPCMSim() {
return m_module;
}
}