Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .wpilib/wpilib_preferences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"currentLanguage": "none",
"enableCppIntellisense": false,
"projectYear": "none",
"teamNumber": 1868
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package tagalong.subsystems.micro;

public class ElevatorConfigurationTests {}
public class ElevatorConfigurationTests {}
60 changes: 60 additions & 0 deletions src/test/java/tagalong/subsystems/micro/ElevatorUnitTests.java
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package tagalong.subsystems.micro;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
Expand Down
101 changes: 101 additions & 0 deletions src/test/java/tagalong/subsystems/micro/PivotUnitTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
96 changes: 96 additions & 0 deletions src/test/java/tagalong/subsystems/micro/RollerUnitTest.java
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Loading