2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-06-19 14:56:06 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
import static org.hamcrest.Matchers.greaterThan;
|
|
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.hal.can.CANMessageNotFoundException;
|
|
|
|
|
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.TestBench;
|
2018-05-24 00:31:04 -04:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.logging.Logger;
|
2014-06-19 14:56:06 -04:00
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
2014-07-29 17:57:29 -04:00
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.junit.runners.Parameterized;
|
|
|
|
|
import org.junit.runners.Parameterized.Parameters;
|
2014-06-19 14:56:06 -04:00
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
/** Test that covers the {@link PowerDistribution}. */
|
2014-07-29 17:57:29 -04:00
|
|
|
@RunWith(Parameterized.class)
|
2014-06-19 14:56:06 -04:00
|
|
|
public class PDPTest extends AbstractComsSetup {
|
2019-11-23 07:47:02 -08:00
|
|
|
private static final Logger logger = Logger.getLogger(PDPTest.class.getName());
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
private static PowerDistribution pdp;
|
2015-06-25 15:07:55 -04:00
|
|
|
private static MotorEncoderFixture<?> me;
|
2016-05-20 12:07:40 -04:00
|
|
|
private final double m_expectedStoppedCurrentDraw;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
@BeforeClass
|
2019-08-01 01:19:48 -04:00
|
|
|
public static void setUpBeforeClass() {
|
2021-08-04 20:31:17 -07:00
|
|
|
pdp = new PowerDistribution();
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
2019-08-01 01:19:48 -04:00
|
|
|
public static void tearDownAfterClass() {
|
2015-06-25 15:07:55 -04:00
|
|
|
pdp = null;
|
|
|
|
|
me.teardown();
|
|
|
|
|
me = null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-24 00:13:55 -07:00
|
|
|
/**
|
|
|
|
|
* PDPTest constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param mef Motor encoder fixture.
|
|
|
|
|
* @param expectedCurrentDraw Expected current draw in Amps.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
public PDPTest(MotorEncoderFixture<?> mef, Double expectedCurrentDraw) {
|
|
|
|
|
logger.fine("Constructor with: " + mef.getType());
|
2016-05-20 12:07:40 -04:00
|
|
|
if (me != null && !me.equals(mef)) {
|
2015-06-25 15:07:55 -04:00
|
|
|
me.teardown();
|
2016-05-20 12:07:40 -04:00
|
|
|
}
|
2015-06-25 15:07:55 -04:00
|
|
|
me = mef;
|
|
|
|
|
me.setup();
|
|
|
|
|
|
2016-05-20 12:07:40 -04:00
|
|
|
m_expectedStoppedCurrentDraw = expectedCurrentDraw;
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Parameters(name = "{index}: {0}, Expected Stopped Current Draw: {1}")
|
|
|
|
|
public static Collection<Object[]> generateData() {
|
|
|
|
|
// logger.fine("Loading the MotorList");
|
2021-06-15 23:06:03 -07:00
|
|
|
return Arrays.asList(new Object[][] {{TestBench.getTalonPair(), 0.0}});
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
2019-08-01 01:19:48 -04:00
|
|
|
public void tearDown() {
|
2015-06-25 15:07:55 -04:00
|
|
|
me.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
/** Test if the current changes when the motor is driven using a talon. */
|
2015-06-25 15:07:55 -04:00
|
|
|
@Test
|
2021-04-17 11:27:16 -07:00
|
|
|
public void checkStoppedCurrentForMotorController() throws CANMessageNotFoundException {
|
2015-06-25 15:07:55 -04:00
|
|
|
Timer.delay(0.25);
|
|
|
|
|
|
|
|
|
|
/* The Current should be 0 */
|
2020-12-29 22:45:16 -08:00
|
|
|
assertEquals(
|
|
|
|
|
"The low current was not within the expected range.",
|
|
|
|
|
m_expectedStoppedCurrentDraw,
|
|
|
|
|
pdp.getCurrent(me.getPDPChannel()),
|
|
|
|
|
0.001);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
/** Test if the current changes when the motor is driven using a talon. */
|
2015-06-25 15:07:55 -04:00
|
|
|
@Test
|
2021-04-17 11:27:16 -07:00
|
|
|
public void checkRunningCurrentForMotorController() throws CANMessageNotFoundException {
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Set the motor to full forward */
|
|
|
|
|
me.getMotor().set(1.0);
|
2016-01-29 14:25:19 -05:00
|
|
|
Timer.delay(2);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
/* The current should now be greater than the low current */
|
2020-12-29 22:45:16 -08:00
|
|
|
assertThat(
|
|
|
|
|
"The driven current is not greater than the resting current.",
|
|
|
|
|
pdp.getCurrent(me.getPDPChannel()),
|
|
|
|
|
is(greaterThan(m_expectedStoppedCurrentDraw)));
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Logger getClassLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
2014-06-19 14:56:06 -04:00
|
|
|
}
|