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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "WPILib.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
2014-06-02 17:34:10 -04:00
|
|
|
#include "fixtures/TiltPanCameraFixture.h"
|
|
|
|
|
#include "TestBench.h"
|
2014-06-02 10:12:08 -04:00
|
|
|
|
|
|
|
|
class TiltPanCameraTest : public testing::Test {
|
|
|
|
|
protected:
|
2014-06-02 17:34:10 -04:00
|
|
|
TiltPanCameraFixture *m_fixture;
|
2014-06-02 10:12:08 -04:00
|
|
|
|
|
|
|
|
virtual void SetUp() {
|
2014-06-02 17:34:10 -04:00
|
|
|
m_fixture = TestBench::GetTiltPanCamera();
|
2014-06-02 10:12:08 -04:00
|
|
|
|
2014-06-02 17:34:10 -04:00
|
|
|
m_fixture->SetUp();
|
2014-06-02 10:12:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
2014-06-02 17:34:10 -04:00
|
|
|
m_fixture->TearDown();
|
2014-06-02 10:12:08 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if the servo turns 180 degrees and the gyroscope measures this angle
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(TiltPanCameraTest, GyroAngle) {
|
|
|
|
|
const double TEST_ANGLE = 180.0;
|
|
|
|
|
|
2014-06-02 17:34:10 -04:00
|
|
|
m_fixture->Reset();
|
2014-06-02 10:12:08 -04:00
|
|
|
|
|
|
|
|
for(int i = 0; i < 100; i++) {
|
2014-06-02 17:34:10 -04:00
|
|
|
m_fixture->GetPan()->Set(i / 100.0);
|
2014-06-02 10:12:08 -04:00
|
|
|
Wait(0.05);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 17:34:10 -04:00
|
|
|
double gyroAngle = m_fixture->GetGyro()->GetAngle();
|
2014-06-02 10:12:08 -04:00
|
|
|
|
|
|
|
|
double error = std::abs(TEST_ANGLE - gyroAngle);
|
|
|
|
|
|
|
|
|
|
ASSERT_LE(error, 10.0) << "Gyro measured " << gyroAngle
|
|
|
|
|
<< " degrees, servo should have turned " << TEST_ANGLE << " degrees";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|