Search in sources :

Example 1 with ElapsedTimer

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();
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) Translation(me.wobblyyyy.pathfinder2.geometry.Translation) ElapsedTimer(me.wobblyyyy.pathfinder2.time.ElapsedTimer) SimulatedOdometry(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)

Example 2 with ElapsedTimer

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);
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) Translation(me.wobblyyyy.pathfinder2.geometry.Translation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ElapsedTimer(me.wobblyyyy.pathfinder2.time.ElapsedTimer) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ) SimulatedOdometry(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)

Example 3 with ElapsedTimer

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);
}
Also used : ElapsedTimer(me.wobblyyyy.pathfinder2.time.ElapsedTimer) Test(org.junit.jupiter.api.Test)

Example 4 with ElapsedTimer

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);
}
Also used : ElapsedTimer(me.wobblyyyy.pathfinder2.time.ElapsedTimer)

Example 5 with ElapsedTimer

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);
}
Also used : ElapsedTimer(me.wobblyyyy.pathfinder2.time.ElapsedTimer) Test(org.junit.jupiter.api.Test)

Aggregations

ElapsedTimer (me.wobblyyyy.pathfinder2.time.ElapsedTimer)9 Test (org.junit.jupiter.api.Test)3 Pathfinder (me.wobblyyyy.pathfinder2.Pathfinder)2 PointXYZ (me.wobblyyyy.pathfinder2.geometry.PointXYZ)2 Translation (me.wobblyyyy.pathfinder2.geometry.Translation)2 SimulatedOdometry (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MultiSegmentTrajectory (me.wobblyyyy.pathfinder2.trajectory.multi.segment.MultiSegmentTrajectory)1