[wpilibc] Clean up integration tests (#3400)

The command and shuffleboard integration tests were removed because
their unit tests counterparts already provide adequate coverage. Java
already removed these.
This commit is contained in:
Tyler Veness
2021-05-31 10:21:34 -07:00
committed by GitHub
parent 4f7a4464df
commit 93523d572e
38 changed files with 662 additions and 2232 deletions

View File

@@ -13,137 +13,79 @@
#include "frc/Timer.h"
#include "gtest/gtest.h"
using namespace frc;
static constexpr auto kServoResetTime = 2_s;
static constexpr double kTestAngle = 90.0;
static constexpr double kTiltSetpoint0 = 0.22;
static constexpr double kTiltSetpoint45 = 0.45;
static constexpr double kTiltSetpoint90 = 0.68;
static constexpr auto kTiltTime = 1_s;
static constexpr double kAccelerometerTolerance = 0.2;
static constexpr double kSensitivity = 0.013;
/**
* A fixture for the camera with two servos and a gyro
*/
class TiltPanCameraTest : public testing::Test {
protected:
static AnalogGyro* m_gyro;
Servo *m_tilt, *m_pan;
Accelerometer* m_spiAccel;
frc::Servo m_tilt{TestBench::kCameraTiltChannel};
frc::Servo m_pan{TestBench::kCameraPanChannel};
frc::ADXL345_SPI m_spiAccel{frc::SPI::kOnboardCS1};
static void SetUpTestCase() {
// The gyro object blocks for 5 seconds in the constructor, so only
// construct it once for the whole test case
m_gyro = new AnalogGyro(TestBench::kCameraGyroChannel);
m_gyro->SetSensitivity(kSensitivity);
TiltPanCameraTest() {
m_tilt.Set(kTiltSetpoint45);
m_pan.SetAngle(0.0);
// Wait for servos to reset
frc::Wait(2_s);
}
static void TearDownTestCase() { delete m_gyro; }
/**
* Test if the servo turns 90 degrees and the gyroscope measures this angle
* Note servo on TestBench is not the same type of servo that servo class
* was designed for so setAngle is significantly off. This has been calibrated
* for the servo on the rig.
*/
void GyroTests(frc::AnalogGyro& gyro) {
gyro.SetSensitivity(0.013);
void SetUp() override {
m_tilt = new Servo(TestBench::kCameraTiltChannel);
m_pan = new Servo(TestBench::kCameraPanChannel);
m_spiAccel = new ADXL345_SPI(SPI::kOnboardCS1);
gyro.Reset();
m_tilt->Set(kTiltSetpoint45);
m_pan->SetAngle(0.0);
// Accumulator needs a small amount of time to reset before being tested
frc::Wait(1_ms);
Wait(kServoResetTime);
// Verify the gyro angle defaults to 0 immediately after being reset
EXPECT_NEAR(0.0, gyro.GetAngle(), 1.0);
m_gyro->Reset();
}
// Make sure that the gyro doesn't get jerked when the servo goes to zero.
m_pan.SetAngle(0.0);
frc::Wait(0.5_s);
gyro.Reset();
void DefaultGyroAngle();
void GyroAngle();
void GyroCalibratedParameters();
for (int32_t i = 0; i < 600; i++) {
m_pan.Set(i / 1000.0);
frc::Wait(1_ms);
}
void TearDown() override {
delete m_tilt;
delete m_pan;
delete m_spiAccel;
double gyroAngle = gyro.GetAngle();
EXPECT_NEAR(gyroAngle, 90.0, 10.0)
<< "Gyro measured " << gyroAngle
<< " degrees, servo should have turned 90 degrees";
}
};
AnalogGyro* TiltPanCameraTest::m_gyro = nullptr;
TEST_F(TiltPanCameraTest, Gyro) {
int cCenter;
double cOffset;
/**
* Test if the gyro angle defaults to 0 immediately after being reset.
*/
void TiltPanCameraTest::DefaultGyroAngle() {
EXPECT_NEAR(0.0, m_gyro->GetAngle(), 1.0);
}
{
frc::AnalogGyro gyro{TestBench::kCameraGyroChannel};
GyroTests(gyro);
/**
* Test if the servo turns 90 degrees and the gyroscope measures this angle
* Note servo on TestBench is not the same type of servo that servo class
* was designed for so setAngle is significantly off. This has been calibrated
* for the servo on the rig.
*/
void TiltPanCameraTest::GyroAngle() {
// Make sure that the gyro doesn't get jerked when the servo goes to zero.
m_pan->SetAngle(0.0);
Wait(0.5_s);
m_gyro->Reset();
for (int32_t i = 0; i < 600; i++) {
m_pan->Set(i / 1000.0);
Wait(1_ms);
// Gets calibrated parameters from previously calibrated gyro, allocates a
// new gyro with the given parameters for center and offset, and re-runs
// tests on the new gyro.
cCenter = gyro.GetCenter();
cOffset = gyro.GetOffset();
}
double gyroAngle = m_gyro->GetAngle();
EXPECT_NEAR(gyroAngle, kTestAngle, 10.0)
<< "Gyro measured " << gyroAngle << " degrees, servo should have turned "
<< kTestAngle << " degrees";
}
/**
* Gets calibrated parameters from previously calibrated gyro, allocates a new
* gyro with the given parameters for center and offset, and re-runs tests on
* the new gyro.
*/
void TiltPanCameraTest::GyroCalibratedParameters() {
uint32_t cCenter = m_gyro->GetCenter();
double cOffset = m_gyro->GetOffset();
delete m_gyro;
m_gyro = new AnalogGyro(TestBench::kCameraGyroChannel, cCenter, cOffset);
m_gyro->SetSensitivity(kSensitivity);
// Default gyro angle test
// Accumulator needs a small amount of time to reset before being tested
m_gyro->Reset();
Wait(1_ms);
EXPECT_NEAR(0.0, m_gyro->GetAngle(), 1.0);
// Gyro angle test
// Make sure that the gyro doesn't get jerked when the servo goes to zero.
m_pan->SetAngle(0.0);
Wait(0.5_s);
m_gyro->Reset();
for (int32_t i = 0; i < 600; i++) {
m_pan->Set(i / 1000.0);
Wait(1_ms);
}
double gyroAngle = m_gyro->GetAngle();
EXPECT_NEAR(gyroAngle, kTestAngle, 10.0)
<< "Gyro measured " << gyroAngle << " degrees, servo should have turned "
<< kTestAngle << " degrees";
}
/**
* Run all gyro tests in one function to make sure they are run in order.
*/
TEST_F(TiltPanCameraTest, TestAllGyroTests) {
DefaultGyroAngle();
GyroAngle();
GyroCalibratedParameters();
frc::AnalogGyro gyro{TestBench::kCameraGyroChannel, cCenter, cOffset};
GyroTests(gyro);
}
/**
@@ -151,21 +93,24 @@ TEST_F(TiltPanCameraTest, TestAllGyroTests) {
* camera rotates
*/
TEST_F(TiltPanCameraTest, SPIAccelerometer) {
m_tilt->Set(kTiltSetpoint0);
Wait(kTiltTime);
EXPECT_NEAR(-1.0, m_spiAccel->GetX(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel->GetY(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel->GetZ(), kAccelerometerTolerance);
static constexpr auto kTiltTime = 1_s;
static constexpr double kAccelerometerTolerance = 0.2;
m_tilt->Set(kTiltSetpoint45);
Wait(kTiltTime);
EXPECT_NEAR(-std::sqrt(0.5), m_spiAccel->GetX(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel->GetY(), kAccelerometerTolerance);
EXPECT_NEAR(std::sqrt(0.5), m_spiAccel->GetZ(), kAccelerometerTolerance);
m_tilt.Set(kTiltSetpoint0);
frc::Wait(kTiltTime);
EXPECT_NEAR(-1.0, m_spiAccel.GetX(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel.GetY(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel.GetZ(), kAccelerometerTolerance);
m_tilt->Set(kTiltSetpoint90);
Wait(kTiltTime);
EXPECT_NEAR(0.0, m_spiAccel->GetX(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel->GetY(), kAccelerometerTolerance);
EXPECT_NEAR(1.0, m_spiAccel->GetZ(), kAccelerometerTolerance);
m_tilt.Set(kTiltSetpoint45);
frc::Wait(kTiltTime);
EXPECT_NEAR(-std::sqrt(0.5), m_spiAccel.GetX(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel.GetY(), kAccelerometerTolerance);
EXPECT_NEAR(std::sqrt(0.5), m_spiAccel.GetZ(), kAccelerometerTolerance);
m_tilt.Set(kTiltSetpoint90);
frc::Wait(kTiltTime);
EXPECT_NEAR(0.0, m_spiAccel.GetX(), kAccelerometerTolerance);
EXPECT_NEAR(0.0, m_spiAccel.GetY(), kAccelerometerTolerance);
EXPECT_NEAR(1.0, m_spiAccel.GetZ(), kAccelerometerTolerance);
}