Search in sources :

Example 1 with TaskTrajectoryBuilder

use of me.wobblyyyy.pathfinder2.trajectory.TaskTrajectoryBuilder 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 2 with TaskTrajectoryBuilder

use of me.wobblyyyy.pathfinder2.trajectory.TaskTrajectoryBuilder in project Pathfinder2 by Wobblyyyy.

the class Pathfinder method task.

/**
 * Create a new {@link TaskTrajectory} and add it to Pathfinder's
 * queue so that it can be executed
 *
 * @param initial    code to be executed the first time the trajectory's
 *                   {@code #isDone(PointXYZ)} method is called.
 * @param during     code to be executed any time the trajectory's
 *                   {@code #isDone(PointXYZ)} method is called.
 * @param onFinish   code to be executed whenever the task is finished.
 * @param isFinished a supplier that indicates if the task is finished.
 *                   If the task is not finished, it should continue stop
 *                   its execution.
 * @param minTimeMs  the minimum time, in milliseconds, the trajectory
 *                   will be active for.
 * @param maxTimeMs  the maximum time, in milliseconds, the trajectory
 *                   will be active for.
 * @return {@code this}, used for method chaining.
 */
public Pathfinder task(Runnable initial, Runnable during, Runnable onFinish, Supplier<Boolean> isFinished, double minTimeMs, double maxTimeMs) {
    Trajectory trajectory = new TaskTrajectoryBuilder().setInitial(initial).setDuring(during).setOnFinish(onFinish).setIsFinished(isFinished).setMinTimeMs(minTimeMs).setMaxTimeMs(maxTimeMs).build();
    followTrajectory(trajectory);
    return this;
}
Also used : Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) TaskTrajectory(me.wobblyyyy.pathfinder2.trajectory.TaskTrajectory) LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) TaskTrajectoryBuilder(me.wobblyyyy.pathfinder2.trajectory.TaskTrajectoryBuilder)

Example 3 with TaskTrajectoryBuilder

use of me.wobblyyyy.pathfinder2.trajectory.TaskTrajectoryBuilder in project Pathfinder2 by Wobblyyyy.

the class TestTaskTrajectory method testMinTimeTaskTrajectory.

@Test
public void testMinTimeTaskTrajectory() {
    ElapsedTimer timer = new ElapsedTimer(true);
    Trajectory trajectory = new TaskTrajectoryBuilder().setMinTimeMs(10).setIsFinished(() -> timer.elapsedMs() > 10).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)

Aggregations

ElapsedTimer (me.wobblyyyy.pathfinder2.time.ElapsedTimer)2 Test (org.junit.jupiter.api.Test)2 LinearTrajectory (me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)1 TaskTrajectory (me.wobblyyyy.pathfinder2.trajectory.TaskTrajectory)1 TaskTrajectoryBuilder (me.wobblyyyy.pathfinder2.trajectory.TaskTrajectoryBuilder)1 Trajectory (me.wobblyyyy.pathfinder2.trajectory.Trajectory)1