def handle_shooter_inputs( self, joystick: wpilib.Joystick, gamepad: wpilib.XboxController ) -> None: if joystick.getTrigger(): self.shooter_controller.fire_input() if gamepad.getBackButton() and gamepad.getRawButtonPressed(5): # Disable turret in case of catastrophic malfunction # Make this toggle to allow re-enabling turret in case it was accidentally disabled self.shooter.disabled = not self.shooter.disabled self.turret.disabled = self.shooter.disabled
def handle_shooter_inputs(self, joystick: wpilib.Joystick, gamepad: wpilib.XboxController) -> None: if joystick.getTrigger(): self.shooter_controller.fire_input() if gamepad.getBackButton() and gamepad.getBumperPressed( Hand.kLeftHand): # Disable turret in case of catastrophic malfunction # Make this toggle to allow re-enabling turret in case it was accidentally disabled self.shooter.toggle() self.turret.toggle() # Hold to stay in manual aiming mode if gamepad.getXButton(): self.shooter_controller.manual_slew( rescale_js(gamepad.getX(Hand.kLeftHand), 0.1) * -self.MANUAL_SLEW_SPEED)
class _OI: def __init__(self): self.drive_gamepad = XboxController(0) self.op_gamepad = XboxController(1) self._action_listeners = [] self._while_listeners = [] self.arm_toggle = LambdaDebouncer( lambda: self.op_gamepad.getTriggerAxis(XboxController.Hand.kRight ) > 0.75) # Utility def exec_while_condition(self, condition: Callable, cmd: Command): self._while_listeners.append((condition, cmd)) def update(self): for condition, action in self._action_listeners: if condition(): action() for condition, command in self._while_listeners: command = typing.cast(Command, command) cond_result = condition() if cond_result: if command.isRunning(): pass else: command.start() else: command.cancel() def add_action_listener(self, condition, action): self._action_listeners.append((condition, action)) # OpDrive def get_left_power(self): return -self.drive_gamepad.getY(XboxController.Hand.kLeft) def get_right_power(self): return -self.drive_gamepad.getY(XboxController.Hand.kRight) def get_turn_command(self): return -self.drive_gamepad.getX(XboxController.Hand.kRight) def get_fine_left_turn(self): return self.drive_gamepad.getXButton() def get_fine_right_turn(self): return self.drive_gamepad.getBButton() def get_fine_forward(self): return self.drive_gamepad.getPOV() == 0 def get_fine_backward(self): return self.drive_gamepad.getPOV() == -180 def get_spot_turn(self): return self.drive_gamepad.getBumper(XboxController.Hand.kLeft) # Intake def intake_is_active(self): return self.op_gamepad.getBumper(XboxController.Hand.kRight) def get_outtake_command(self): return self.op_gamepad.getY(XboxController.Hand.kRight) def toggle_arm(self): return self.arm_toggle def arm_is_open(self): return self.op_gamepad.getBumper(XboxController.Hand.kLeft) def rumble_op(self): rumble_val = 1 self.op_gamepad.setRumble(XboxController.RumbleType.kLeftRumble, rumble_val) self.op_gamepad.setRumble(XboxController.RumbleType.kRightRumble, rumble_val) def unrumble_op(self): self.op_gamepad.setRumble(XboxController.RumbleType.kLeftRumble, 0) self.op_gamepad.setRumble(XboxController.RumbleType.kRightRumble, 0) # Elevator def get_elevator_manual_command(self): return -self.op_gamepad.getY(XboxController.Hand.kLeft) def elevator_is_manual_control(self): return self.op_gamepad.getTriggerAxis(XboxController.Hand.kLeft) > 0.75 def elevator_move_to_top(self): return self.op_gamepad.getPOV() == 0 def elevator_move_to_switch(self): return self.op_gamepad.getPOV() == 90 def elevator_move_to_bottom(self): return self.op_gamepad.getPOV() == 180 def elevator_zero(self): return False # Climber def do_drop_forks(self): return self.op_gamepad.getBackButton() def do_climb(self): return self.op_gamepad.getStartButton()
class XboxControllerPlus(): def __init__(self, port): self._controller = XboxController(port) self._a = False self._b = False self._x = False self._y = False self._lb = False self._rb = False self._lt = False self._rt = False self._ls = False self._rs = False self._start = False self._back = False self._dpad = -1 def getAButton(self): a = self._a b = self._controller.getAButton() self._a = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getBButton(self): a = self._b b = self._controller.getBButton() self._b = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getXButton(self): a = self._x b = self._controller.getXButton() self._x = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getYButton(self): a = self._y b = self._controller.getYButton() self._y = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getBumper(self, h): if h == kLeft: a = self._lb else: a = self._rb b = self._controller.getBumper(h) if h == kLeft: self._lb = b else: self._rb = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getTrigger(self, h): if h == kLeft: a = self._lt else: a = self._rt b = self._controller.getTriggerAxis(h) >= 0.5 if h == kLeft: self._lt = b else: self._rt = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getStickButton(self, h): if h == kLeft: a = self._ls else: a = self._rs b = self._controller.getStickButton(h) if h == kLeft: self._ls = b else: self._rs = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getStartButton(self): a = self._start b = self._controller.getStartButton() self._start = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getBackButton(self): a = self._back b = self._controller.getBackButton() self._back = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def getDpad(self, value): a = self._dpad b = self._controller.getPOV(0) self._dpad = b if b != a: if b: return PRESSED else: return RELEASED elif b: return DOWN else: return UP def setRumble(self, type1, d): self._controller.setRumble(type1, d) def getX(self, hand): return self._controller.getX(hand) def getY(self, hand): return self._controller.getY(hand)