Add new CTRE classes and update PDP tests

Change-Id: I489091c5b8b0f1f9890e5104bf01e40ae53cf6ce
This commit is contained in:
Thomas Clark
2014-08-18 10:32:26 -04:00
parent c82a94b268
commit 687bc44ae5
4 changed files with 69 additions and 79 deletions

View File

@@ -9,92 +9,83 @@
#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;
static const double kMotorTime = 0.25;
class PowerDistributionPanelTest : public testing::Test {
protected:
PowerDistributionPanel *m_pdp;
Talon *m_talon;
Victor *m_victor;
Jaguar *m_jaguar;
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 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);
}
virtual void TearDown() {
delete m_pdp;
delete m_talon;
delete m_victor;
delete m_jaguar;
}
};
/**
* Test if the current changes when the motor is driven using a talon
*/
TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) {
Reset();
TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) {
Wait(kMotorTime);
/* The Current should be kLowCurrent */
EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kTalonPDPChannel), kCurrentTolerance)
<< "The low current was not within the expected range.";
/* The Current should be 0 */
EXPECT_FLOAT_EQ(0, m_pdp->GetCurrent(TestBench::kTalonPDPChannel))
<< "The Talon current was non-zero";
/* Set the motor to full forward */
m_talon->Set(1.0);
Wait(0.02);
/* Set the motor to full forward */
m_talon->Set(1.0);
Wait(kMotorTime);
/* 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.";
/* The current should now be positive */
ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), 0)
<< "The Talon current was not positive";
}
/**
* Test if the current changes when the motor is driven using a victor
*/
TEST_F(PowerDistributionPanelTest,CheckCurrentVictor) {
Reset();
TEST_F(PowerDistributionPanelTest, CheckCurrentVictor) {
Wait(kMotorTime);
/* The Current should be kLowCurrent */
EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kVictorPDPChannel), kCurrentTolerance)
<< "The low current was not within the expected range.";
/* The Current should be 0 */
EXPECT_FLOAT_EQ(0, m_pdp->GetCurrent(TestBench::kVictorPDPChannel))
<< "The Victor current was non-zero";
/* Set the motor to full forward */
m_victor->Set(1.0);
Wait(0.02);
/* Set the motor to full forward */
m_victor->Set(1.0);
Wait(kMotorTime);
/* 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.";
/* The current should now be positive */
ASSERT_GT(m_pdp->GetCurrent(TestBench::kVictorPDPChannel), 0)
<< "The Victor current was not positive";
}
/**
* Test if the current changes when the motor is driven using a jaguar
*/
TEST_F(PowerDistributionPanelTest, CheckCurrentJaguar) {
Reset();
TEST_F(PowerDistributionPanelTest, CheckCurrentJaguar) {
Wait(kMotorTime);
/* The Current should be kLowCurrent */
EXPECT_NEAR(kLowCurrent, m_pdp->GetCurrent(TestBench::kJaguarPDPChannel), kCurrentTolerance)
<< "The low current was not within the expected range.";
/* The Current should be 0 */
EXPECT_FLOAT_EQ(0, m_pdp->GetCurrent(TestBench::kJaguarPDPChannel))
<< "The Jaguar current was non-zero";
/* Set the motor to full forward */
m_jaguar->Set(1.0);
Wait(0.02);
/* Set the motor to full forward */
m_jaguar->Set(1.0);
Wait(kMotorTime);
/* 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.";
/* The current should now be positive */
ASSERT_GT(m_pdp->GetCurrent(TestBench::kJaguarPDPChannel), 0)
<< "The Jaguar current was not positive";
}