Search in sources :

Example 11 with Pathfinder

use of me.wobblyyyy.pathfinder2.Pathfinder in project Pathfinder2 by Wobblyyyy.

the class ExampleListeners method exampleToggleListeners.

public void exampleToggleListeners() {
    Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
    Toggle toggle = new Toggle();
    // bind the A button to toggling the toggle
    pathfinder.getListenerManager().bind(ListenerMode.CONDITION_NEWLY_MET, this::aButton, b -> b, b -> toggle.toggle());
    while (true) {
        pathfinder.tick();
    }
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) Toggle(me.wobblyyyy.pathfinder2.utils.Toggle)

Example 12 with Pathfinder

use of me.wobblyyyy.pathfinder2.Pathfinder in project Pathfinder2 by Wobblyyyy.

the class GenericTrajectoryBenchmarker method followTrajectories.

public void followTrajectories(Blackhole blackhole, Trajectory... trajectories) {
    SimulatedRobot robot = new SimulatedRobot();
    Pathfinder pathfinder = new Pathfinder(robot, -0.05);
    PointXYZ lastPosition = PointXYZ.ZERO;
    double distance = 0;
    for (Trajectory trajectory : trajectories) {
        robot.setPosition(PointXYZ.ZERO);
        pathfinder.followTrajectory(trajectory);
        while (distance < 10) {
            pathfinder.tick();
            distance += pathfinder.getPosition().absDistance(lastPosition);
        }
    }
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) SimulatedRobot(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ)

Example 13 with Pathfinder

use of me.wobblyyyy.pathfinder2.Pathfinder in project Pathfinder2 by Wobblyyyy.

the class Pathfinder method goTo.

/**
 * Go to a specific point. This method will create a new linear trajectory.
 *
 * @param point the target point to go to.
 * @return this instance of Pathfinder, used for method chaining.
 * @see #setSpeed(double)
 * @see #setTolerance(double)
 * @see #setAngleTolerance(Angle)
 */
public Pathfinder goTo(PointXYZ point) {
    NullPointException.throwIfInvalid("Attempted to navigate to a null point.", point);
    checkForMissingDefaultValues();
    followTrajectory(new LinearTrajectory(point, speed, tolerance, angleTolerance));
    return this;
}
Also used : LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)

Example 14 with Pathfinder

use of me.wobblyyyy.pathfinder2.Pathfinder in project Pathfinder2 by Wobblyyyy.

the class Pathfinder method moveFor.

/**
 * Move the robot in a certain direction for a certain amount of time.
 * This is a blocking method call, meaning it will block the current thread
 * until its execution has finished (whatever {@code timeoutMs} is).
 *
 * @param translation the translation that will be set to the robot.
 *                    This value may not be null.
 * @param timeoutMs   how long the robot should move for. This value is
 *                    represented in milliseconds and must be greater
 *                    than 0. This value may also not be infinite.
 * @return {@code this, used for method chaining}
 */
@SuppressWarnings("BusyWait")
public Pathfinder moveFor(Translation translation, double timeoutMs) {
    if (translation == null)
        throw new NullPointerException("Cannot use a null translation!");
    if (timeoutMs <= 0 || Double.isInfinite(timeoutMs) || timeoutMs == Double.MAX_VALUE)
        throw new IllegalArgumentException("Invalid timeout!");
    ElapsedTimer timer = new ElapsedTimer(true);
    setTranslation(translation);
    try {
        while (timer.isElapsedLessThan(timeoutMs)) Thread.sleep(Core.pathfinderWaitSleepTimeMs);
    } catch (Exception ignored) {
    }
    return this;
}
Also used : ElapsedTimer(me.wobblyyyy.pathfinder2.time.ElapsedTimer)

Example 15 with Pathfinder

use of me.wobblyyyy.pathfinder2.Pathfinder in project Pathfinder2 by Wobblyyyy.

the class Pathfinder method newEmptyPathfinder.

/**
 * Create a new, "empty" instance of Pathfinder.
 *
 * <p>
 * This is pretty much only useful for debugging or testing purposes.
 * </p>
 *
 * @param coefficient the coefficient to use for the turn controller.
 * @return a new instance of Pathfinder that makes use of both the
 * {@link EmptyDrive} and {@link EmptyOdometry} classes.
 */
public static Pathfinder newEmptyPathfinder(double coefficient) {
    Drive drive = new EmptyDrive();
    Odometry odometry = new EmptyOdometry();
    Robot robot = new Robot(drive, odometry);
    return new Pathfinder(robot, coefficient);
}
Also used : EmptyOdometry(me.wobblyyyy.pathfinder2.robot.simulated.EmptyOdometry) Drive(me.wobblyyyy.pathfinder2.robot.Drive) EmptyDrive(me.wobblyyyy.pathfinder2.robot.simulated.EmptyDrive) SimulatedDrive(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedDrive) EmptyOdometry(me.wobblyyyy.pathfinder2.robot.simulated.EmptyOdometry) Odometry(me.wobblyyyy.pathfinder2.robot.Odometry) SimulatedOdometry(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry) Robot(me.wobblyyyy.pathfinder2.robot.Robot) SimulatedRobot(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot) EmptyDrive(me.wobblyyyy.pathfinder2.robot.simulated.EmptyDrive)

Aggregations

Pathfinder (me.wobblyyyy.pathfinder2.Pathfinder)17 PointXYZ (me.wobblyyyy.pathfinder2.geometry.PointXYZ)14 Trajectory (me.wobblyyyy.pathfinder2.trajectory.Trajectory)7 Translation (me.wobblyyyy.pathfinder2.geometry.Translation)6 SimulatedRobot (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot)6 LinearTrajectory (me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)6 SimulatedOdometry (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)5 TaskTrajectory (me.wobblyyyy.pathfinder2.trajectory.TaskTrajectory)4 Test (org.junit.jupiter.api.Test)4 ProportionalController (me.wobblyyyy.pathfinder2.control.ProportionalController)3 Robot (me.wobblyyyy.pathfinder2.robot.Robot)3 SimulatedDrive (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedDrive)3 ElapsedTimer (me.wobblyyyy.pathfinder2.time.ElapsedTimer)3 SplineBuilderFactory (me.wobblyyyy.pathfinder2.trajectory.spline.SplineBuilderFactory)3 Angle (me.wobblyyyy.pathfinder2.geometry.Angle)2 PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)2 AdvancedSplineTrajectoryBuilder (me.wobblyyyy.pathfinder2.trajectory.spline.AdvancedSplineTrajectoryBuilder)2 RandomString (me.wobblyyyy.pathfinder2.utils.RandomString)2 Shifter (me.wobblyyyy.pathfinder2.utils.Shifter)2 TimedRobot (edu.wpi.first.wpilibj.TimedRobot)1