2014-06-12 18:07:45 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
|
2014-06-12 18:07:45 -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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
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 <AnalogInput.h>
|
|
|
|
|
#include <AnalogOutput.h>
|
|
|
|
|
#include <AnalogTrigger.h>
|
|
|
|
|
#include <Counter.h>
|
|
|
|
|
#include <Timer.h>
|
2014-06-12 18:07:45 -04:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "TestBench.h"
|
|
|
|
|
|
2014-07-29 16:36:36 -04:00
|
|
|
static const double kDelayTime = 0.01;
|
2014-06-12 18:07:45 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A fixture with an analog input and an analog output wired together
|
|
|
|
|
*/
|
|
|
|
|
class AnalogLoopTest : public testing::Test {
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
|
|
|
|
AnalogInput *m_input;
|
|
|
|
|
AnalogOutput *m_output;
|
|
|
|
|
|
|
|
|
|
virtual void SetUp() override {
|
|
|
|
|
m_input = new AnalogInput(TestBench::kFakeAnalogOutputChannel);
|
|
|
|
|
m_output = new AnalogOutput(TestBench::kAnalogOutputChannel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() override {
|
|
|
|
|
delete m_input;
|
|
|
|
|
delete m_output;
|
|
|
|
|
}
|
2014-06-12 18:07:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test analog inputs and outputs by setting one and making sure the other
|
|
|
|
|
* matches.
|
|
|
|
|
*/
|
2014-07-29 16:36:36 -04:00
|
|
|
TEST_F(AnalogLoopTest, AnalogInputWorks) {
|
2015-06-25 15:07:55 -04:00
|
|
|
// Set the output voltage and check if the input measures the same voltage
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
|
m_output->SetVoltage(i / 10.0f);
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(kDelayTime);
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_NEAR(m_output->GetVoltage(), m_input->GetVoltage(), 0.01f);
|
|
|
|
|
}
|
2014-07-29 16:36:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if we can use an analog trigger to check if the output is within a
|
|
|
|
|
* range correctly.
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
|
2015-06-25 15:07:55 -04:00
|
|
|
AnalogTrigger trigger(m_input);
|
|
|
|
|
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_output->SetVoltage(1.0f);
|
|
|
|
|
Wait(kDelayTime);
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_FALSE(trigger.GetInWindow())
|
|
|
|
|
<< "Analog trigger is in the window (2V, 3V)";
|
|
|
|
|
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_output->SetVoltage(2.5f);
|
|
|
|
|
Wait(kDelayTime);
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_TRUE(trigger.GetInWindow())
|
|
|
|
|
<< "Analog trigger is not in the window (2V, 3V)";
|
|
|
|
|
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
m_output->SetVoltage(4.0f);
|
|
|
|
|
Wait(kDelayTime);
|
2014-07-29 16:36:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_FALSE(trigger.GetInWindow())
|
|
|
|
|
<< "Analog trigger is in the window (2V, 3V)";
|
|
|
|
|
EXPECT_TRUE(trigger.GetTriggerState()) << "Analog trigger is not on";
|
2014-07-29 16:36:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if we can count the right number of ticks from an analog trigger with
|
|
|
|
|
* a counter.
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(AnalogLoopTest, AnalogTriggerCounterWorks) {
|
2015-06-25 15:07:55 -04:00
|
|
|
AnalogTrigger trigger(m_input);
|
|
|
|
|
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
|
|
|
|
|
|
|
|
|
Counter counter(trigger);
|
|
|
|
|
|
|
|
|
|
// Turn the analog output low and high 50 times
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
|
m_output->SetVoltage(1.0);
|
|
|
|
|
Wait(kDelayTime);
|
|
|
|
|
m_output->SetVoltage(4.0);
|
|
|
|
|
Wait(kDelayTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The counter should be 50
|
|
|
|
|
EXPECT_EQ(50, counter.Get())
|
|
|
|
|
<< "Analog trigger counter did not count 50 ticks";
|
2014-06-12 18:07:45 -04:00
|
|
|
}
|
2014-08-04 12:19:31 -04:00
|
|
|
|
|
|
|
|
static void InterruptHandler(uint32_t interruptAssertedMask, void *param) {
|
2015-06-25 15:07:55 -04:00
|
|
|
*(int *)param = 12345;
|
2014-08-04 12:19:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int param = 0;
|
|
|
|
|
AnalogTrigger trigger(m_input);
|
|
|
|
|
trigger.SetLimitsVoltage(2.0f, 3.0f);
|
|
|
|
|
|
|
|
|
|
// Given an interrupt handler that sets an int to 12345
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<AnalogTriggerOutput> triggerOutput = trigger.CreateOutput(kState);
|
2015-06-25 15:07:55 -04:00
|
|
|
triggerOutput->RequestInterrupts(InterruptHandler, ¶m);
|
|
|
|
|
triggerOutput->EnableInterrupts();
|
|
|
|
|
|
|
|
|
|
// If the analog output moves from below to above the window
|
|
|
|
|
m_output->SetVoltage(0.0);
|
|
|
|
|
Wait(kDelayTime);
|
|
|
|
|
m_output->SetVoltage(5.0);
|
|
|
|
|
triggerOutput->CancelInterrupts();
|
|
|
|
|
|
|
|
|
|
// Then the int should be 12345
|
|
|
|
|
Wait(kDelayTime);
|
|
|
|
|
EXPECT_EQ(12345, param) << "The interrupt did not run.";
|
2014-08-04 12:19:31 -04:00
|
|
|
}
|