use of net.minecraft.server.v1_15_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class TestStatTracker method testTicksPerSecond.
public void testTicksPerSecond() {
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01).setSpeed(0.75).setTolerance(2).setAngleTolerance(Angle.fixedDeg(10));
pathfinder.loadPlugin(new StatTracker());
pathfinder.goTo(new PointXYZ(10, 10, 0));
pathfinder.splineTo(new PointXYZ(10, 10, 90), new PointXYZ(12, 11, 45), new PointXYZ(13, 15, 180));
ElapsedTimer timer = new ElapsedTimer(true);
SimulatedOdometry odometry = (SimulatedOdometry) pathfinder.getOdometry();
AtomicInteger i = new AtomicInteger(0);
try {
while (timer.elapsedSeconds() < 5) {
if (Math.random() > 0.5)
Thread.sleep(2);
pathfinder.tick();
Translation translation = pathfinder.getTranslation();
odometry.setRawPosition(odometry.getRawPosition().add(new PointXYZ(translation.vx() / 50, translation.vy() / 50, Angle.fixedRad(translation.vz() / 50))));
}
} catch (Exception ignored) {
}
pathfinder.tick();
System.out.println("tps: " + pathfinder.ticksPerSecond());
System.out.println("ticks: " + pathfinder.getData("pf_ticks"));
System.out.println("position: " + pathfinder.getPosition());
System.out.println("condition met: " + i.get());
System.out.println("total PointXY: " + PointXY.COUNT);
System.out.println("total PointXYZ: " + PointXYZ.COUNT);
System.out.println("total Angle: " + Angle.COUNT);
}
use of net.minecraft.server.v1_15_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class ExampleTimedRobot method robotInit.
@Override
public void robotInit() {
// initialize everything. if this was a real implementation, you would
// not want to use SimulatedDrive or SimulatedOdometry
drive = new SimulatedDrive();
odometry = new SimulatedOdometry();
robot = new Robot(drive, odometry);
pathfinder = new Pathfinder(robot, controller).setSpeed(0.5).setTolerance(2).setAngleTolerance(Angle.fromDeg(5));
}
use of net.minecraft.server.v1_15_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class ExampleSpline method run.
public void run() {
// before anything else, we have to get some stuff set up.
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
// alright! trajectory time! let's see what's up.
// as you can see, this is mostly pretty self-explanatory.
// you create an AdvancedSplineTrajectoryBuilder and use the
// add methods provided by that class to construct a trajectory.
// this method works well, but it's a bit verbose - there's a
// solution to that problem you'll see in just a moment.
Trajectory trajectory1 = new AdvancedSplineTrajectoryBuilder().setSpeed(0.5).setStep(0.1).setTolerance(2).setAngleTolerance(Angle.fromDeg(5)).add(new PointXYZ(0, 0, 0)).add(new PointXYZ(4, 6, 0)).add(new PointXYZ(6, 12, 0)).add(new PointXYZ(8, 24, 0)).build();
Trajectory trajectory2 = new AdvancedSplineTrajectoryBuilder().setSpeed(0.5).setStep(0.1).setTolerance(2).setAngleTolerance(Angle.fromDeg(5)).add(new PointXYZ(8, 24, 0)).add(new PointXYZ(6, 36, 0)).add(new PointXYZ(4, 40, 0)).add(new PointXYZ(0, 42, 0)).build();
// thankfully, there's an easier way to create trajectories just like
// that - we can make use of a "SplineBuilderFactory"
SplineBuilderFactory factory = new SplineBuilderFactory().setSpeed(0.5).setStep(0.1).setTolerance(2).setAngleTolerance(Angle.fromDeg(5));
// set the default speed, step, tolerance, and angle tolerance
// values for the factory. all of the spline builders produced by
// the factory will have have these values by default.
// now we can create new trajectories, without having to repeat
// the same 4 lines for each of the trajectories.
Trajectory trajectory3 = factory.builder().add(0, 60, Angle.fromDeg(0)).add(new PointXYZ(20, 60, 0)).add(new PointXYZ(30, 60, 0)).add(new PointXYZ(40, 70, 0)).build();
Trajectory trajectory4 = factory.builder().add(new PointXYZ(40, 70, 0)).add(new PointXYZ(30, 60, 0)).add(new PointXYZ(20, 60, 0)).add(0, 60, Angle.fromDeg(0)).build();
// time to actually make the robot move now! once again, most of
// these methods are fairly self-explanatory. basically, follow
// the first two trajectories, come to a complete stop, and then
// follow the next two trajectories, but each of those trajectories
// should have an individual timeout of 10 seconds.
pathfinder.followTrajectories(trajectory1, trajectory2).andThen(pf -> {
// any other code you want to be executed after the
// trajectory is finished
pf.setTranslation(new Translation(0, 0, 0));
}).followTrajectory(trajectory3).tickUntil(10_000).followTrajectory(trajectory4).tickUntil(10_000);
}
use of net.minecraft.server.v1_15_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.
the class ExampleElevator method exampleShifterElevator.
public void exampleShifterElevator() {
Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
Map<Integer, Integer> levels = new HashMap<Integer, Integer>() {
{
put(1, 100);
put(2, 200);
put(3, 300);
put(4, 400);
put(5, 500);
}
};
Controller controller = new ProportionalController(0.001);
Shifter shifter = new Shifter(1, 1, 5, false, gear -> {
int target = levels.get(gear);
controller.setTarget(target);
});
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.onTick(pf -> {
int elevatorPosition = getPosition();
double elevatorPower = controller.calculate(elevatorPosition);
setElevatorPower(elevatorPower);
});
}
use of net.minecraft.server.v1_15_R1.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();
}
}
Aggregations