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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations