[hal] Rename PowerDistributionPanel to PowerDistribution (#3466)

Makes HAL more generic for the PDP, to enable the Rev PDH in the future.
This commit is contained in:
Thad House
2021-08-04 20:31:17 -07:00
committed by GitHub
parent 2014115bca
commit 1ac73a247e
50 changed files with 1612 additions and 1177 deletions

View File

@@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.PDPJNI;
import edu.wpi.first.hal.PowerDistributionJNI;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
@@ -15,30 +15,29 @@ import edu.wpi.first.util.sendable.SendableRegistry;
* Class for getting voltage, current, temperature, power and energy from the Power Distribution
* Panel over CAN.
*/
public class PowerDistributionPanel implements Sendable, AutoCloseable {
public class PowerDistribution implements Sendable, AutoCloseable {
private final int m_handle;
private final int m_module;
/**
* Constructs a PowerDistributionPanel.
* Constructs a PowerDistribution.
*
* @param module The CAN ID of the PDP
*/
public PowerDistributionPanel(int module) {
SensorUtil.checkPDPModule(module);
m_handle = PDPJNI.initializePDP(module);
public PowerDistribution(int module) {
m_handle = PowerDistributionJNI.initialize(module, 0);
m_module = module;
HAL.report(tResourceType.kResourceType_PDP, module + 1);
SendableRegistry.addLW(this, "PowerDistributionPanel", module);
SendableRegistry.addLW(this, "PowerDistribution", module);
}
/**
* Constructs a PowerDistributionPanel.
* Constructs a PowerDistribution.
*
* <p>Uses the default CAN ID (0).
*/
public PowerDistributionPanel() {
public PowerDistribution() {
this(0);
}
@@ -53,7 +52,7 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
* @return The voltage of the PDP in volts
*/
public double getVoltage() {
return PDPJNI.getPDPVoltage(m_handle);
return PowerDistributionJNI.getVoltage(m_handle);
}
/**
@@ -62,7 +61,7 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
* @return The temperature of the PDP in degrees Celsius
*/
public double getTemperature() {
return PDPJNI.getPDPTemperature(m_handle);
return PowerDistributionJNI.getTemperature(m_handle);
}
/**
@@ -72,9 +71,7 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
* @return The current of one of the PDP channels (channels 0-15) in Amperes
*/
public double getCurrent(int channel) {
double current = PDPJNI.getPDPChannelCurrent((byte) channel, m_handle);
SensorUtil.checkPDPChannel(channel);
double current = PowerDistributionJNI.getChannelCurrent((byte) channel, m_handle);
return current;
}
@@ -85,7 +82,7 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
* @return The current of all the channels in Amperes
*/
public double getTotalCurrent() {
return PDPJNI.getPDPTotalCurrent(m_handle);
return PowerDistributionJNI.getTotalCurrent(m_handle);
}
/**
@@ -94,7 +91,7 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
* @return the total power in Watts
*/
public double getTotalPower() {
return PDPJNI.getPDPTotalPower(m_handle);
return PowerDistributionJNI.getTotalPower(m_handle);
}
/**
@@ -103,17 +100,17 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
* @return the total energy in Joules
*/
public double getTotalEnergy() {
return PDPJNI.getPDPTotalEnergy(m_handle);
return PowerDistributionJNI.getTotalEnergy(m_handle);
}
/** Reset the total energy to 0. */
public void resetTotalEnergy() {
PDPJNI.resetPDPTotalEnergy(m_handle);
PowerDistributionJNI.resetTotalEnergy(m_handle);
}
/** Clear all PDP sticky faults. */
public void clearStickyFaults() {
PDPJNI.clearPDPStickyFaults(m_handle);
PowerDistributionJNI.clearStickyFaults(m_handle);
}
/**
@@ -127,7 +124,7 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("PowerDistributionPanel");
builder.setSmartDashboardType("PowerDistribution");
for (int i = 0; i < SensorUtil.kPDPChannels; ++i) {
final int chan = i;
builder.addDoubleProperty("Chan" + i, () -> getCurrent(chan), null);

View File

@@ -7,7 +7,6 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.AnalogJNI;
import edu.wpi.first.hal.ConstantsJNI;
import edu.wpi.first.hal.DIOJNI;
import edu.wpi.first.hal.PDPJNI;
import edu.wpi.first.hal.PWMJNI;
import edu.wpi.first.hal.PortsJNI;
import edu.wpi.first.hal.RelayJNI;
@@ -133,39 +132,6 @@ public final class SensorUtil {
}
}
/**
* Verify that the power distribution channel number is within limits. Channel numbers are
* 0-based.
*
* @param channel The channel number to check.
*/
public static void checkPDPChannel(final int channel) {
if (!PDPJNI.checkPDPChannel(channel)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested PDP channel is out of range. Minimum: 0, Maximum: ")
.append(kPDPChannels)
.append(", Requested: ")
.append(channel);
throw new IllegalArgumentException(buf.toString());
}
}
/**
* Verify that the PDP module number is within limits. module numbers are 0-based.
*
* @param module The module number to check.
*/
public static void checkPDPModule(final int module) {
if (!PDPJNI.checkPDPModule(module)) {
StringBuilder buf = new StringBuilder();
buf.append("Requested PDP module is out of range. Minimum: 0, Maximum: ")
.append(kPDPModules)
.append(", Requested: ")
.append(module);
throw new IllegalArgumentException(buf.toString());
}
}
/**
* Get the number of the default solenoid module.
*

View File

@@ -188,11 +188,11 @@ public enum BuiltInWidgets implements WidgetType {
*/
kVoltageView("Voltage View"),
/**
* Displays a {@link edu.wpi.first.wpilibj.PowerDistributionPanel PowerDistributionPanel}. <br>
* Displays a {@link edu.wpi.first.wpilibj.PowerDistribution PowerDistribution}. <br>
* Supported types:
*
* <ul>
* <li>{@link edu.wpi.first.wpilibj.PowerDistributionPanel}
* <li>{@link edu.wpi.first.wpilibj.PowerDistribution}
* </ul>
*
* <br>
@@ -204,7 +204,7 @@ public enum BuiltInWidgets implements WidgetType {
* <td>Whether or not to display the voltage and current draw</td></tr>
* </table>
*/
kPowerDistributionPanel("PDP"),
kPowerDistribution("PDP"),
/**
* Displays a {@link edu.wpi.first.wpilibj.smartdashboard.SendableChooser SendableChooser} with a
* dropdown combo box with a list of options. <br>

View File

@@ -5,8 +5,8 @@
package edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.hal.simulation.NotifyCallback;
import edu.wpi.first.hal.simulation.PDPDataJNI;
import edu.wpi.first.wpilibj.PowerDistributionPanel;
import edu.wpi.first.hal.simulation.PowerDistributionDataJNI;
import edu.wpi.first.wpilibj.PowerDistribution;
/** Class to control a simulated Power Distribution Panel (PDP). */
public class PDPSim {
@@ -27,11 +27,11 @@ public class PDPSim {
}
/**
* Constructs from a PowerDistributionPanel object.
* Constructs from a PowerDistribution object.
*
* @param pdp PowerDistributionPanel to simulate
* @param pdp PowerDistribution to simulate
*/
public PDPSim(PowerDistributionPanel pdp) {
public PDPSim(PowerDistribution pdp) {
m_index = pdp.getModule();
}
@@ -44,8 +44,9 @@ public class PDPSim {
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
int uid = PDPDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, PDPDataJNI::cancelInitializedCallback);
int uid =
PowerDistributionDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, PowerDistributionDataJNI::cancelInitializedCallback);
}
/**
@@ -54,7 +55,7 @@ public class PDPSim {
* @return true if initialized
*/
public boolean getInitialized() {
return PDPDataJNI.getInitialized(m_index);
return PowerDistributionDataJNI.getInitialized(m_index);
}
/**
@@ -63,7 +64,7 @@ public class PDPSim {
* @param initialized whether this object is initialized
*/
public void setInitialized(boolean initialized) {
PDPDataJNI.setInitialized(m_index, initialized);
PowerDistributionDataJNI.setInitialized(m_index, initialized);
}
/**
@@ -75,8 +76,9 @@ public class PDPSim {
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerTemperatureCallback(NotifyCallback callback, boolean initialNotify) {
int uid = PDPDataJNI.registerTemperatureCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, PDPDataJNI::cancelTemperatureCallback);
int uid =
PowerDistributionDataJNI.registerTemperatureCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, PowerDistributionDataJNI::cancelTemperatureCallback);
}
/**
@@ -85,7 +87,7 @@ public class PDPSim {
* @return the PDP temperature
*/
public double getTemperature() {
return PDPDataJNI.getTemperature(m_index);
return PowerDistributionDataJNI.getTemperature(m_index);
}
/**
@@ -94,7 +96,7 @@ public class PDPSim {
* @param temperature the new PDP temperature
*/
public void setTemperature(double temperature) {
PDPDataJNI.setTemperature(m_index, temperature);
PowerDistributionDataJNI.setTemperature(m_index, temperature);
}
/**
@@ -106,8 +108,8 @@ public class PDPSim {
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerVoltageCallback(NotifyCallback callback, boolean initialNotify) {
int uid = PDPDataJNI.registerVoltageCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, PDPDataJNI::cancelVoltageCallback);
int uid = PowerDistributionDataJNI.registerVoltageCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, PowerDistributionDataJNI::cancelVoltageCallback);
}
/**
@@ -116,7 +118,7 @@ public class PDPSim {
* @return the PDP voltage.
*/
public double getVoltage() {
return PDPDataJNI.getVoltage(m_index);
return PowerDistributionDataJNI.getVoltage(m_index);
}
/**
@@ -125,7 +127,7 @@ public class PDPSim {
* @param voltage the new PDP voltage
*/
public void setVoltage(double voltage) {
PDPDataJNI.setVoltage(m_index, voltage);
PowerDistributionDataJNI.setVoltage(m_index, voltage);
}
/**
@@ -139,8 +141,10 @@ public class PDPSim {
*/
public CallbackStore registerCurrentCallback(
int channel, NotifyCallback callback, boolean initialNotify) {
int uid = PDPDataJNI.registerCurrentCallback(m_index, channel, callback, initialNotify);
return new CallbackStore(m_index, channel, uid, PDPDataJNI::cancelCurrentCallback);
int uid =
PowerDistributionDataJNI.registerCurrentCallback(m_index, channel, callback, initialNotify);
return new CallbackStore(
m_index, channel, uid, PowerDistributionDataJNI::cancelCurrentCallback);
}
/**
@@ -150,7 +154,7 @@ public class PDPSim {
* @return the current in the given channel
*/
public double getCurrent(int channel) {
return PDPDataJNI.getCurrent(m_index, channel);
return PowerDistributionDataJNI.getCurrent(m_index, channel);
}
/**
@@ -160,11 +164,11 @@ public class PDPSim {
* @param current the new current for the channel
*/
public void setCurrent(int channel, double current) {
PDPDataJNI.setCurrent(m_index, channel, current);
PowerDistributionDataJNI.setCurrent(m_index, channel, current);
}
/** Reset all PDP simulation data. */
public void resetData() {
PDPDataJNI.resetData(m_index);
PowerDistributionDataJNI.resetData(m_index);
}
}