Search in sources :

Example 16 with Pathfinder

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

the class Pathfinder method loadBundledPlugins.

/**
 * Load all of the plugins bundled with Pathfinder.
 * <p>
 * The plugins that will be loaded are (in order):
 * <ul>
 *     <li>{@link StatTracker}</li>
 *     <li>{@link PositionLocker}</li>
 * </ul>
 *
 * @return {@code this}, used for method chaining.
 */
public Pathfinder loadBundledPlugins() {
    pluginManager.loadPlugin(new StatTracker());
    pluginManager.loadPlugin(new PositionLocker());
    return this;
}
Also used : StatTracker(me.wobblyyyy.pathfinder2.plugin.bundled.StatTracker) PositionLocker(me.wobblyyyy.pathfinder2.plugin.bundled.PositionLocker)

Example 17 with Pathfinder

use of me.wobblyyyy.pathfinder2.Pathfinder 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 18 with Pathfinder

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

the class Pathfinder method followTrajectories.

/**
 * Follow multiple trajectories.
 *
 * @param trajectories a list of trajectories to follow.
 * @return this instance of Pathfinder, used for method chaining.
 */
public Pathfinder followTrajectories(List<Trajectory> trajectories) {
    if (trajectories == null)
        throw new NullPointerException("Cannot follow null trajectories!");
    List<Follower> followers = new ArrayList<>();
    for (Trajectory trajectory : trajectories) followers.add(generator.generate(robot, trajectory));
    follow(followers);
    return this;
}
Also used : Follower(me.wobblyyyy.pathfinder2.follower.Follower) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) TaskTrajectory(me.wobblyyyy.pathfinder2.trajectory.TaskTrajectory) LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)

Example 19 with Pathfinder

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

the class ListenerManager method tick.

/**
 * "Tick", or update, the listener manager once by ticking/updating
 * each of the listeners operated by the manager.
 */
@Override
public boolean tick(Pathfinder pathfinder) {
    List<String> expiredListeners = new ArrayList<String>(listeners.size());
    for (Map.Entry<String, Listener> entry : listeners.entrySet()) {
        String name = entry.getKey();
        Listener listener = entry.getValue();
        // remove expired listeners, tick non-expired listeners
        if (listener.hasExpired())
            expiredListeners.add(name);
        else
            listener.tick(pathfinder);
    }
    // actually remove the listener if it's expired
    for (String key : expiredListeners) listeners.remove(key);
    return true;
}
Also used : RandomString(me.wobblyyyy.pathfinder2.utils.RandomString)

Example 20 with Pathfinder

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

the class StatTracker method onTick.

@Override
public void onTick(Pathfinder pathfinder) {
    if (lastMs == 0)
        lastMs = Time.ms();
    ticks++;
    PointXYZ position = pathfinder.getPosition();
    if (lastPoint == null)
        lastPoint = position;
    totalDistance += lastPoint.absDistance(position);
    double currentMs = Time.ms();
    double elapsedSeconds = (currentMs - lastMs) / SECOND_MS_DURATION;
    if (elapsedSeconds < 1 / SECOND_MS_DURATION)
        return;
    lastMs = currentMs;
    double tps = 1 / elapsedSeconds;
    ticksPerSecond.add(tps);
    pathfinder.putData(KEY_TPS, ticksPerSecond.average());
    pathfinder.putData(KEY_TICKS, ticks);
}
Also used : PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ)

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