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 "TestBench.h"
|
2014-06-02 10:12:08 -04:00
|
|
|
|
2014-06-07 17:37:51 -04:00
|
|
|
static constexpr double kResetTime = 1.0;
|
|
|
|
|
static constexpr double kTestAngle = 180.0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 {
|
2014-06-07 17:37:51 -04:00
|
|
|
protected:
|
|
|
|
|
Servo *m_tilt, *m_pan;
|
|
|
|
|
Gyro *m_gyro;
|
2014-06-02 10:12:08 -04:00
|
|
|
|
|
|
|
|
virtual void SetUp() {
|
2014-06-07 17:37:51 -04:00
|
|
|
m_tilt = new Servo(TestBench::kCameraTiltChannel);
|
|
|
|
|
m_pan = new Servo(TestBench::kCameraPanChannel);
|
|
|
|
|
m_gyro = new Gyro(TestBench::kCameraGyroChannel);
|
2014-06-02 10:12:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
2014-06-07 17:37:51 -04:00
|
|
|
delete m_tilt;
|
|
|
|
|
delete m_pan;
|
|
|
|
|
delete m_gyro;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
|
m_tilt->Set(0.0);
|
|
|
|
|
m_pan->Set(0.0);
|
|
|
|
|
|
|
|
|
|
Wait(kResetTime);
|
|
|
|
|
|
|
|
|
|
m_gyro->Reset();
|
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) {
|
2014-06-07 17:37:51 -04:00
|
|
|
Reset();
|
2014-06-02 10:12:08 -04:00
|
|
|
|
|
|
|
|
for(int i = 0; i < 100; i++) {
|
2014-06-07 17:37:51 -04:00
|
|
|
m_pan->Set(i / 100.0);
|
2014-06-02 10:12:08 -04:00
|
|
|
Wait(0.05);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-07 17:37:51 -04:00
|
|
|
double gyroAngle = m_gyro->GetAngle();
|
2014-06-02 10:12:08 -04:00
|
|
|
|
2014-06-07 17:37:51 -04:00
|
|
|
EXPECT_NEAR(gyroAngle, kTestAngle, 20.0) << "Gyro measured " << gyroAngle
|
|
|
|
|
<< " degrees, servo should have turned " << kTestAngle << " degrees";
|
2014-06-02 10:12:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|