mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[wpilib] Fix PowerDistribution.GetAllCurrents() (#6025)
This commit is contained in:
@@ -113,6 +113,17 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
return PowerDistributionJNI.getChannelCurrent(m_handle, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query all currents of the PDP.
|
||||
*
|
||||
* @return The current of each channel in Amperes
|
||||
*/
|
||||
public double[] getAllCurrents() {
|
||||
double[] currents = new double[getNumChannels()];
|
||||
PowerDistributionJNI.getAllCurrents(m_handle, currents);
|
||||
return currents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the current of all monitored channels.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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 static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
|
||||
import edu.wpi.first.wpilibj.simulation.PDPSim;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PowerDistributionTest {
|
||||
@Test
|
||||
void testGetAllCurrents() {
|
||||
HAL.initialize(500, 0);
|
||||
PowerDistribution pdp = new PowerDistribution(1, ModuleType.kRev);
|
||||
PDPSim sim = new PDPSim(pdp);
|
||||
|
||||
for (int i = 0; i < pdp.getNumChannels(); i++) {
|
||||
sim.setCurrent(i, 24 - i);
|
||||
}
|
||||
double[] currents = pdp.getAllCurrents();
|
||||
for (int i = 0; i < pdp.getNumChannels(); i++) {
|
||||
assertEquals(24 - i, currents[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user