mirror of
https://github.com/Team4388/2022NoWayHome.git
synced 2026-06-09 00:38:05 -06:00
Upgrade to 2022
* Update license * Remove arcade drive * Correct indentation * Disable RobotGyro (new gyro is untested)
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package frc4388.mocks;
|
||||
|
||||
@@ -14,41 +11,41 @@ import com.ctre.phoenix.sensors.PigeonIMU;
|
||||
* Add your docs here.
|
||||
*/
|
||||
public class MockPigeonIMU extends PigeonIMU {
|
||||
public int m_deviceNumber;
|
||||
public double currentYaw;
|
||||
public double currentPitch;
|
||||
public double currentRoll;
|
||||
public int m_deviceNumber;
|
||||
public double currentYaw;
|
||||
public double currentPitch;
|
||||
public double currentRoll;
|
||||
|
||||
public MockPigeonIMU(int deviceNumber) {
|
||||
super(deviceNumber);
|
||||
m_deviceNumber = deviceNumber;
|
||||
}
|
||||
public MockPigeonIMU(int deviceNumber) {
|
||||
super(deviceNumber);
|
||||
m_deviceNumber = deviceNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode setYaw(double angleDeg) {
|
||||
currentYaw = angleDeg;
|
||||
return ErrorCode.OK;
|
||||
}
|
||||
@Override
|
||||
public ErrorCode setYaw(double angleDeg) {
|
||||
currentYaw = angleDeg;
|
||||
return ErrorCode.OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param currentPitch the Pitch to set
|
||||
*/
|
||||
public void setCurrentPitch(double currentPitch) {
|
||||
this.currentPitch = currentPitch;
|
||||
}
|
||||
/**
|
||||
* @param currentPitch the Pitch to set
|
||||
*/
|
||||
public void setCurrentPitch(double currentPitch) {
|
||||
this.currentPitch = currentPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param currentRoll the Roll to set
|
||||
*/
|
||||
public void setCurrentRoll(double currentRoll) {
|
||||
this.currentRoll = currentRoll;
|
||||
}
|
||||
/**
|
||||
* @param currentRoll the Roll to set
|
||||
*/
|
||||
public void setCurrentRoll(double currentRoll) {
|
||||
this.currentRoll = currentRoll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode getYawPitchRoll(double[] ypr_deg) {
|
||||
ypr_deg[0] = currentYaw;
|
||||
ypr_deg[1] = currentPitch;
|
||||
ypr_deg[2] = currentRoll;
|
||||
return ErrorCode.OK;
|
||||
}
|
||||
@Override
|
||||
public ErrorCode getYawPitchRoll(double[] ypr_deg) {
|
||||
ypr_deg[0] = currentYaw;
|
||||
ypr_deg[1] = currentPitch;
|
||||
ypr_deg[2] = currentRoll;
|
||||
return ErrorCode.OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package frc4388.robot.subsystems;
|
||||
|
||||
@@ -12,7 +9,7 @@ import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.*;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Spark;
|
||||
import frc4388.robot.Constants.LEDConstants;
|
||||
import frc4388.utility.LEDPatterns;
|
||||
|
||||
@@ -20,40 +17,40 @@ import frc4388.utility.LEDPatterns;
|
||||
* Add your docs here.
|
||||
*/
|
||||
public class LEDSubsystemTest {
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
// Arrange
|
||||
Spark ledController = mock(Spark.class);
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
// Arrange
|
||||
Spark ledController = mock(Spark.class);
|
||||
|
||||
// Act
|
||||
LED led = new LED(ledController);
|
||||
// Act
|
||||
LED led = new LED(ledController);
|
||||
|
||||
// Assert
|
||||
assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
}
|
||||
// Assert
|
||||
assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatterns() {
|
||||
// Arrange
|
||||
Spark ledController = mock(Spark.class);
|
||||
LED led = new LED(ledController);
|
||||
@Test
|
||||
public void testPatterns() {
|
||||
// Arrange
|
||||
Spark ledController = mock(Spark.class);
|
||||
LED led = new LED(ledController);
|
||||
|
||||
// Act
|
||||
led.setPattern(LEDPatterns.RAINBOW_RAINBOW);
|
||||
// Act
|
||||
led.setPattern(LEDPatterns.RAINBOW_RAINBOW);
|
||||
|
||||
// Assert
|
||||
assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
// Assert
|
||||
assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
|
||||
// Act
|
||||
led.setPattern(LEDPatterns.BLUE_BREATH);
|
||||
// Act
|
||||
led.setPattern(LEDPatterns.BLUE_BREATH);
|
||||
|
||||
// Assert
|
||||
assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
// Assert
|
||||
assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
|
||||
// Act
|
||||
led.setPattern(LEDPatterns.SOLID_BLACK);
|
||||
// Act
|
||||
led.setPattern(LEDPatterns.SOLID_BLACK);
|
||||
|
||||
// Assert
|
||||
assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
}
|
||||
// Assert
|
||||
assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-6
@@ -1,9 +1,6 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package frc4388.utility;
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package frc4388.utility;
|
||||
|
||||
@@ -15,90 +12,90 @@ import org.junit.*;
|
||||
* Add your docs here.
|
||||
*/
|
||||
public class RobotTimeUtilityTest {
|
||||
RobotTime robotTime = RobotTime.getInstance();
|
||||
RobotTime robotTime = RobotTime.getInstance();
|
||||
|
||||
@Test
|
||||
public void testUpdateTimes() {
|
||||
// Arrange
|
||||
long lastTime;
|
||||
robotTime.m_deltaTime = 0;
|
||||
robotTime.m_robotTime = 0;
|
||||
robotTime.m_lastRobotTime = 0;
|
||||
robotTime.m_frameNumber = 0;
|
||||
robotTime.endMatchTime();
|
||||
robotTime.m_lastMatchTime = 0;
|
||||
@Test
|
||||
public void testUpdateTimes() {
|
||||
// Arrange
|
||||
long lastTime;
|
||||
robotTime.m_deltaTime = 0;
|
||||
robotTime.m_robotTime = 0;
|
||||
robotTime.m_lastRobotTime = 0;
|
||||
robotTime.m_frameNumber = 0;
|
||||
robotTime.endMatchTime();
|
||||
robotTime.m_lastMatchTime = 0;
|
||||
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_deltaTime);
|
||||
assertEquals(0, robotTime.m_robotTime);
|
||||
assertEquals(0, robotTime.m_lastRobotTime);
|
||||
assertEquals(0, robotTime.m_frameNumber);
|
||||
lastTime = robotTime.m_robotTime;
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_deltaTime);
|
||||
assertEquals(0, robotTime.m_robotTime);
|
||||
assertEquals(0, robotTime.m_lastRobotTime);
|
||||
assertEquals(0, robotTime.m_frameNumber);
|
||||
lastTime = robotTime.m_robotTime;
|
||||
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
|
||||
// Assert
|
||||
assertEquals(true, robotTime.m_deltaTime > 0);
|
||||
assertEquals(true, robotTime.m_robotTime > 0);
|
||||
assertEquals(lastTime, robotTime.m_lastRobotTime);
|
||||
assertEquals(1, robotTime.m_frameNumber);
|
||||
lastTime = robotTime.m_robotTime;
|
||||
// Assert
|
||||
assertEquals(true, robotTime.m_deltaTime > 0);
|
||||
assertEquals(true, robotTime.m_robotTime > 0);
|
||||
assertEquals(lastTime, robotTime.m_lastRobotTime);
|
||||
assertEquals(1, robotTime.m_frameNumber);
|
||||
lastTime = robotTime.m_robotTime;
|
||||
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
|
||||
// Assert
|
||||
assertEquals(true, robotTime.m_deltaTime > 0);
|
||||
assertEquals(true, robotTime.m_robotTime > 0);
|
||||
assertEquals(lastTime, robotTime.m_lastRobotTime);
|
||||
assertEquals(2, robotTime.m_frameNumber);
|
||||
}
|
||||
// Assert
|
||||
assertEquals(true, robotTime.m_deltaTime > 0);
|
||||
assertEquals(true, robotTime.m_robotTime > 0);
|
||||
assertEquals(lastTime, robotTime.m_lastRobotTime);
|
||||
assertEquals(2, robotTime.m_frameNumber);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchTime() {
|
||||
// Arrange
|
||||
long lastTime;
|
||||
@Test
|
||||
public void testMatchTime() {
|
||||
// Arrange
|
||||
long lastTime;
|
||||
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_matchTime);
|
||||
assertEquals(0, robotTime.m_lastMatchTime);
|
||||
lastTime = robotTime.m_matchTime;
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_matchTime);
|
||||
assertEquals(0, robotTime.m_lastMatchTime);
|
||||
lastTime = robotTime.m_matchTime;
|
||||
|
||||
// Act
|
||||
robotTime.startMatchTime();
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
// Act
|
||||
robotTime.startMatchTime();
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
|
||||
// Assert
|
||||
assertEquals(true, robotTime.m_matchTime > 0);
|
||||
assertEquals(lastTime, robotTime.m_lastMatchTime);
|
||||
lastTime = robotTime.m_matchTime;
|
||||
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
robotTime.endMatchTime();
|
||||
// Assert
|
||||
assertEquals(true, robotTime.m_matchTime > 0);
|
||||
assertEquals(lastTime, robotTime.m_lastMatchTime);
|
||||
lastTime = robotTime.m_matchTime;
|
||||
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
robotTime.endMatchTime();
|
||||
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_matchTime);
|
||||
assertEquals(lastTime, robotTime.m_lastMatchTime);
|
||||
lastTime = robotTime.m_matchTime;
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_matchTime);
|
||||
assertEquals(lastTime, robotTime.m_lastMatchTime);
|
||||
lastTime = robotTime.m_matchTime;
|
||||
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
// Act
|
||||
wait(1);
|
||||
robotTime.updateTimes();
|
||||
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_matchTime);
|
||||
assertEquals(lastTime, robotTime.m_lastMatchTime);
|
||||
}
|
||||
// Assert
|
||||
assertEquals(0, robotTime.m_matchTime);
|
||||
assertEquals(lastTime, robotTime.m_lastMatchTime);
|
||||
}
|
||||
|
||||
private void wait(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
private void wait(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user