mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
Test bench fixes and updates. Attempting to make it possible to have a stable build again. Gyro test still seems a bit unreliable.
Change-Id: I0c140a5263048ff47ed1ec6b243e07baf43ec21e
This commit is contained in:
@@ -274,7 +274,7 @@ TEST_F(CANJaguarTest, SpeedModeWorks) {
|
||||
m_jaguar->SetSpeedMode(CANJaguar::QuadEncoder, 360, 0.1f, 0.003f, 0.01f);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
constexpr float speed = 60.0f;
|
||||
constexpr float speed = 50.0f;
|
||||
|
||||
SetJaguar(kMotorTime, speed);
|
||||
EXPECT_NEAR(speed, m_jaguar->GetSpeed(), kEncoderSpeedTolerance);
|
||||
|
||||
@@ -25,7 +25,8 @@ protected:
|
||||
m_outputA = new DigitalOutput(TestBench::kLoop2OutputChannel);
|
||||
m_outputB = new DigitalOutput(TestBench::kLoop1OutputChannel);
|
||||
m_indexOutput = new AnalogOutput(TestBench::kAnalogOutputChannel);
|
||||
|
||||
m_outputA->Set(false);
|
||||
m_outputB->Set(false);
|
||||
m_encoder = new Encoder(TestBench::kLoop1InputChannel, TestBench::kLoop2InputChannel);
|
||||
m_indexAnalogTrigger = new AnalogTrigger(TestBench::kFakeAnalogOutputChannel);
|
||||
m_indexAnalogTrigger->SetLimitsVoltage(2.0, 3.0);
|
||||
@@ -80,6 +81,7 @@ TEST_F(FakeEncoderTest, TestDefaultState) {
|
||||
* Test the encoder by setting the digital outputs and reading the value.
|
||||
*/
|
||||
TEST_F(FakeEncoderTest, TestCountUp) {
|
||||
m_encoder->Reset();
|
||||
Simulate100QuadratureTicks();
|
||||
|
||||
EXPECT_FLOAT_EQ(100.0f, m_encoder->Get())
|
||||
|
||||
@@ -70,7 +70,10 @@ TEST_F(TiltPanCameraTest, DefaultGyroAngle) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the servo turns 180 degrees and the gyroscope measures this angle
|
||||
* 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.
|
||||
*/
|
||||
TEST_F(TiltPanCameraTest, GyroAngle) {
|
||||
// Make sure that the gyro doesn't get jerked when the servo goes to zero.
|
||||
|
||||
@@ -20,84 +20,86 @@ import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
public class GyroTest extends AbstractComsSetup {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(GyroTest.class.getName());
|
||||
private static final Logger logger = Logger.getLogger(GyroTest.class.getName());
|
||||
|
||||
public static final double TEST_ANGLE = 90.0;
|
||||
public static final double TEST_ANGLE = 90.0;
|
||||
|
||||
private TiltPanCameraFixture tpcam;
|
||||
private TiltPanCameraFixture tpcam;
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger(){
|
||||
return logger;
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
logger.fine("Setup: TiltPan camera");
|
||||
tpcam = TestBench.getInstance().getTiltPanCam();
|
||||
tpcam.setup();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
logger.fine("Setup: TiltPan camera");
|
||||
tpcam = TestBench.getInstance().getTiltPanCam();
|
||||
tpcam.setup();
|
||||
}
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
tpcam.reset();
|
||||
tpcam.teardown();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
tpcam.reset();
|
||||
tpcam.teardown();
|
||||
}
|
||||
@Test
|
||||
public void testInitial() {
|
||||
double angle = tpcam.getGyro().getAngle();
|
||||
assertEquals(errorMessage(angle, 0), 0, angle, .5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitial(){
|
||||
double angle = tpcam.getGyro().getAngle();
|
||||
assertEquals(errorMessage(angle, 0), 0, angle, .5);
|
||||
}
|
||||
/**
|
||||
* Test to see if the Servo and the gyroscope is turning 90 degrees 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.
|
||||
*/
|
||||
@Test
|
||||
public void testGyroAngle() {
|
||||
//Set angle
|
||||
for (int i = 0; i < 5; i++) {
|
||||
tpcam.getPan().set(0);
|
||||
Timer.delay(.1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the Servo and the gyroscope is turning 180 degrees
|
||||
*/
|
||||
@Test
|
||||
public void testGyroAngle() {
|
||||
//Set angle
|
||||
for(int i = 0; i < 5; i++) {
|
||||
tpcam.getPan().setAngle(45);
|
||||
Timer.delay(.1);
|
||||
}
|
||||
Timer.delay(0.5);
|
||||
//Reset for setup
|
||||
tpcam.getGyro().reset();
|
||||
Timer.delay(0.5);
|
||||
|
||||
Timer.delay(0.5);
|
||||
//Reset for setup
|
||||
tpcam.getGyro().reset();
|
||||
Timer.delay(0.5);
|
||||
//Perform test
|
||||
for (int i = 0; i < 53; i++) {
|
||||
tpcam.getPan().set(i / 100.0);
|
||||
Timer.delay(0.05);
|
||||
}
|
||||
Timer.delay(1.2);
|
||||
|
||||
//Perform test
|
||||
for(int i = 450; i < 1420; i++) {
|
||||
tpcam.getPan().setAngle(i / 10.0);
|
||||
Timer.delay(0.005);
|
||||
}
|
||||
Timer.delay(.2);
|
||||
double angle = tpcam.getGyro().getAngle();
|
||||
|
||||
double angle = tpcam.getGyro().getAngle();
|
||||
double difference = TEST_ANGLE - angle;
|
||||
|
||||
double difference = TEST_ANGLE - angle;
|
||||
double diff = Math.abs(difference);
|
||||
|
||||
double diff = Math.abs(difference);
|
||||
assertEquals(errorMessage(diff, TEST_ANGLE), TEST_ANGLE, angle, 10);
|
||||
}
|
||||
|
||||
assertEquals(errorMessage(diff, TEST_ANGLE), TEST_ANGLE, angle, 4);
|
||||
}
|
||||
@Test
|
||||
public void testDeviationOverTime() {
|
||||
// Make sure that the test isn't influenced by any previous motions.
|
||||
Timer.delay(0.25);
|
||||
tpcam.getGyro().reset();
|
||||
Timer.delay(0.25);
|
||||
double angle = tpcam.getGyro().getAngle();
|
||||
assertEquals(errorMessage(angle, 0), 0, angle, .5);
|
||||
Timer.delay(5);
|
||||
angle = tpcam.getGyro().getAngle();
|
||||
assertEquals("After 5 seconds " + errorMessage(angle, 0), 0, angle, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeviationOverTime(){
|
||||
// Make sure that the test isn't influenced by any previous motions.
|
||||
Timer.delay(0.25);
|
||||
tpcam.getGyro().reset();
|
||||
Timer.delay(0.25);
|
||||
double angle = tpcam.getGyro().getAngle();
|
||||
assertEquals(errorMessage(angle, 0), 0, angle, .5);
|
||||
Timer.delay(5);
|
||||
angle = tpcam.getGyro().getAngle();
|
||||
assertEquals("After 5 seconds " + errorMessage(angle, 0), 0, angle, 1);
|
||||
}
|
||||
|
||||
private String errorMessage(double difference, double target){
|
||||
return "Gryo angle skewed " + difference + " deg away from target " + target;
|
||||
}
|
||||
private String errorMessage(double difference, double target) {
|
||||
return "Gyro angle skewed " + difference + " deg away from target " + target;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class CANDefaultTest extends AbstractCANTest{
|
||||
|
||||
@Test
|
||||
public void testPositionModeVerifiesOnBrownOut() {
|
||||
final double setpoint = 10.0;
|
||||
final double setpoint = 1.0;
|
||||
|
||||
//Given
|
||||
getME().getMotor().setPositionMode(CANJaguar.kQuadEncoder, 360, 10.0, 0.1, 0.0);
|
||||
|
||||
@@ -57,9 +57,9 @@ public class CANSpeedQuadEncoderModeTest extends AbstractCANTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRotateForwardSpeed() {
|
||||
double speed = 60.0f;
|
||||
double speed = 50.0f;
|
||||
double initialPosition = getME().getMotor().getPosition();
|
||||
setCANJaguar(kMotorTime, speed);
|
||||
setCANJaguar(2*kMotorTime, speed);
|
||||
assertEquals("The motor did not reach the required speed in speed mode", speed, getME().getMotor().getSpeed(), kEncoderSpeedTolerance);
|
||||
assertThat("The motor did not move forward in speed mode", getME().getMotor().getPosition(), is(greaterThan(initialPosition)));
|
||||
}
|
||||
@@ -70,9 +70,9 @@ public class CANSpeedQuadEncoderModeTest extends AbstractCANTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRotateReverseSpeed() {
|
||||
double speed = -60.0f;
|
||||
double speed = -50.0f;
|
||||
double initialPosition = getME().getMotor().getPosition();
|
||||
setCANJaguar(kMotorTime, speed);
|
||||
setCANJaguar(2*kMotorTime, speed);
|
||||
assertEquals("The motor did not reach the required speed in speed mode", speed, getME().getMotor().getSpeed(), kEncoderSpeedTolerance);
|
||||
assertThat("The motor did not move in reverse in speed mode", getME().getMotor().getPosition(), is(lessThan(initialPosition)));
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
/** The stopped value in volts */
|
||||
private static final double kStoppedValue = 0;
|
||||
/** The running value in volts */
|
||||
private static final double kRunningValue = 12;
|
||||
private static final double kRunningValue = 4;
|
||||
|
||||
private static final double kVoltageTolerance = .25;
|
||||
|
||||
@@ -110,7 +110,7 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
@Test
|
||||
public void testMaxOutputVoltagePositive(){
|
||||
//given
|
||||
double maxVoltage = 5;
|
||||
double maxVoltage = 3;
|
||||
|
||||
setupMotorVoltageForTest(kRunningValue, kWait);
|
||||
|
||||
@@ -155,7 +155,7 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
@Test
|
||||
public void testMaxOutputVoltageNegative(){
|
||||
//given
|
||||
double maxVoltage = 5;
|
||||
double maxVoltage = 3;
|
||||
|
||||
setupMotorVoltageForTest(-kRunningValue, kWait);
|
||||
final double fastSpeed = getME().getMotor().getSpeed();
|
||||
|
||||
Reference in New Issue
Block a user