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