2016-01-02 03:02:34 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2014-06-19 14:56:06 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
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
|
|
|
|
2018-09-20 21:59:46 -07:00
|
|
|
import edu.wpi.first.hal.can.CANMessageNotFoundException;
|
2014-07-29 17:57:29 -04:00
|
|
|
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
2014-06-19 14:56:06 -04:00
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.TestBench;
|
|
|
|
|
|
2016-05-20 12:07:40 -04: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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test that covers the {@link PowerDistributionPanel}.
|
|
|
|
|
*/
|
2014-07-29 17:57:29 -04:00
|
|
|
@RunWith(Parameterized.class)
|
2014-06-19 14:56:06 -04:00
|
|
|
public class PDPTest extends AbstractComsSetup {
|
2015-06-25 15:07:55 -04:00
|
|
|
private static final Logger logger = Logger.getLogger(PCMTest.class.getName());
|
|
|
|
|
|
|
|
|
|
private static PowerDistributionPanel pdp;
|
|
|
|
|
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
|
|
|
|
|
public static void setUpBeforeClass() throws Exception {
|
|
|
|
|
pdp = new PowerDistributionPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void tearDownAfterClass() throws Exception {
|
2018-05-22 23:33:17 -07:00
|
|
|
pdp.close();
|
2015-06-25 15:07:55 -04:00
|
|
|
pdp = null;
|
|
|
|
|
me.teardown();
|
|
|
|
|
me = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-05-20 12:07:40 -04:00
|
|
|
@SuppressWarnings("JavadocMethod")
|
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");
|
2016-05-20 12:07:40 -04:00
|
|
|
return Arrays.asList(new Object[][]{
|
2016-01-29 14:25:19 -05:00
|
|
|
{TestBench.getInstance().getTalonPair(), new Double(0.0)}});
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
|
me.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-05-20 12:07:40 -04:00
|
|
|
* Test if the current changes when the motor is driven using a talon.
|
2015-06-25 15:07:55 -04:00
|
|
|
*/
|
|
|
|
|
@Test
|
2016-05-20 12:07:40 -04:00
|
|
|
public void checkStoppedCurrentForSpeedController() throws CANMessageNotFoundException {
|
2015-06-25 15:07:55 -04:00
|
|
|
Timer.delay(0.25);
|
|
|
|
|
|
|
|
|
|
/* The Current should be 0 */
|
2016-05-20 12:07:40 -04:00
|
|
|
assertEquals("The low current was not within the expected range.", m_expectedStoppedCurrentDraw,
|
2015-06-25 15:07:55 -04:00
|
|
|
pdp.getCurrent(me.getPDPChannel()), 0.001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-05-20 12:07:40 -04:00
|
|
|
* Test if the current changes when the motor is driven using a talon.
|
2015-06-25 15:07:55 -04:00
|
|
|
*/
|
|
|
|
|
@Test
|
2016-05-20 12:07:40 -04:00
|
|
|
public void checkRunningCurrentForSpeedController() 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 */
|
|
|
|
|
assertThat("The driven current is not greater than the resting current.",
|
2016-05-20 12:07:40 -04:00
|
|
|
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
|
|
|
}
|