Search in sources :

Example 6 with Pathfinder

use of net.minecraft.server.v1_16_R3.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);
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) Translation(me.wobblyyyy.pathfinder2.geometry.Translation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ElapsedTimer(me.wobblyyyy.pathfinder2.time.ElapsedTimer) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ) SimulatedOdometry(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)

Example 7 with Pathfinder

use of net.minecraft.server.v1_16_R3.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));
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) SimulatedDrive(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedDrive) SimulatedOdometry(me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry) TimedRobot(edu.wpi.first.wpilibj.TimedRobot) Robot(me.wobblyyyy.pathfinder2.robot.Robot)

Example 8 with Pathfinder

use of net.minecraft.server.v1_16_R3.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);
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) Translation(me.wobblyyyy.pathfinder2.geometry.Translation) SplineBuilderFactory(me.wobblyyyy.pathfinder2.trajectory.spline.SplineBuilderFactory) Trajectory(me.wobblyyyy.pathfinder2.trajectory.Trajectory) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ) AdvancedSplineTrajectoryBuilder(me.wobblyyyy.pathfinder2.trajectory.spline.AdvancedSplineTrajectoryBuilder)

Example 9 with Pathfinder

use of net.minecraft.server.v1_16_R3.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);
    });
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) HashMap(java.util.HashMap) Shifter(me.wobblyyyy.pathfinder2.utils.Shifter) ProportionalController(me.wobblyyyy.pathfinder2.control.ProportionalController) Controller(me.wobblyyyy.pathfinder2.control.Controller) ProportionalController(me.wobblyyyy.pathfinder2.control.ProportionalController)

Example 10 with Pathfinder

use of net.minecraft.server.v1_16_R3.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();
    }
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) Toggle(me.wobblyyyy.pathfinder2.utils.Toggle)

Aggregations

Pathfinder (me.wobblyyyy.pathfinder2.Pathfinder)17 PointXYZ (me.wobblyyyy.pathfinder2.geometry.PointXYZ)7 Translation (me.wobblyyyy.pathfinder2.geometry.Translation)5 SimulatedRobot (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot)5 SimulatedOdometry (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)4 Test (org.junit.jupiter.api.Test)4 ProportionalController (me.wobblyyyy.pathfinder2.control.ProportionalController)2 PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)2 Robot (me.wobblyyyy.pathfinder2.robot.Robot)2 SimulatedDrive (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedDrive)2 ElapsedTimer (me.wobblyyyy.pathfinder2.time.ElapsedTimer)2 SplineBuilderFactory (me.wobblyyyy.pathfinder2.trajectory.spline.SplineBuilderFactory)2 Shifter (me.wobblyyyy.pathfinder2.utils.Shifter)2 TimedRobot (edu.wpi.first.wpilibj.TimedRobot)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Controller (me.wobblyyyy.pathfinder2.control.Controller)1 Listener (me.wobblyyyy.pathfinder2.listening.Listener)1 ListenerMode (me.wobblyyyy.pathfinder2.listening.ListenerMode)1