From f0039f3428c1d434be8885354b040d4dfbc433d2 Mon Sep 17 00:00:00 2001 From: Kristen Oh Date: Sun, 19 Jan 2025 17:58:08 -0800 Subject: [PATCH 1/6] not done --- .../micro/ElevatorConfigurationTests.java | 2 +- .../subsystems/micro/ElevatorUnitTests.java | 79 +++++++++++++++++++ .../subsystems/micro/PivotUnitTest.java | 63 +++++++++++++++ .../subsystems/micro/RollerUnitTest.java | 39 +++++++++ 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java create mode 100644 src/test/java/tagalong/subsystems/micro/PivotUnitTest.java create mode 100644 src/test/java/tagalong/subsystems/micro/RollerUnitTest.java 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..e4f59d0 --- /dev/null +++ b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java @@ -0,0 +1,79 @@ +package tagalong.subsystems.micro; +import static org.junit.jupiter.api.Assertions.*; + +import com.ctre.phoenix6.hardware.TalonFX; +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 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.subsystems.micro.Elevator; +import tagalong.subsystems.micro.confs.ElevatorConf; + +// a work in progress plspls ignore for now if u see this its kind of all over the place - caitlin + +// TODO: add values for instance variables +// TODO: make tolerance possible for over and under target pos +// TODO: fix methods +// TODO: figure out assertEquals logic +// TODO: test + +public class ElevatorUnitTests { + public double _tolerance = 0.0; // stub + public Elevator _elevator; + public ElevatorConf _elevatorConf; + private double _goalPosition; + private double _maxVelocityMPS; + + protected TalonFX _driveMotor; + public int _riveMotorID = 12; // stub + + public ElevatorUnitTests() {} + + @BeforeEach + void setup() { + _elevator = new Elevator(_elevatorConf); + } + + @AfterEach + void shutdown() throws Exception { + _elevator.setBrakeMode(true); + } + + @Test + void doesntWorkWhenClosed() { + _elevator.setBrakeMode(true); + _elevator.setElevatorProfile(_goalPosition, _maxVelocityMPS); + assertEquals( + _driveMotor.getPosition().getValueAsDouble(), Math.abs(_tolerance - _goalPosition) + ); + } + + @Test + void worksWhenOpen() { + _elevator.setElevatorProfile(_goalPosition, _maxVelocityMPS); + _elevator.setElevatorHeight(0.5); + assertEquals(_driveMotor.getPosition(), Math.abs(_tolerance - _goalPosition)); + } + + @Test + void retractTest() { + _elevator.setBrakeMode(true); + assertEquals(_driveMotor.getPosition(), Math.abs(_tolerance - _goalPosition)); + } + + @Test + void deployTest() { + _elevator.setElevatorProfile(_goalPosition, _maxVelocityMPS); + assertEquals(_driveMotor.getPosition(), Math.abs(_tolerance - _goalPosition)); + } +} \ No newline at end of file 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..ae84165 --- /dev/null +++ b/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java @@ -0,0 +1,63 @@ +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 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 double tolerance = 0.1; // CHANGE + public Angle angleTolerance = new Angle(0.0); + + @BeforeEach + void setUp() { + _pivot = new Pivot(_pivotConf); + } + + @AfterEach + void shutdown() throws Exception { + _pivot.setBrakeMode(true); + } + + @Test + public boolean testPower(Pivot pivot, double power) { + pivot.setPivotPower(power); + assertEquals(tolerance, Math.abs(Math.abs(power - pivot.getPivotPower()))); + } + + @Test + public boolean testVelocity(Pivot pivot, double velocity) { + pivot.setPivotVelocity(velocity, false); + assertEquals(tolerance, Math.abs(Math.abs(velocity - pivot.getPivotVelocity()))); + } + + @Test + public boolean testProfile(Pivot pivot, Angle goalPosition, double goalPositionRPS) { + pivot.setPivotProfile(goalPosition, goalPositionRPS); + if (pivot.getPivotPosition() == Math.abs(goalPosition - angleTolerance)) { + return true; + } else { + return false; + } + } +} 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..03cfa03 --- /dev/null +++ b/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java @@ -0,0 +1,39 @@ +package tagalong.subsystems.micro; +import static org.junit.jupiter.api.Assertions.*; + +import com.ctre.phoenix6.hardware.CANcoder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +// not sure which of these +import org.junit.jupiter.api.Test; +import tagalong.devices.Encoders; +import tagalong.devices.Motors; +import tagalong.measurements.*; +import tagalong.subsystems.micro.Pivot; +import tagalong.subsystems.micro.Roller; +import tagalong.subsystems.micro.confs.PivotConf; +import tagalong.subsystems.micro.confs.RollerConf; + +public class RollerUnitTest { + static final double DELTA = 0.0; + private Roller _roller; + public RollerConf rollerConf; + private static final Motors driveMotor = Motors.FALCON500_FOC; + private static final int driveMotorID = 12; + + static final double rollerSpeed = 0.3; // super super basic test value + public RollerUnitTest(){}; + + @BeforeEach + void setup() {} + + @AfterEach + void shutdown() throws Exception { + _roller.setBrakeMode(true); + } + + @Test + public void testRollers() { + assertEquals(0.0, driveMotor.getVelocity().getValueAsDouble(), DELTA); + } +} \ No newline at end of file From c6a730781bd75bcfc5a47329a95e92c1e6286ab2 Mon Sep 17 00:00:00 2001 From: Kristen Oh Date: Tue, 21 Jan 2025 18:06:29 -0800 Subject: [PATCH 2/6] started --- .wpilib/wpilib_preferences.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .wpilib/wpilib_preferences.json 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 From 26e07e6e612965908efed90f00f9b9a861362aa1 Mon Sep 17 00:00:00 2001 From: Kristen Oh Date: Tue, 21 Jan 2025 19:46:12 -0800 Subject: [PATCH 3/6] maybe done --- .../subsystems/micro/ElevatorUnitTests.java | 68 +++++-------------- .../micro/MicrosystemConfigurationTest.java | 1 - .../subsystems/micro/PivotUnitTest.java | 24 +++---- .../subsystems/micro/RollerUnitTest.java | 57 ++++++++++++---- 4 files changed, 70 insertions(+), 80 deletions(-) diff --git a/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java index e4f59d0..f7d3922 100644 --- a/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java +++ b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java @@ -1,79 +1,45 @@ package tagalong.subsystems.micro; import static org.junit.jupiter.api.Assertions.*; -import com.ctre.phoenix6.hardware.TalonFX; -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 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; -// a work in progress plspls ignore for now if u see this its kind of all over the place - caitlin - -// TODO: add values for instance variables -// TODO: make tolerance possible for over and under target pos -// TODO: fix methods -// TODO: figure out assertEquals logic -// TODO: test - public class ElevatorUnitTests { - public double _tolerance = 0.0; // stub - public Elevator _elevator; + public double kTol = 2e-1; // stub public ElevatorConf _elevatorConf; - private double _goalPosition; - private double _maxVelocityMPS; - protected TalonFX _driveMotor; - public int _riveMotorID = 12; // stub - - public ElevatorUnitTests() {} + private final double _heightTolerance = 1.0; // stub + private final double _velocityTolerance = 1.0; // stub @BeforeEach - void setup() { - _elevator = new Elevator(_elevatorConf); + void setup(Elevator elevator) { + elevator = new Elevator(_elevatorConf); } @AfterEach - void shutdown() throws Exception { - _elevator.setBrakeMode(true); - } - - @Test - void doesntWorkWhenClosed() { - _elevator.setBrakeMode(true); - _elevator.setElevatorProfile(_goalPosition, _maxVelocityMPS); - assertEquals( - _driveMotor.getPosition().getValueAsDouble(), Math.abs(_tolerance - _goalPosition) - ); + void shutdown(Elevator elevator) throws Exception { + elevator.setBrakeMode(true); } @Test - void worksWhenOpen() { - _elevator.setElevatorProfile(_goalPosition, _maxVelocityMPS); - _elevator.setElevatorHeight(0.5); - assertEquals(_driveMotor.getPosition(), Math.abs(_tolerance - _goalPosition)); + public void testHeight(Elevator elevator, double height) { + elevator.setElevatorHeight(height); + assertEquals(_heightTolerance, Math.abs(height - elevator.getElevatorHeightM())); } - @Test - void retractTest() { - _elevator.setBrakeMode(true); - assertEquals(_driveMotor.getPosition(), Math.abs(_tolerance - _goalPosition)); + public void testVelocity(Elevator elevator, double velocity, boolean withFF) { + elevator.setElevatorVelocity(velocity, withFF); + assertEquals(_velocityTolerance, Math.abs(velocity - elevator.getElevatorVelocityMPS())); } - @Test - void deployTest() { - _elevator.setElevatorProfile(_goalPosition, _maxVelocityMPS); - assertEquals(_driveMotor.getPosition(), Math.abs(_tolerance - _goalPosition)); + public void testProfile(Elevator elevator, double goalPosition, double goalVelocityMPS) { + elevator.setElevatorProfile(goalPosition, goalVelocityMPS); + assertEquals(_heightTolerance, Math.abs(goalPosition - 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..9767a1d 100644 --- a/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java +++ b/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; -import tagalong.subsystems.micro.confs.MicrosystemConf; public class MicrosystemConfigurationTest { @Test diff --git a/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java b/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java index ae84165..4859c2e 100644 --- a/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java +++ b/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java @@ -10,6 +10,7 @@ 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; @@ -26,8 +27,9 @@ public class PivotUnitTest { static final double kCANCoderDelayTime = 0.5; // same here public Pivot _pivot; public PivotConf _pivotConf; - public double tolerance = 0.1; // CHANGE - public Angle angleTolerance = new Angle(0.0); + public final double powerTolerance = 1.0; // CHANGE + public final double velocityTolerance = 1.0; // change + public final double angleToleranceDeg = 1.0; // change @BeforeEach void setUp() { @@ -40,24 +42,20 @@ void shutdown() throws Exception { } @Test - public boolean testPower(Pivot pivot, double power) { + public void testPower(Pivot pivot, double power) { pivot.setPivotPower(power); - assertEquals(tolerance, Math.abs(Math.abs(power - pivot.getPivotPower()))); + assertEquals(powerTolerance, Math.abs(power - pivot.getPivotPower())); } @Test - public boolean testVelocity(Pivot pivot, double velocity) { + public void testVelocity(Pivot pivot, double velocity) { pivot.setPivotVelocity(velocity, false); - assertEquals(tolerance, Math.abs(Math.abs(velocity - pivot.getPivotVelocity()))); + assertEquals(velocityTolerance, Math.abs(Math.abs(velocity - pivot.getPivotVelocity()))); } @Test - public boolean testProfile(Pivot pivot, Angle goalPosition, double goalPositionRPS) { - pivot.setPivotProfile(goalPosition, goalPositionRPS); - if (pivot.getPivotPosition() == Math.abs(goalPosition - angleTolerance)) { - return true; - } else { - return false; - } + public void testProfileAngle(Pivot pivot, Angle goalPosition) { + pivot.setPivotProfile(goalPosition); + assertEquals(angleToleranceDeg, Math.abs(pivot.getPivotPosition() - goalPosition.getDegrees())); } } diff --git a/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java b/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java index 03cfa03..ffb3810 100644 --- a/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java +++ b/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java @@ -1,39 +1,66 @@ package tagalong.subsystems.micro; import static org.junit.jupiter.api.Assertions.*; -import com.ctre.phoenix6.hardware.CANcoder; +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; -// not sure which of these import org.junit.jupiter.api.Test; import tagalong.devices.Encoders; import tagalong.devices.Motors; -import tagalong.measurements.*; -import tagalong.subsystems.micro.Pivot; +import tagalong.measurements.Angle; import tagalong.subsystems.micro.Roller; -import tagalong.subsystems.micro.confs.PivotConf; import tagalong.subsystems.micro.confs.RollerConf; public class RollerUnitTest { static final double DELTA = 0.0; - private Roller _roller; - public RollerConf rollerConf; - private static final Motors driveMotor = Motors.FALCON500_FOC; - private static final int driveMotorID = 12; + public Roller _roller; + public RollerConf _rollerConf; - static final double rollerSpeed = 0.3; // super super basic test value - public RollerUnitTest(){}; + public final double powerTolerance = 1.0; // change + public final double velocityTolerance = 1.0; // change + public final double rotationTolerance = 1.0; // change + public final double angleToleranceDeg = 1.0; @BeforeEach - void setup() {} + void setUp() { + _roller = new Roller(_rollerConf); + } @AfterEach void shutdown() throws Exception { - _roller.setBrakeMode(true); + _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 testRollers() { - assertEquals(0.0, driveMotor.getVelocity().getValueAsDouble(), DELTA); + public void testProfileAngle(Roller roller, Angle goalAngle) { + roller.setRollerProfile(goalAngle); + assertEquals(angleToleranceDeg, Math.abs(roller.getRollerPosition() - goalAngle.getDegrees())); } } \ No newline at end of file From 49a6c6c5f2657b95be1b1b038b029b077ee2c662 Mon Sep 17 00:00:00 2001 From: Kristen Oh Date: Tue, 21 Jan 2025 20:07:34 -0800 Subject: [PATCH 4/6] hopefully done --- .../subsystems/micro/ElevatorUnitTests.java | 18 ++++++- .../subsystems/micro/PivotUnitTest.java | 48 +++++++++++++++++-- .../subsystems/micro/RollerUnitTest.java | 34 ++++++++++++- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java index f7d3922..837edf2 100644 --- a/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java +++ b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java @@ -38,8 +38,22 @@ public void testVelocity(Elevator elevator, double velocity, boolean withFF) { assertEquals(_velocityTolerance, Math.abs(velocity - elevator.getElevatorVelocityMPS())); } @Test - public void testProfile(Elevator elevator, double goalPosition, double goalVelocityMPS) { - elevator.setElevatorProfile(goalPosition, goalVelocityMPS); + public void testProfile(Elevator elevator, double height) { + elevator.setElevatorProfile(height); + assertEquals(_heightTolerance, Math.abs(height - elevator.getElevatorHeightM())); + } + @Test + public void testProfileComplex( + Elevator elevator, + double goalPosition, + double goalVelocityMPS, + double maxVelocityMPS, + double maxAccelerationMPS2, + boolean setCurrentState + ) { + elevator.setElevatorProfile( + goalPosition, goalVelocityMPS, maxVelocityMPS, maxAccelerationMPS2, true + ); assertEquals(_heightTolerance, Math.abs(goalPosition - elevator.getElevatorHeightM())); } } \ No newline at end of file diff --git a/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java b/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java index 4859c2e..dee6f30 100644 --- a/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java +++ b/src/test/java/tagalong/subsystems/micro/PivotUnitTest.java @@ -29,7 +29,7 @@ public class PivotUnitTest { public PivotConf _pivotConf; public final double powerTolerance = 1.0; // CHANGE public final double velocityTolerance = 1.0; // change - public final double angleToleranceDeg = 1.0; // change + public final double angleToleranceRot = 1.0; // change @BeforeEach void setUp() { @@ -54,8 +54,48 @@ public void testVelocity(Pivot pivot, double velocity) { } @Test - public void testProfileAngle(Pivot pivot, Angle goalPosition) { - pivot.setPivotProfile(goalPosition); - assertEquals(angleToleranceDeg, Math.abs(pivot.getPivotPosition() - goalPosition.getDegrees())); + 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 index ffb3810..5716cb8 100644 --- a/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java +++ b/src/test/java/tagalong/subsystems/micro/RollerUnitTest.java @@ -28,7 +28,7 @@ public class RollerUnitTest { public final double powerTolerance = 1.0; // change public final double velocityTolerance = 1.0; // change public final double rotationTolerance = 1.0; // change - public final double angleToleranceDeg = 1.0; + public final double angleToleranceRot = 1.0; @BeforeEach void setUp() { @@ -61,6 +61,36 @@ public void testProfileRot(Roller roller, double goalPositionRot) { @Test public void testProfileAngle(Roller roller, Angle goalAngle) { roller.setRollerProfile(goalAngle); - assertEquals(angleToleranceDeg, Math.abs(roller.getRollerPosition() - goalAngle.getDegrees())); + 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 From 0c2d7a075822f13dd9f9111fd2875122186c5d15 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Wed, 22 Jan 2025 19:52:47 -0800 Subject: [PATCH 5/6] fix build issues --- .../tagalong/subsystems/micro/MicrosystemConfigurationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java b/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java index 9767a1d..8e41c77 100644 --- a/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java +++ b/src/test/java/tagalong/subsystems/micro/MicrosystemConfigurationTest.java @@ -1,8 +1,8 @@ package tagalong.subsystems.micro; - import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; +import tagalong.subsystems.micro.confs.MicrosystemConf; public class MicrosystemConfigurationTest { @Test From 9cab76d01d18730edcde3a4c36cbb04dbfe83baf Mon Sep 17 00:00:00 2001 From: Caitlin Date: Wed, 22 Jan 2025 20:02:52 -0800 Subject: [PATCH 6/6] trying to fix build issues: --- .../subsystems/micro/ElevatorUnitTests.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java index 837edf2..9cdaf15 100644 --- a/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java +++ b/src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java @@ -12,19 +12,20 @@ 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 elevator) { - elevator = new Elevator(_elevatorConf); + void setup() { + _elevator = new Elevator(_elevatorConf); } @AfterEach - void shutdown(Elevator elevator) throws Exception { - elevator.setBrakeMode(true); + void shutdown() throws Exception { + _elevator.setBrakeMode(true); } @Test @@ -35,25 +36,25 @@ public void testHeight(Elevator elevator, double height) { @Test public void testVelocity(Elevator elevator, double velocity, boolean withFF) { elevator.setElevatorVelocity(velocity, withFF); - assertEquals(_velocityTolerance, Math.abs(velocity - elevator.getElevatorVelocityMPS())); + assertEquals( + _velocityTolerance, Math.abs(Math.abs(velocity - elevator.getElevatorVelocityMPS())) + ); } @Test public void testProfile(Elevator elevator, double height) { elevator.setElevatorProfile(height); - assertEquals(_heightTolerance, Math.abs(height - elevator.getElevatorHeightM())); + assertEquals(_heightTolerance, Math.abs(elevator.getElevatorHeightM()) - height); } @Test public void testProfileComplex( Elevator elevator, - double goalPosition, + double height, double goalVelocityMPS, double maxVelocityMPS, double maxAccelerationMPS2, boolean setCurrentState ) { - elevator.setElevatorProfile( - goalPosition, goalVelocityMPS, maxVelocityMPS, maxAccelerationMPS2, true - ); - assertEquals(_heightTolerance, Math.abs(goalPosition - elevator.getElevatorHeightM())); + elevator.setElevatorProfile(height, goalVelocityMPS, maxVelocityMPS, maxAccelerationMPS2, true); + assertEquals(_heightTolerance, Math.abs(height - elevator.getElevatorHeightM())); } } \ No newline at end of file