2015-03-24 15:01:17 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-01-01 01:05:57 -07:00
|
|
|
/* Copyright (c) FIRST 2014-2017. All Rights Reserved. */
|
2015-03-24 15:01:17 -04: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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include "Encoder.h"
|
|
|
|
|
#include "Jaguar.h"
|
|
|
|
|
#include "Talon.h"
|
|
|
|
|
#include "TestBench.h"
|
|
|
|
|
#include "Timer.h"
|
|
|
|
|
#include "Victor.h"
|
2016-09-05 13:55:31 -07:00
|
|
|
#include "gtest/gtest.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2015-03-24 15:01:17 -04:00
|
|
|
enum MotorInvertingTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
|
2016-01-28 14:25:39 -05:00
|
|
|
static const double motorSpeed = 0.15;
|
2015-03-24 15:01:17 -04:00
|
|
|
static const double delayTime = 0.5;
|
2016-05-20 17:30:37 -07:00
|
|
|
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:
|
2016-05-20 17:30:37 -07:00
|
|
|
SpeedController* m_speedController;
|
|
|
|
|
Encoder* m_encoder;
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
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);
|
2016-11-20 07:25:03 -08:00
|
|
|
m_speedController->Set(0.0);
|
2015-06-25 15:07:55 -04:00
|
|
|
m_encoder->Reset();
|
|
|
|
|
}
|
2015-03-24 15:01:17 -04:00
|
|
|
};
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingPositive) {
|
|
|
|
|
Reset();
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_speedController->Set(motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
|
|
|
|
|
<< "Inverting with Positive value does not change direction";
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingNegative) {
|
|
|
|
|
Reset();
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_speedController->SetInverted(false);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
|
|
|
|
|
<< "Inverting with Negative value does not change direction";
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingSwitchingPosToNeg) {
|
|
|
|
|
Reset();
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_speedController->SetInverted(false);
|
|
|
|
|
m_speedController->Set(motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
|
|
|
|
|
<< "Inverting with Switching value does change direction";
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
TEST_P(MotorInvertingTest, InvertingSwitchingNegToPos) {
|
|
|
|
|
Reset();
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_speedController->SetInverted(false);
|
|
|
|
|
m_speedController->Set(-motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
bool initDirection = m_encoder->GetDirection();
|
|
|
|
|
m_speedController->SetInverted(true);
|
|
|
|
|
m_speedController->Set(motorSpeed);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(delayTime);
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
|
|
|
|
|
<< "Inverting with Switching value does change direction";
|
2017-08-07 17:36:34 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Reset();
|
2015-03-24 15:01:17 -04:00
|
|
|
}
|
2017-08-07 17:36:34 -07:00
|
|
|
|
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));
|