2015-03-24 15:01:17 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
Replaced WPILib.h includes in integration tests with the minimum required subheaders to improve compilation times
I ran the benchmark in a tmpfs with an Intel Core i5-2430M. I ran it three times for each combination of build invokation and source tree.
First, I tested "make". For master (eb7d55f), I measured an average of 42.751s with a standard deviation of 0.372s. For this commit, I measured an average of 33.394s with a standard deviation of 0.140s. There was a 9.356s, or 22%, improvement with a total error of 1.3%.
Second, I tested "make -j4". For master (eb7d55f), I measured an average of 21.723s with a standard deviation of 0.158s. For this commit, I measured an average of 16.823s with a standard deviation of 0.340s. There was a 4.900s, or 23%, improvement with a total error of 2.7%.
Change-Id: Idb3adce62ed8ef449360c6583896b6da3565cf58
2015-07-22 02:34:12 -07:00
|
|
|
#include <Encoder.h>
|
|
|
|
|
#include <Jaguar.h>
|
|
|
|
|
#include <Talon.h>
|
|
|
|
|
#include <Timer.h>
|
|
|
|
|
#include <Victor.h>
|
2015-03-24 15:01:17 -04:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "TestBench.h"
|
|
|
|
|
|
|
|
|
|
enum MotorInvertingTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
|
|
|
|
|
static const double motorSpeed = 0.25;
|
|
|
|
|
static const double delayTime = 0.5;
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, MotorInvertingTestType const &type) {
|
2015-06-25 15:07:55 -04:00
|
|
|
switch (type) {
|
|
|
|
|
case TEST_VICTOR:
|
|
|
|
|
os << "Victor";
|
|
|
|
|
break;
|
|
|
|
|
case TEST_JAGUAR:
|
|
|
|
|
os << "Jaguar";
|
|
|
|
|
break;
|
|
|
|
|
case TEST_TALON:
|
|
|
|
|
os << "Talon";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-03-24 15:01:17 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return os;
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2015-06-25 15:07:55 -04:00
|
|
|
class MotorInvertingTest
|
|
|
|
|
: public testing::TestWithParam<MotorInvertingTestType> {
|
|
|
|
|
protected:
|
|
|
|
|
SpeedController *m_speedController;
|
|
|
|
|
Encoder *m_encoder;
|
2015-06-23 04:49:51 -07:00
|
|
|
virtual void SetUp() override {
|
2015-06-25 15:07:55 -04:00
|
|
|
switch (GetParam()) {
|
|
|
|
|
case TEST_VICTOR:
|
|
|
|
|
m_speedController = new Victor(TestBench::kVictorChannel);
|
|
|
|
|
m_encoder = new Encoder(TestBench::kVictorEncoderChannelA,
|
|
|
|
|
TestBench::kVictorEncoderChannelB);
|
|
|
|
|
break;
|
2015-03-24 15:01:17 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
case TEST_JAGUAR:
|
|
|
|
|
m_speedController = new Jaguar(TestBench::kJaguarChannel);
|
|
|
|
|
m_encoder = new Encoder(TestBench::kJaguarEncoderChannelA,
|
|
|
|
|
TestBench::kJaguarEncoderChannelB);
|
|
|
|
|
break;
|
2015-03-24 15:01:17 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
case TEST_TALON:
|
|
|
|
|
m_speedController = new Talon(TestBench::kTalonChannel);
|
|
|
|
|
m_encoder = new Encoder(TestBench::kTalonEncoderChannelA,
|
|
|
|
|
TestBench::kTalonEncoderChannelB);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-23 04:49:51 -07:00
|
|
|
virtual void TearDown() override {
|
2015-06-25 15:07:55 -04:00
|
|
|
delete m_speedController;
|
|
|
|
|
delete m_encoder;
|
|
|
|
|
}
|
2015-03-24 15:01:17 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void Reset() {
|
|
|
|
|
m_speedController->SetInverted(false);
|
|
|
|
|
m_speedController->Set(0.0f);
|
|
|
|
|
m_encoder->Reset();
|
|
|
|
|
}
|
2015-03-24 15:01:17 -04:00
|
|
|
};
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingPositive) {
|
|
|
|
|
Reset();
|
|
|
|
|
m_speedController->Set(motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
|
|
|
|
|
<< "Inverting with Positive value does not change direction";
|
|
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingNegative) {
|
|
|
|
|
Reset();
|
|
|
|
|
m_speedController->SetInverted(false);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
|
|
|
|
|
<< "Inverting with Negative value does not change direction";
|
|
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingSwitchingPosToNeg) {
|
|
|
|
|
Reset();
|
|
|
|
|
m_speedController->SetInverted(false);
|
|
|
|
|
m_speedController->Set(motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
|
|
|
|
|
<< "Inverting with Switching value does change direction";
|
|
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingSwitchingNegToPos) {
|
|
|
|
|
Reset();
|
|
|
|
|
m_speedController->SetInverted(false);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(motorSpeed);
|
|
|
|
|
Wait(delayTime);
|
|
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
|
|
|
|
|
<< "Inverting with Switching value does change direction";
|
|
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Test, MotorInvertingTest,
|
2015-06-25 15:07:55 -04:00
|
|
|
testing::Values(TEST_VICTOR, TEST_JAGUAR, TEST_TALON));
|