mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Added PDP tests for java and C++, updated TestBench.h
Change-Id: Idd6be8739065d757f5d1471ebb685d48a1c53e59
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
#include "PIDOutput.h"
|
||||
#include "PIDSource.h"
|
||||
#include "Preferences.h"
|
||||
#include "PowerDistributionPanel.h"
|
||||
#include "PWM.h"
|
||||
#include "Relay.h"
|
||||
#include "Resource.h"
|
||||
|
||||
@@ -50,4 +50,9 @@ public:
|
||||
|
||||
/* CAN IDs */
|
||||
static const uint32_t kCANJaguarID = 1;
|
||||
|
||||
/* PDP channels */
|
||||
static const uint32_t kJaguarPDPChannel = 7;
|
||||
static const uint32_t kVictorPDPChannel = 11;
|
||||
static const uint32_t kTalonPDPChannel = 12;
|
||||
};
|
||||
|
||||
0
wpilibc/wpilibC++IntegrationTests/src/PDPTest.cpp
Normal file
0
wpilibc/wpilibC++IntegrationTests/src/PDPTest.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WPILib.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "TestBench.h"
|
||||
|
||||
/* The current returned when the motor is not being driven */
|
||||
static const double kLowCurrent = 1.52;
|
||||
static const double kCurrentTolerance = 0.1;
|
||||
|
||||
class PowerDistributionPanelTest : public testing::Test {
|
||||
protected:
|
||||
PowerDistributionPanel *m_pdp;
|
||||
Talon *m_talon;
|
||||
Victor *m_victor;
|
||||
Jaguar *m_jaguar;
|
||||
|
||||
virtual void SetUp() {
|
||||
m_pdp = new PowerDistributionPanel();
|
||||
m_talon = new Talon(TestBench::kTalonChannel);
|
||||
m_victor = new Victor(TestBench::kVictorChannel);
|
||||
m_jaguar = new Jaguar(TestBench::kJaguarChannel);
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
delete m_pdp;
|
||||
delete m_talon;
|
||||
delete m_victor;
|
||||
delete m_jaguar;
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
/* Reset all speed controllers to 0.0 */
|
||||
m_talon->Set(0.0f);
|
||||
m_victor->Set(0.0f);
|
||||
m_jaguar->Set(0.0f);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the current changes when the motor is driven using a talon
|
||||
*/
|
||||
TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) {
|
||||
Reset();
|
||||
|
||||
/* The Current should be kLowCurrent */
|
||||
EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kTalonPDPChannel), kCurrentTolerance)
|
||||
<< "The low current was not within the expected range.";
|
||||
|
||||
/* Set the motor to full forward */
|
||||
m_talon->Set(1.0);
|
||||
Wait(0.02);
|
||||
|
||||
/* The current should now be greater than the low current */
|
||||
ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), kLowCurrent)
|
||||
<< "The driven current is not greater than the resting current.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the current changes when the motor is driven using a victor
|
||||
*/
|
||||
TEST_F(PowerDistributionPanelTest,CheckCurrentVictor) {
|
||||
Reset();
|
||||
|
||||
/* The Current should be kLowCurrent */
|
||||
EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kVictorPDPChannel), kCurrentTolerance)
|
||||
<< "The low current was not within the expected range.";
|
||||
|
||||
/* Set the motor to full forward */
|
||||
m_victor->Set(1.0);
|
||||
Wait(0.02);
|
||||
|
||||
/* The current should now be greater than the low current */
|
||||
ASSERT_GT(m_pdp->GetCurrent(TestBench::kVictorPDPChannel), kLowCurrent)
|
||||
<< "The driven current is not greater than the resting current.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the current changes when the motor is driven using a jaguar
|
||||
*/
|
||||
TEST_F(PowerDistributionPanelTest, CheckCurrentJaguar) {
|
||||
Reset();
|
||||
|
||||
/* The Current should be kLowCurrent */
|
||||
EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kJaguarPDPChannel), kCurrentTolerance)
|
||||
<< "The low current was not within the expected range.";
|
||||
|
||||
/* Set the motor to full forward */
|
||||
m_jaguar->Set(1.0);
|
||||
Wait(0.02);
|
||||
|
||||
/* The current should now be greater than the low current */
|
||||
ASSERT_GT(m_pdp->GetCurrent(TestBench::kJaguarPDPChannel), kLowCurrent)
|
||||
<< "The driven current is not greater than the resting current.";
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<!--dependency>
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.can.CANTimeoutException;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
public class PDPTest extends AbstractComsSetup {
|
||||
private static final Logger logger = Logger.getLogger(PCMTest.class.getName());
|
||||
/* The current returned when the motor is not being driven */
|
||||
protected static final double kLowCurrent = 1.52;
|
||||
|
||||
protected static final double kCurrentTolerance = 0.1;
|
||||
|
||||
private static PowerDistributionPanel pdp;
|
||||
private static Talon talon;
|
||||
private static Victor victor;
|
||||
private static Jaguar jaguar;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
pdp = new PowerDistributionPanel();
|
||||
talon = new Talon(TestBench.kTalonPDPChannel);
|
||||
victor = new Victor(TestBench.kVictorPDPChannel);
|
||||
jaguar = new Jaguar(TestBench.kJaguarPDPChannel);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
pdp.free();
|
||||
talon.free();
|
||||
victor.free();
|
||||
jaguar.free();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
/* Reset all speed controllers to 0.0 */
|
||||
talon.set(0.0);
|
||||
victor.set(0.0);
|
||||
jaguar.set(0.0);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the current changes when the motor is driven using a talon
|
||||
*/
|
||||
@Test
|
||||
public void CheckCurrentTalon() {
|
||||
/* The Current should be kLowCurrent */
|
||||
try {
|
||||
assertEquals("The low current was not within the expected range.",
|
||||
kLowCurrent, pdp.getCurrent(TestBench.kTalonPDPChannel), kCurrentTolerance);
|
||||
} catch (CANTimeoutException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Timer.delay(0.02);
|
||||
|
||||
/* Set the motor to full forward */
|
||||
talon.set(1.0);
|
||||
Timer.delay(0.02);
|
||||
/* The current should now be greater than the low current */
|
||||
try {
|
||||
assertThat("The driven current is not greater than the resting current.",
|
||||
pdp.getCurrent(TestBench.kTalonPDPChannel), is(greaterThan(kLowCurrent)));
|
||||
} catch (CANTimeoutException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the current changes when the motor is driven using a victor
|
||||
*/
|
||||
@Test
|
||||
public void CheckCurrentVictor() {
|
||||
/* The Current should be kLowCurrent */
|
||||
try {
|
||||
assertEquals("The low current was not within the expected range.",
|
||||
kLowCurrent, pdp.getCurrent(TestBench.kVictorPDPChannel), kCurrentTolerance);
|
||||
} catch (CANTimeoutException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Timer.delay(0.02);
|
||||
|
||||
/* Set the motor to full forward */
|
||||
victor.set(1.0);
|
||||
Timer.delay(0.02);
|
||||
/* The current should now be greater than the low current */
|
||||
try {
|
||||
assertThat("The driven current is not greater than the resting current.",
|
||||
pdp.getCurrent(TestBench.kVictorPDPChannel), is(greaterThan(kLowCurrent)));
|
||||
} catch (CANTimeoutException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the current changes when the motor is driven using a jaguar
|
||||
*/
|
||||
@Test
|
||||
public void CheckCurrentJaguar() {
|
||||
/* The Current should be kLowCurrent */
|
||||
try {
|
||||
assertEquals("The low current was not within the expected range.",
|
||||
kLowCurrent, pdp.getCurrent(TestBench.kJaguarPDPChannel), kCurrentTolerance);
|
||||
} catch (CANTimeoutException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Timer.delay(0.02);
|
||||
|
||||
/* Set the motor to full forward */
|
||||
jaguar.set(1.0);
|
||||
Timer.delay(0.02);
|
||||
|
||||
/* The current should now be greater than the low current */
|
||||
try {
|
||||
assertThat("The driven current is not greater than the resting current.",
|
||||
pdp.getCurrent(TestBench.kJaguarPDPChannel), is(greaterThan(kLowCurrent)));
|
||||
} catch (CANTimeoutException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
RelayCrossConnectTest.class,
|
||||
SampleTest.class,
|
||||
TiltPanCameraTest.class,
|
||||
TimerTest.class
|
||||
TimerTest.class,
|
||||
PDPTest.class
|
||||
})
|
||||
public class WpiLibJTestSuite {
|
||||
|
||||
|
||||
@@ -47,13 +47,17 @@ public final class TestBench {
|
||||
* completely stopped
|
||||
*/
|
||||
public static final double MOTOR_STOP_TIME = 0.20;
|
||||
|
||||
|
||||
/* PowerDistributionPanel channels */
|
||||
public static final int kJaguarPDPChannel = 7;
|
||||
public static final int kVictorPDPChannel = 11;
|
||||
public static final int kTalonPDPChannel = 12;
|
||||
|
||||
//THESE MUST BE IN INCREMENTING ORDER
|
||||
public static final int DIOCrossConnectA1 = 6;
|
||||
public static final int DIOCrossConnectA2 = 7;
|
||||
public static final int DIOCrossConnectB1 = 8;
|
||||
public static final int DIOCrossConnectB2 = 9;
|
||||
public static final int DIOCrossConnectB1 = 8;
|
||||
public static final int DIOCrossConnectA2 = 7;
|
||||
public static final int DIOCrossConnectA1 = 6;
|
||||
|
||||
/** The Singleton instance of the Test Bench */
|
||||
private static TestBench instance = null;
|
||||
|
||||
Reference in New Issue
Block a user