use of me.wobblyyyy.pathfinder2.time.ElapsedTimer in project Pathfinder2 by Wobblyyyy.
the class TestMovementRecorder method testMovementRecorder.
public void testMovementRecorder() {
Pathfinder pf = Pathfinder.newSimulatedPathfinder(0.01);
SimulatedOdometry odometry = (SimulatedOdometry) pf.getOdometry();
Translation translation = new Translation(0.51, 0.51, 0);
odometry.setVelocity(Angle.DEG_45, 0.5);
odometry.setTranslation(translation);
pf.setTranslation(translation);
pf.getRecorder().start();
pf.tick();
ElapsedTimer timer = new ElapsedTimer(true);
while (timer.elapsedSeconds() < 2) pf.tick();
}
use of me.wobblyyyy.pathfinder2.time.ElapsedTimer in project Pathfinder2 by Wobblyyyy.
the class TestStatTracker method testTicksPerSecond.
public void testTicksPerSecond() {
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01).setSpeed(0.75).setTolerance(2).setAngleTolerance(Angle.fixedDeg(10));
pathfinder.loadPlugin(new StatTracker());
pathfinder.goTo(new PointXYZ(10, 10, 0));
pathfinder.splineTo(new PointXYZ(10, 10, 90), new PointXYZ(12, 11, 45), new PointXYZ(13, 15, 180));
ElapsedTimer timer = new ElapsedTimer(true);
SimulatedOdometry odometry = (SimulatedOdometry) pathfinder.getOdometry();
AtomicInteger i = new AtomicInteger(0);
try {
while (timer.elapsedSeconds() < 5) {
if (Math.random() > 0.5)
Thread.sleep(2);
pathfinder.tick();
Translation translation = pathfinder.getTranslation();
odometry.setRawPosition(odometry.getRawPosition().add(new PointXYZ(translation.vx() / 50, translation.vy() / 50, Angle.fixedRad(translation.vz() / 50))));
}
} catch (Exception ignored) {
}
pathfinder.tick();
System.out.println("tps: " + pathfinder.ticksPerSecond());
System.out.println("ticks: " + pathfinder.getData("pf_ticks"));
System.out.println("position: " + pathfinder.getPosition());
System.out.println("condition met: " + i.get());
System.out.println("total PointXY: " + PointXY.COUNT);
System.out.println("total PointXYZ: " + PointXYZ.COUNT);
System.out.println("total Angle: " + Angle.COUNT);
}
use of me.wobblyyyy.pathfinder2.time.ElapsedTimer in project Pathfinder2 by Wobblyyyy.
the class TestTaskTrajectory method testMaxTimeTaskTrajectory.
@Test
public void testMaxTimeTaskTrajectory() {
ElapsedTimer timer = new ElapsedTimer(true);
Trajectory trajectory = new TaskTrajectoryBuilder().setMaxTimeMs(10).setIsFinished(() -> false).build();
testTrajectory(trajectory, pathfinder.getPosition(), 100);
Assertions.assertTrue(timer.elapsedMs() < 10);
}
use of me.wobblyyyy.pathfinder2.time.ElapsedTimer in project Pathfinder2 by Wobblyyyy.
the class TestableRobot method testTrajectory.
public void testTrajectory(Trajectory trajectory, PointXYZ target, double maxTimeMs) {
if (!hasBeforeEachBeenCalled)
throw new RuntimeException("Did not call beforeEach method! Try super.beforeEach()?");
ValidationUtils.validate(trajectory, "trajectory");
ValidationUtils.validate(target, "target");
pathfinder.followTrajectory(trajectory);
ElapsedTimer timer = new ElapsedTimer(true);
pathfinder.tickUntil(maxTimeMs);
if (timer.elapsedMs() >= maxTimeMs)
throw new RuntimeException(StringUtils.format("Trajectory <%s> to target <%s> took <%s> milliseconds " + "to execute indicating there was an issue " + "following the trajectory.", trajectory, target, timer.elapsedMs()));
AssertionUtils.assertIsNear(target, pathfinder.getPosition(), tolerance, angleTolerance);
}
use of me.wobblyyyy.pathfinder2.time.ElapsedTimer in project Pathfinder2 by Wobblyyyy.
the class TestTimeCommands method testWaitCommand.
@Test
public void testWaitCommand() {
ElapsedTimer timer = new ElapsedTimer(true);
registry.execute("wait", "3");
Assertions.assertTrue(timer.elapsedMs() >= 3);
}
Aggregations