Search in sources :

Example 16 with Pathfinder

use of net.minecraft.server.v1_14_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.

the class ExampleTeleOp method exampleTeleOpListeners.

@SuppressWarnings("deprecation")
public void exampleTeleOpListeners() {
    Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
    AtomicReference<Double> multiplier = new AtomicReference<>(0.5);
    Shifter shifter = new Shifter(1, 1, 5, false, i -> {
    });
    Joystick right = new Joystick(() -> 0d, () -> 0d);
    Joystick left = new Joystick(() -> 0d, () -> 0d);
    Button a = new Button(() -> false);
    Button b = new Button(() -> false);
    Button rightBumper = new Button(() -> false);
    Button leftBumper = new Button(() -> false);
    // bind the following controls:
    // a button       -> shift elevator up a gear
    // b button       -> shift elevator down a gear
    // right bumper   -> set the multiplier to 1.0 (full speed)
    // left bumper    -> set the multiplier to 0.25 (slowest speed)
    // neither bumper -> set the multiplier to 0.5 (normal speed)
    pathfinder.getListenerManager().bind(// whenever the right bumper is pressed (even if held)...
    ListenerMode.CONDITION_IS_MET, rightBumper::isPressed, isPressed -> isPressed, isPressed -> multiplier.set(1.0)).bind(// whenever the left bumper is pressed (even if held)...
    ListenerMode.CONDITION_IS_MET, leftBumper::isPressed, isPressed -> isPressed, isPressed -> multiplier.set(0.25)).bind(// whenever neither bumper is pressed...
    ListenerMode.CONDITION_IS_NOT_MET, () -> SupplierFilter.anyTrue(rightBumper::isPressed, leftBumper::isPressed), isPressed -> isPressed, isPressed -> multiplier.set(0.5)).bind(// whenever the a button is initially pressed...
    ListenerMode.CONDITION_NEWLY_MET, () -> SupplierFilter.trueThenAllTrue(// a must be pressed
    a::isPressed, // a must NOT be pressed
    b::isPressed), isPressed -> isPressed, isPressed -> shifter.shift(ShifterDirection.UP)).bind(// whenever the b button is initially pressed...
    ListenerMode.CONDITION_NEWLY_MET, () -> SupplierFilter.trueThenAllTrue(// b must be pressed
    a::isPressed, // a must NOT be pressed
    b::isPressed), isPressed -> isPressed, isPressed -> shifter.shift(ShifterDirection.DOWN));
    pathfinder.onTick(pf -> {
        double m = multiplier.get();
        double vertical = right.getX();
        double horizontal = right.getY();
        double turn = left.getX();
        Translation translation = new Translation(vertical * m, horizontal * m, turn * m);
        pf.setTranslation(translation);
    }).onTick(pf -> {
    // some magic code that updates the elevator based on
    // what level it's currently on and what level it's
    // trying to get to
    });
    while (true) pathfinder.tick();
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) me.wobblyyyy.pathfinder2.utils(me.wobblyyyy.pathfinder2.utils) ListenerMode(me.wobblyyyy.pathfinder2.listening.ListenerMode) Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Translation(me.wobblyyyy.pathfinder2.geometry.Translation) Translation(me.wobblyyyy.pathfinder2.geometry.Translation) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 17 with Pathfinder

use of net.minecraft.server.v1_14_R1.Pathfinder in project Pathfinder2 by Wobblyyyy.

the class ExampleSplineTo method run.

public void run() {
    Pathfinder pathfinder = Pathfinder.newSimulatedPathfinder(0.01);
    pathfinder.setSpeed(0.5).setTolerance(2).setAngleTolerance(Angle.fromDeg(5)).splineTo(new PointXYZ(0, 10, 0), new PointXYZ(5, 15, 0), new PointXYZ(10, 25, 0)).tickUntil(10_000).splineTo(new PointXYZ(20, 15, 0), new PointXYZ(25, 10, 0), new PointXYZ(30, 5, 0)).tickUntil(10_000);
}
Also used : Pathfinder(me.wobblyyyy.pathfinder2.Pathfinder) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ)

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