mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Artifact artf3528, Added support for PDP's having addresses other than zero, and added ability to have multiple PDP's.
Change-Id: I8e36ab47d6f60b99a668965396c25856cc07a0cb
This commit is contained in:
@@ -22,9 +22,20 @@ import edu.wpi.first.wpilibj.tables.ITable;
|
||||
* @author Thomas Clark
|
||||
*/
|
||||
public class PowerDistributionPanel extends SensorBase implements LiveWindowSendable {
|
||||
public PowerDistributionPanel() {
|
||||
|
||||
int m_module;
|
||||
|
||||
public PowerDistributionPanel(int module) {
|
||||
m_module = module;
|
||||
checkPDPModule(m_module);
|
||||
PDPJNI.initializePDP(m_module);
|
||||
}
|
||||
|
||||
public PowerDistributionPanel() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query the input voltage of the PDP
|
||||
* @return The voltage of the PDP in volts
|
||||
@@ -33,7 +44,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double voltage = PDPJNI.getPDPVoltage(status.asIntBuffer());
|
||||
double voltage = PDPJNI.getPDPVoltage(status.asIntBuffer(), m_module);
|
||||
|
||||
return voltage;
|
||||
}
|
||||
@@ -46,7 +57,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double temperature = PDPJNI.getPDPTemperature(status.asIntBuffer());
|
||||
double temperature = PDPJNI.getPDPTemperature(status.asIntBuffer(), m_module);
|
||||
|
||||
return temperature;
|
||||
}
|
||||
@@ -59,7 +70,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double current = PDPJNI.getPDPChannelCurrent((byte)channel, status.asIntBuffer());
|
||||
double current = PDPJNI.getPDPChannelCurrent((byte)channel, status.asIntBuffer(), m_module);
|
||||
|
||||
checkPDPChannel(channel);
|
||||
|
||||
@@ -74,7 +85,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double current = PDPJNI.getPDPTotalCurrent(status.asIntBuffer());
|
||||
double current = PDPJNI.getPDPTotalCurrent(status.asIntBuffer(), m_module);
|
||||
|
||||
return current;
|
||||
}
|
||||
@@ -87,7 +98,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double power = PDPJNI.getPDPTotalPower(status.asIntBuffer());
|
||||
double power = PDPJNI.getPDPTotalPower(status.asIntBuffer(), m_module);
|
||||
|
||||
return power;
|
||||
|
||||
@@ -101,7 +112,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
double energy = PDPJNI.getPDPTotalEnergy(status.asIntBuffer());
|
||||
double energy = PDPJNI.getPDPTotalEnergy(status.asIntBuffer(), m_module);
|
||||
|
||||
return energy;
|
||||
}
|
||||
@@ -113,7 +124,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
PDPJNI.resetPDPTotalEnergy(status.asIntBuffer());
|
||||
PDPJNI.resetPDPTotalEnergy(status.asIntBuffer(), m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +134,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
PDPJNI.clearPDPStickyFaults(status.asIntBuffer());
|
||||
PDPJNI.clearPDPStickyFaults(status.asIntBuffer(), m_module);
|
||||
}
|
||||
|
||||
public String getSmartDashboardType() {
|
||||
|
||||
@@ -55,7 +55,11 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* Number of power distribution channels
|
||||
*/
|
||||
public static final int kPDPChannels = 16;
|
||||
|
||||
/**
|
||||
* Number of power distribution modules
|
||||
*/
|
||||
public static final int kPDPModules = 63;
|
||||
|
||||
private static int m_defaultSolenoidModule = 0;
|
||||
|
||||
/**
|
||||
@@ -174,6 +178,18 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the PDP module number is within limits.
|
||||
* module numbers are 0-based.
|
||||
*
|
||||
* @param channel The module number to check.
|
||||
*/
|
||||
protected static void checkPDPModule(final int module) {
|
||||
if (module < 0 || module > kPDPModules) {
|
||||
throw new IndexOutOfBoundsException("Requested PDP module number is out of range.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of the default solenoid module.
|
||||
*
|
||||
|
||||
@@ -4,12 +4,13 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class PDPJNI extends JNIWrapper {
|
||||
public static native double getPDPTemperature(IntBuffer status);
|
||||
public static native double getPDPVoltage(IntBuffer status);
|
||||
public static native double getPDPChannelCurrent(byte channel, IntBuffer status);
|
||||
public static native double getPDPTotalCurrent(IntBuffer status);
|
||||
public static native double getPDPTotalPower(IntBuffer status);
|
||||
public static native double getPDPTotalEnergy(IntBuffer status);
|
||||
public static native void resetPDPTotalEnergy(IntBuffer status);
|
||||
public static native void clearPDPStickyFaults(IntBuffer status);
|
||||
public static native void initializePDP(int module);
|
||||
public static native double getPDPTemperature(IntBuffer status, int module);
|
||||
public static native double getPDPVoltage(IntBuffer status, int module);
|
||||
public static native double getPDPChannelCurrent(byte channel, IntBuffer status, int module);
|
||||
public static native double getPDPTotalCurrent(IntBuffer status, int module);
|
||||
public static native double getPDPTotalPower(IntBuffer status, int module);
|
||||
public static native double getPDPTotalEnergy(IntBuffer status, int module);
|
||||
public static native void resetPDPTotalEnergy(IntBuffer status, int module);
|
||||
public static native void clearPDPStickyFaults(IntBuffer status, int module);
|
||||
}
|
||||
Reference in New Issue
Block a user