diff --git a/.wpilib/wpilib_preferences.json b/.wpilib/wpilib_preferences.json new file mode 100644 index 0000000..fda3022 --- /dev/null +++ b/.wpilib/wpilib_preferences.json @@ -0,0 +1,6 @@ +{ + "currentLanguage": "none", + "enableCppIntellisense": false, + "projectYear": "none", + "teamNumber": 1868 +} \ No newline at end of file diff --git a/src/test/java/tagalong/subsystems/micro/ElevatorConfigurationTests.java b/src/test/java/tagalong/subsystems/micro/ElevatorConfigurationTests.java index 53550a1..b6c2040 100644 --- a/src/test/java/tagalong/subsystems/micro/ElevatorConfigurationTests.java +++ b/src/test/java/tagalong/subsystems/micro/ElevatorConfigurationTests.java @@ -1,3 +1,3 @@ package tagalong.subsystems.micro; -public class ElevatorConfigurationTests {} +public class ElevatorConfigurationTests {} \ No newline at end of file diff --git a/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java new file mode 100644 index 0000000..9cdaf15 --- /dev/null +++ b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java @@ -0,0 +1,60 @@ +package tagalong.subsystems.micro; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import tagalong.devices.Encoders; +import tagalong.devices.Motors; +import tagalong.measurements.Height; +import tagalong.subsystems.micro.Elevator; +import tagalong.subsystems.micro.confs.ElevatorConf; + +public class ElevatorUnitTests { + public double kTol = 2e-1; // stub + static final double kCANCoderDelayTime = 0.5; // stub + public ElevatorConf _elevatorConf; + public Elevator _elevator; + private final double _heightTolerance = 1.0; // stub + private final double _velocityTolerance = 1.0; // stub + + @BeforeEach + void setup() { + _elevator = new Elevator(_elevatorConf); + } + + @AfterEach + void shutdown() throws Exception { + _elevator.setBrakeMode(true); + } + + @Test + public void testHeight(Elevator elevator, double height) { + elevator.setElevatorHeight(height); + assertEquals(_heightTolerance, Math.abs(height - elevator.getElevatorHeightM())); + } + @Test + public void testVelocity(Elevator elevator, double velocity, boolean withFF) { + elevator.setElevatorVelocity(velocity, withFF); + assertEquals( + _velocityTolerance, Math.abs(Math.abs(velocity - elevator.getElevatorVelocityMPS())) + ); + } + @Test + public void testProfile(Elevator elevator, double height) { + elevator.setElevatorProfile(height); + assertEquals(_heightTolerance, Math.abs(elevator.getElevatorHeightM()) - height); + } + @Test + public void testProfileComplex( + Elevator elevator, + double height, + double goalVelocityMPS, + double maxVelocityMPS, + double maxAccelerationMPS2, + boolean setCurrentState + ) { + elevator.setElevatorProfile(height, goalVelocityMPS, maxVelocityMPS, maxAccelerationMPS2, true); + assertEquals(_heightTolerance, Math.abs(height - elevator.getElevatorHeightM())); + } +} \ No newline at end of file diff --git a/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java b/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java index fcfe507..8e41c77 100644 --- a/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java +++ b/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java @@ -1,5 +1,4 @@ package tagalong.subsystems.micro; - import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; diff --git a/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java b/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java new file mode 100644 index 0000000..dee6f30 --- /dev/null +++ b/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java @@ -0,0 +1,101 @@ +package tagalong.subsystems.micro; +import static org.junit.jupiter.api.Assertions.*; + +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Transform2d; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.util.Units; +import edu.wpi.first.wpilibj.RobotController; +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.simulation.ElevatorSim; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import java.nio.file.attribute.GroupPrincipal; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import tagalong.devices.Encoders; +import tagalong.devices.Motors; +import tagalong.measurements.Angle; +import tagalong.subsystems.micro.Pivot; +import tagalong.subsystems.micro.confs.PivotConf; + +// are we testing the endocer for pivot or the reefarm pivot itself... + +public class PivotUnitTest { + static final double kTol = 2e-1; // idk what these r for.... + static final double kCANCoderDelayTime = 0.5; // same here + public Pivot _pivot; + public PivotConf _pivotConf; + public final double powerTolerance = 1.0; // CHANGE + public final double velocityTolerance = 1.0; // change + public final double angleToleranceRot = 1.0; // change + + @BeforeEach + void setUp() { + _pivot = new Pivot(_pivotConf); + } + + @AfterEach + void shutdown() throws Exception { + _pivot.setBrakeMode(true); + } + + @Test + public void testPower(Pivot pivot, double power) { + pivot.setPivotPower(power); + assertEquals(powerTolerance, Math.abs(power - pivot.getPivotPower())); + } + + @Test + public void testVelocity(Pivot pivot, double velocity) { + pivot.setPivotVelocity(velocity, false); + assertEquals(velocityTolerance, Math.abs(Math.abs(velocity - pivot.getPivotVelocity()))); + } + + @Test + public void testProfileAngle(Pivot pivot, Angle goalPositionRot) { + pivot.setPivotProfile(goalPositionRot); + assertEquals( + angleToleranceRot, Math.abs(pivot.getPivotPosition() - goalPositionRot.getRotations()) + ); + } + + @Test + public void testProfileRot(Pivot pivot, double goalPositionRot) { + pivot.setPivotProfile(goalPositionRot); + assertEquals(angleToleranceRot, Math.abs(pivot.getPivotPosition() - goalPositionRot)); + } + + @Test + public void testProfileAngleComplex( + Pivot pivot, + Angle goalPositionRot, + double goalVelocityRPS, + double maxVelocityRPS, + double maxAccerlerationRPS2, + boolean setCurrentState + ) { + pivot.setPivotProfile( + goalPositionRot, goalVelocityRPS, maxVelocityRPS, maxAccerlerationRPS2, setCurrentState + ); + assertEquals( + angleToleranceRot, Math.abs(pivot.getPivotPosition() - goalPositionRot.getRotations()) + ); + } + + @Test + public void testProfileRotComplex( + Pivot pivot, + double goalPositionRot, + double goalVelocityRPS, + double maxVelocityRPS, + double maxAccerlerationRPS2, + boolean setCurrentState + ) { + pivot.setPivotProfile( + goalPositionRot, goalVelocityRPS, maxVelocityRPS, maxAccerlerationRPS2, setCurrentState + ); + assertEquals(angleToleranceRot, Math.abs(pivot.getPivotPosition() - goalPositionRot)); + } +} diff --git a/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java b/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java new file mode 100644 index 0000000..5716cb8 --- /dev/null +++ b/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java @@ -0,0 +1,96 @@ +package tagalong.subsystems.micro; +import static org.junit.jupiter.api.Assertions.*; + +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Transform2d; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.util.Units; +import edu.wpi.first.wpilibj.RobotController; +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.simulation.ElevatorSim; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import java.nio.file.attribute.GroupPrincipal; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import tagalong.devices.Encoders; +import tagalong.devices.Motors; +import tagalong.measurements.Angle; +import tagalong.subsystems.micro.Roller; +import tagalong.subsystems.micro.confs.RollerConf; + +public class RollerUnitTest { + static final double DELTA = 0.0; + public Roller _roller; + public RollerConf _rollerConf; + + public final double powerTolerance = 1.0; // change + public final double velocityTolerance = 1.0; // change + public final double rotationTolerance = 1.0; // change + public final double angleToleranceRot = 1.0; + + @BeforeEach + void setUp() { + _roller = new Roller(_rollerConf); + } + + @AfterEach + void shutdown() throws Exception { + _roller.setBrakeMode(true); // need for rollers? + } + + @Test + public void testPower(Roller roller, double power) { + roller.setRollerPower(power); + assertEquals(powerTolerance, Math.abs(roller.getRollerPower() - power)); + } + + @Test + public void testVelocity(Roller roller, double velocity) { + roller.setRollerVelocity(velocity, false); // change w/ FF? + assertEquals(velocityTolerance, Math.abs(roller.getRollerVelocity() - velocity)); + } + + @Test + public void testProfileRot(Roller roller, double goalPositionRot) { + roller.setRollerProfile(goalPositionRot); + assertEquals(rotationTolerance, Math.abs(roller.getRollerPosition()) - goalPositionRot); + } + + @Test + public void testProfileAngle(Roller roller, Angle goalAngle) { + roller.setRollerProfile(goalAngle); + assertEquals( + angleToleranceRot, Math.abs(roller.getRollerPosition() - goalAngle.getRotations()) + ); + } + + @Test + public void testProfileRotComplex( + Roller roller, + double goalPositionRot, + double goalVelocityMPS, + double maxVelocityMPS, + double maxAccelerationMPS2, + boolean setCurrentState + ) { + roller.setRollerProfile( + goalPositionRot, goalVelocityMPS, maxVelocityMPS, maxAccelerationMPS2, true + ); + assertEquals(rotationTolerance, Math.abs(goalPositionRot - roller.getRollerPosition())); + } + public void testProfileAngComplex( + Roller roller, + double goalPositionRot, + double goalVelocityMPS, + double maxVelocityMPS, + double maxAccelerationMPS2, + boolean setCurrentState + ) { + roller.setRollerProfile( + goalPositionRot, goalVelocityMPS, maxVelocityMPS, maxAccelerationMPS2, true + ); + assertEquals(rotationTolerance, Math.abs(goalPositionRot - roller.getRollerPosition())); + } +} \ No newline at end of file