2014-06-02 10:12:08 -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 <ADXL345_SPI.h>
|
2015-11-06 12:05:40 -08:00
|
|
|
#include <AnalogGyro.h>
|
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 <Servo.h>
|
|
|
|
|
#include <Timer.h>
|
2014-06-02 10:12:08 -04:00
|
|
|
#include "gtest/gtest.h"
|
2014-06-02 17:34:10 -04:00
|
|
|
#include "TestBench.h"
|
2014-06-02 10:12:08 -04:00
|
|
|
|
2014-07-31 15:46:14 -04:00
|
|
|
static constexpr double kServoResetTime = 2.0;
|
2014-07-17 15:43:25 -04:00
|
|
|
|
2015-05-18 11:56:49 -04:00
|
|
|
static constexpr double kTestAngle = 90.0;
|
2014-07-17 15:43:25 -04:00
|
|
|
|
2014-11-20 16:39:00 -05:00
|
|
|
static constexpr double kTiltSetpoint0 = 0.22;
|
|
|
|
|
static constexpr double kTiltSetpoint45 = 0.45;
|
|
|
|
|
static constexpr double kTiltSetpoint90 = 0.68;
|
2014-07-23 09:36:27 -04:00
|
|
|
static constexpr double kTiltTime = 1.0;
|
|
|
|
|
static constexpr double kAccelerometerTolerance = 0.2;
|
2014-07-17 15:43:25 -04:00
|
|
|
|
2014-06-07 17:37:51 -04:00
|
|
|
/**
|
|
|
|
|
* A fixture for the camera with two servos and a gyro
|
|
|
|
|
* @author Thomas Clark
|
|
|
|
|
*/
|
2014-06-02 10:12:08 -04:00
|
|
|
class TiltPanCameraTest : public testing::Test {
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2015-11-06 12:05:40 -08:00
|
|
|
static AnalogGyro *m_gyro;
|
2015-06-25 15:07:55 -04:00
|
|
|
Servo *m_tilt, *m_pan;
|
|
|
|
|
Accelerometer *m_spiAccel;
|
|
|
|
|
|
|
|
|
|
static void SetUpTestCase() {
|
|
|
|
|
// The gyro object blocks for 5 seconds in the constructor, so only
|
|
|
|
|
// construct it once for the whole test case
|
2015-11-06 12:05:40 -08:00
|
|
|
m_gyro = new AnalogGyro(TestBench::kCameraGyroChannel);
|
2015-06-25 15:07:55 -04:00
|
|
|
m_gyro->SetSensitivity(0.013);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void TearDownTestCase() { delete m_gyro; }
|
|
|
|
|
|
|
|
|
|
virtual void SetUp() override {
|
|
|
|
|
m_tilt = new Servo(TestBench::kCameraTiltChannel);
|
|
|
|
|
m_pan = new Servo(TestBench::kCameraPanChannel);
|
|
|
|
|
m_spiAccel = new ADXL345_SPI(SPI::kOnboardCS0);
|
|
|
|
|
|
|
|
|
|
m_tilt->Set(kTiltSetpoint45);
|
|
|
|
|
m_pan->SetAngle(0.0f);
|
|
|
|
|
|
|
|
|
|
Wait(kServoResetTime);
|
|
|
|
|
|
|
|
|
|
m_gyro->Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() override {
|
|
|
|
|
delete m_tilt;
|
|
|
|
|
delete m_pan;
|
|
|
|
|
delete m_spiAccel;
|
|
|
|
|
}
|
2014-06-02 10:12:08 -04:00
|
|
|
};
|
|
|
|
|
|
2015-11-06 12:05:40 -08:00
|
|
|
AnalogGyro *TiltPanCameraTest::m_gyro = nullptr;
|
2014-06-02 10:12:08 -04:00
|
|
|
|
2014-07-31 15:46:14 -04:00
|
|
|
/**
|
|
|
|
|
* Test if the gyro angle defaults to 0 immediately after being reset.
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(TiltPanCameraTest, DefaultGyroAngle) {
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_NEAR(0.0f, m_gyro->GetAngle(), 1.0f);
|
2014-07-31 15:46:14 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-02 10:12:08 -04:00
|
|
|
/**
|
2015-04-10 16:25:20 -04:00
|
|
|
* 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.
|
2014-06-02 10:12:08 -04:00
|
|
|
*/
|
|
|
|
|
TEST_F(TiltPanCameraTest, GyroAngle) {
|
2014-11-20 16:39:00 -05:00
|
|
|
// Make sure that the gyro doesn't get jerked when the servo goes to zero.
|
|
|
|
|
m_pan->SetAngle(0.0);
|
|
|
|
|
Wait(0.25);
|
|
|
|
|
m_gyro->Reset();
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
for (int i = 0; i < 600; i++) {
|
|
|
|
|
m_pan->Set(i / 1000.0);
|
|
|
|
|
Wait(0.001);
|
|
|
|
|
}
|
2014-07-23 09:36:27 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
double gyroAngle = m_gyro->GetAngle();
|
2014-07-23 09:36:27 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
EXPECT_NEAR(gyroAngle, kTestAngle, 10.0)
|
|
|
|
|
<< "Gyro measured " << gyroAngle << " degrees, servo should have turned "
|
|
|
|
|
<< kTestAngle << " degrees";
|
2014-06-02 10:12:08 -04:00
|
|
|
}
|
|
|
|
|
|
2014-07-17 15:43:25 -04:00
|
|
|
/**
|
|
|
|
|
* Test if the accelerometer measures gravity along the correct axes when the
|
|
|
|
|
* camera rotates
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(TiltPanCameraTest, SPIAccelerometer) {
|
2015-06-25 15:07:55 -04:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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(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);
|
2014-07-17 15:43:25 -04:00
|
|
|
}
|