mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[hal] [wpilib] Add initial support for the REV PDH (#3503)
This commit is contained in:
@@ -19,26 +19,40 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
private final int m_handle;
|
||||
private final int m_module;
|
||||
|
||||
public static final int kDefaultModule = PowerDistributionJNI.DEFAULT_MODULE;
|
||||
|
||||
public enum ModuleType {
|
||||
kAutomatic(PowerDistributionJNI.AUTOMATIC_TYPE),
|
||||
kCTRE(PowerDistributionJNI.CTRE_TYPE),
|
||||
kRev(PowerDistributionJNI.REV_TYPE);
|
||||
|
||||
public final int value;
|
||||
|
||||
ModuleType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a PowerDistribution.
|
||||
*
|
||||
* @param module The CAN ID of the PDP
|
||||
*/
|
||||
public PowerDistribution(int module) {
|
||||
m_handle = PowerDistributionJNI.initialize(module, 0);
|
||||
m_module = module;
|
||||
public PowerDistribution(int module, ModuleType moduleType) {
|
||||
m_handle = PowerDistributionJNI.initialize(module, moduleType.value);
|
||||
m_module = PowerDistributionJNI.getModuleNumber(m_handle);
|
||||
|
||||
HAL.report(tResourceType.kResourceType_PDP, module + 1);
|
||||
SendableRegistry.addLW(this, "PowerDistribution", module);
|
||||
HAL.report(tResourceType.kResourceType_PDP, m_module + 1);
|
||||
SendableRegistry.addLW(this, "PowerDistribution", m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a PowerDistribution.
|
||||
*
|
||||
* <p>Uses the default CAN ID (0).
|
||||
* <p>Uses the default CAN ID.
|
||||
*/
|
||||
public PowerDistribution() {
|
||||
this(0);
|
||||
this(kDefaultModule, ModuleType.kAutomatic);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,6 +60,15 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
SendableRegistry.remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of channel for this power distribution.
|
||||
*
|
||||
* @return Number of output channels.
|
||||
*/
|
||||
public int getNumChannels() {
|
||||
return PowerDistributionJNI.getNumChannels(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the input voltage of the PDP.
|
||||
*
|
||||
@@ -71,7 +94,7 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
* @return The current of one of the PDP channels (channels 0-15) in Amperes
|
||||
*/
|
||||
public double getCurrent(int channel) {
|
||||
double current = PowerDistributionJNI.getChannelCurrent((byte) channel, m_handle);
|
||||
double current = PowerDistributionJNI.getChannelCurrent(m_handle, channel);
|
||||
|
||||
return current;
|
||||
}
|
||||
@@ -122,14 +145,25 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
return m_module;
|
||||
}
|
||||
|
||||
public boolean getSwitchableChannel() {
|
||||
return PowerDistributionJNI.getSwitchableChannel(m_handle);
|
||||
}
|
||||
|
||||
public void setSwitchableChannel(boolean enabled) {
|
||||
PowerDistributionJNI.setSwitchableChannel(m_handle, enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("PowerDistribution");
|
||||
for (int i = 0; i < SensorUtil.kPDPChannels; ++i) {
|
||||
int numChannels = getNumChannels();
|
||||
for (int i = 0; i < numChannels; ++i) {
|
||||
final int chan = i;
|
||||
builder.addDoubleProperty("Chan" + i, () -> getCurrent(chan), null);
|
||||
}
|
||||
builder.addDoubleProperty("Voltage", this::getVoltage, null);
|
||||
builder.addDoubleProperty("TotalCurrent", this::getTotalCurrent, null);
|
||||
builder.addBooleanProperty(
|
||||
"SwitchableChannel", this::getSwitchableChannel, this::setSwitchableChannel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class SensorUtil {
|
||||
public static final int kAnalogOutputChannels = PortsJNI.getNumAnalogOutputs();
|
||||
|
||||
/** Number of solenoid channels per module. */
|
||||
public static final int kSolenoidChannels = PortsJNI.getNumSolenoidChannels();
|
||||
public static final int kCTRESolenoidChannels = PortsJNI.getNumCTRESolenoidChannels();
|
||||
|
||||
/** Number of PWM channels per roboRIO. */
|
||||
public static final int kPwmChannels = PortsJNI.getNumPWMChannels();
|
||||
@@ -39,13 +39,13 @@ public final class SensorUtil {
|
||||
public static final int kRelayChannels = PortsJNI.getNumRelayHeaders();
|
||||
|
||||
/** Number of power distribution channels per PDP. */
|
||||
public static final int kPDPChannels = PortsJNI.getNumPDPChannels();
|
||||
public static final int kCTREPDPChannels = PortsJNI.getNumCTREPDPChannels();
|
||||
|
||||
/** Number of power distribution modules per PDP. */
|
||||
public static final int kPDPModules = PortsJNI.getNumPDPModules();
|
||||
public static final int kCTREPDPModules = PortsJNI.getNumCTREPDPModules();
|
||||
|
||||
/** Number of PCM Modules. */
|
||||
public static final int kPCMModules = PortsJNI.getNumPCMModules();
|
||||
public static final int kCTREPCMModules = PortsJNI.getNumCTREPCMModules();
|
||||
|
||||
/**
|
||||
* Check that the digital channel number is valid. Verify that the channel number is one of the
|
||||
|
||||
Reference in New Issue
Block a user