use of me.wobblyyyy.pathfinder2.utils.Shifter 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 me.wobblyyyy.pathfinder2.utils.Shifter 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 me.wobblyyyy.pathfinder2.utils.Shifter 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();
}
Aggregations