use of net.minecraft.server.v1_14_R1.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 net.minecraft.server.v1_14_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class ExampleListeners method exampleShifter.
@SuppressWarnings("InfiniteLoopStatement")
public void exampleShifter() {
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
Shifter shifter = new Shifter(1, 1, 5, false, s -> {
});
pathfinder.getListenerManager().bind(ListenerMode.CONDITION_NEWLY_MET, this::aButton, b -> b, b -> shifter.shift(ShifterDirection.UP));
pathfinder.getListenerManager().bind(ListenerMode.CONDITION_NEWLY_MET, this::bButton, b -> b, b -> shifter.shift(ShifterDirection.DOWN));
pathfinder.getListenerManager().bind(ListenerMode.CONDITION_NEWLY_MET, this::xButton, b -> b, b -> shifter.setGear(1));
pathfinder.getListenerManager().bind(ListenerMode.CONDITION_NEWLY_MET, this::yButton, b -> b, b -> shifter.setGear(5));
while (true) {
pathfinder.tick();
}
}
use of net.minecraft.server.v1_14_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class ExampleListeners method examplePositionListeners.
@SuppressWarnings({ "CodeBlock2Expr", "unchecked", "InfiniteLoopStatement" })
public void examplePositionListeners() {
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
Gamepad gamepad = new Gamepad();
// first up, some listeners for the robot's actual position. you can
// create listeners fairly easily:
// (also, notice how method chaining is used to make code more
// readable - you don't have to do this!)
pathfinder.addListener(new Listener(ListenerMode.CONDITION_NEWLY_MET, () -> {
// this will be executed ONCE whenever x exceeds 500.
// in order for this to be executed again, x will have to
// dip below 500 and then come back over 500 again
System.out.println("x crossed over 500!");
}, () -> {
return pathfinder.getPosition().x() > 500;
})).addListener(new Listener(// here's a nicer-looking way to do the same exact thing.
ListenerMode.CONDITION_NEWLY_MET, () -> System.out.println("y crossed over 500!"), () -> pathfinder.getPosition().y() > 500)).addListener(new Listener(ListenerMode.CONDITION_NEWLY_MET, () -> System.out.println("x AND y crossed over 500! wow!"), () -> {
PointXY position = pathfinder.getPosition();
return position.x() > 500 && position.y() > 500;
}));
// time for more listeners! this time, these listeners demonstrate
// how you could use listeners to bind functionality to a button.
pathfinder.addListener(new Listener(ListenerMode.CONDITION_NEWLY_MET, () -> {
System.out.println("the A button has been pressed!");
}, gamepad::a));
pathfinder.addListener(new Listener(ListenerMode.CONDITION_NEWLY_NOT_MET, () -> {
System.out.println("the A button has been released!");
}, gamepad::a));
// here's a more complex condition...
// notice how we make use of the oh-so-lovely lambda syntax available
// in java to make this code significantly more tolerable
pathfinder.addListener(new Listener(ListenerMode.CONDITION_NEWLY_MET, () -> System.out.println("the right and left joysticks have" + "magnitudes above 0.5!"), () -> gamepad.joysticks.right().getMagnitude() > 0.5 && gamepad.joysticks.left().getMagnitude() > 0.5));
// and here's an alternative way to have multiple preconditions.
pathfinder.addListener(new Listener(ListenerMode.CONDITION_NEWLY_NOT_MET, () -> {
System.out.println("the right and left joysticks have" + "magnitudes below 0.5!");
}, // precondition #1
() -> {
return gamepad.joysticks.right().getMagnitude() > 0.5;
}, // precondition #2
() -> {
return gamepad.joysticks.left().getMagnitude() > 0.5;
}));
// implementation, but yeah.
while (true) {
pathfinder.tick();
}
}
use of net.minecraft.server.v1_14_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class TestHeadingLock method testHeadingLockAlongLine.
@Test
public void testHeadingLockAlongLine() {
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
SimulatedRobot odometry = (SimulatedRobot) pathfinder.getOdometry();
pathfinder.loadBundledPlugins();
pathfinder.lockHeading(new PointXY(10, 10));
pathfinder.followTrajectory(new LinearTrajectory(new PointXYZ(0, 10, 0), 0.5, 2, Angle.fromDeg(5)));
odometry.setPosition(new PointXYZ(0, 0, 0));
pathfinder.tick();
Assertions.assertEquals(-0.45, pathfinder.getTranslation().vz());
odometry.setPosition(new PointXYZ(0, 0, 45));
pathfinder.tick();
Assertions.assertEquals(0, pathfinder.getTranslation().vz());
odometry.setPosition(new PointXYZ(0, 0, 90));
pathfinder.tick();
Assertions.assertEquals(0.45, pathfinder.getTranslation().vz());
odometry.setPosition(0, 5, 0);
pathfinder.tick();
Assertions.assertTrue(Equals.soft(-0.265, pathfinder.getTranslation().vz(), 0.01));
odometry.setPosition(5, 5, 0);
pathfinder.tick();
Assertions.assertTrue(Equals.soft(-0.45, pathfinder.getTranslation().vz(), 0.01));
}
use of net.minecraft.server.v1_14_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class ExampleRecording method init.
public void init() {
drive = new SimulatedDrive();
odometry = new SimulatedOdometry();
robot = new Robot(drive, odometry);
pathfinder = new Pathfinder(robot, 0.02);
}
Aggregations