mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Tilt pan camera test
Change-Id: I4496c9940a5da0bd78d90f1a5b4a9ebea6597336
This commit is contained in:
@@ -6,11 +6,12 @@ if [ $(which sshpass) ]
|
||||
then
|
||||
sshpass -p "" ssh admin@10.1.90.2 killall FRCUserProgram
|
||||
sshpass -p "" scp cmake/target/cmake/wpilibc/wpilibC++IntegrationTests/FRCUserProgram admin@10.1.90.2:/home/admin
|
||||
sshpass -p "" ssh admin@10.1.90.2 ./FRCUserProgram
|
||||
sshpass -p "" ssh admin@10.1.90.2 ./FRCUserProgram
|
||||
else
|
||||
ssh admin@10.1.90.2 killall FRCUserProgram
|
||||
scp cmake/target/cmake/wpilibc/wpilibC++IntegrationTests/FRCUserProgram admin@10.1.90.2:/home/admin
|
||||
ssh admin@10.1.90.2 ./FRCUserProgram
|
||||
ssh admin@10.1.90.2 ./FRCUserProgram
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
17
wpilibc/wpilibC++IntegrationTests/include/TestBench.h
Normal file
17
wpilibc/wpilibC++IntegrationTests/include/TestBench.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WPILib.h"
|
||||
#include "fixtures/TiltPanCameraFixture.h"
|
||||
|
||||
class TestBench {
|
||||
public:
|
||||
static TiltPanCameraFixture *GetTiltPanCamera();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Master interface for all test fixtures. This ensures that all test fixtures
|
||||
* have setup and teardown methods, to ensure that the tests run properly.
|
||||
*
|
||||
* Test fixtures should be modeled around the content of a test, rather than the
|
||||
* actual physical layout of the testing board. They should obtain references to
|
||||
* hardware from the {@link TestBench} class, which is a singleton. Testing
|
||||
* Fixtures are responsible for ensuring that the hardware is in an appropriate
|
||||
* state for the start of a test, and ensuring that future tests will not be
|
||||
* affected by the results of a test.
|
||||
*/
|
||||
class ITestFixture {
|
||||
public:
|
||||
/**
|
||||
* Performs any required setup for this fixture, ensuring that all fixture
|
||||
* elements are ready for testing.
|
||||
*
|
||||
* @return True if the fixture is ready for testing
|
||||
*/
|
||||
virtual bool SetUp() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Resets the fixture back to test start state. This should be called by the
|
||||
* test class in the test setup method to ensure that the hardware is in the
|
||||
* default state. This differs from {@link ITestFixture#setup()} as that is
|
||||
* called once, before the class is constructed, so it may need to start
|
||||
* sensors. This method should not have to start anything, just reset
|
||||
* sensors and ensure that motors are stopped.
|
||||
*
|
||||
* @return True if the fixture is ready for testing
|
||||
*/
|
||||
virtual bool Reset() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Performs any required teardown after use of the fixture, ensuring that
|
||||
* future tests will not run into conflicts.
|
||||
*
|
||||
* @return True if the teardown succeeded
|
||||
*/
|
||||
virtual bool TearDown() = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WPILib.h"
|
||||
#include "ITestFixture.h"
|
||||
|
||||
/**
|
||||
* A class to represent the camera with tilt and pan servos and a gyro
|
||||
*
|
||||
* @author Thomas Clark
|
||||
*/
|
||||
class TiltPanCameraFixture : public ITestFixture {
|
||||
public:
|
||||
TiltPanCameraFixture(Servo *tilt, Servo *pan, Gyro *gyro);
|
||||
|
||||
virtual bool SetUp();
|
||||
virtual bool Reset();
|
||||
virtual bool TearDown();
|
||||
|
||||
Gyro *GetGyro();
|
||||
Servo *GetTilt();
|
||||
Servo *GetPan();
|
||||
|
||||
protected:
|
||||
static const double RESET_TIME = 1.0;
|
||||
|
||||
Servo *m_tilt, *m_pan;
|
||||
Gyro *m_gyro;
|
||||
};
|
||||
18
wpilibc/wpilibC++IntegrationTests/src/TestBench.cpp
Normal file
18
wpilibc/wpilibC++IntegrationTests/src/TestBench.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "TestBench.h"
|
||||
|
||||
TiltPanCameraFixture *TestBench::GetTiltPanCamera() {
|
||||
Gyro *gyro = new Gyro(1);
|
||||
gyro->SetSensitivity(0.007);
|
||||
|
||||
Servo *tilt = new Servo(10),
|
||||
*pan = new Servo(9);
|
||||
|
||||
return new TiltPanCameraFixture(tilt, pan, gyro);
|
||||
}
|
||||
@@ -7,42 +7,21 @@
|
||||
|
||||
#include "WPILib.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "fixtures/TiltPanCameraFixture.h"
|
||||
#include "TestBench.h"
|
||||
|
||||
/**
|
||||
* A class to represent the camera with tilt and pan servos and a gyro
|
||||
*
|
||||
* @author Thomas Clark
|
||||
*/
|
||||
class TiltPanCameraTest : public testing::Test {
|
||||
protected:
|
||||
Servo *m_tilt, *m_pan;
|
||||
Gyro *m_gyro;
|
||||
|
||||
static const double RESET_TIME = 1.0;
|
||||
TiltPanCameraFixture *m_fixture;
|
||||
|
||||
virtual void SetUp() {
|
||||
m_gyro = new Gyro(1);
|
||||
m_gyro->SetSensitivity(0.007);
|
||||
m_fixture = TestBench::GetTiltPanCamera();
|
||||
|
||||
Wait(RESET_TIME);
|
||||
|
||||
m_tilt = new Servo(10);
|
||||
m_pan = new Servo(9);
|
||||
m_fixture->SetUp();
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
delete m_tilt;
|
||||
delete m_pan;
|
||||
delete m_gyro;
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
m_tilt->SetAngle(0.0);
|
||||
m_pan->SetAngle(0.0);
|
||||
|
||||
Wait(RESET_TIME);
|
||||
|
||||
m_gyro->Reset();
|
||||
m_fixture->TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -53,14 +32,14 @@ protected:
|
||||
TEST_F(TiltPanCameraTest, GyroAngle) {
|
||||
const double TEST_ANGLE = 180.0;
|
||||
|
||||
Reset();
|
||||
m_fixture->Reset();
|
||||
|
||||
for(int i = 0; i < 100; i++) {
|
||||
m_pan->Set(i / 100.0);
|
||||
m_fixture->GetPan()->Set(i / 100.0);
|
||||
Wait(0.05);
|
||||
}
|
||||
|
||||
double gyroAngle = m_gyro->GetAngle();
|
||||
double gyroAngle = m_fixture->GetGyro()->GetAngle();
|
||||
|
||||
double error = std::abs(TEST_ANGLE - gyroAngle);
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "fixtures/TiltPanCameraFixture.h"
|
||||
|
||||
TiltPanCameraFixture::TiltPanCameraFixture(Servo *tilt, Servo *pan, Gyro *gyro):
|
||||
m_tilt(tilt),
|
||||
m_pan(pan),
|
||||
m_gyro(gyro) {
|
||||
}
|
||||
|
||||
bool TiltPanCameraFixture::SetUp() {
|
||||
return Reset();
|
||||
}
|
||||
|
||||
bool TiltPanCameraFixture::Reset() {
|
||||
m_tilt->Set(0.0);
|
||||
m_pan->Set(0.0);
|
||||
|
||||
Wait(RESET_TIME);
|
||||
|
||||
m_gyro->Reset();
|
||||
|
||||
return m_pan->Get() == 0.0 and m_tilt->Get() == 0.0 and m_gyro->GetAngle() == 0.0;
|
||||
}
|
||||
|
||||
bool TiltPanCameraFixture::TearDown() {
|
||||
return Reset();
|
||||
}
|
||||
|
||||
Gyro *TiltPanCameraFixture::GetGyro() {
|
||||
return m_gyro;
|
||||
}
|
||||
|
||||
Servo *TiltPanCameraFixture::GetTilt() {
|
||||
return m_tilt;
|
||||
}
|
||||
|
||||
Servo *TiltPanCameraFixture::GetPan() {
|
||||
return m_pan;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user