Beispiel #1
0
class Attack3Joystick(Sensor):
    """
    Sensor wrapper for the Attack 3 Joystick.

    Has boolean attributes for buttons: trigger, button2-9
    and double x_axis, y_axis for joystick position
    """

    x_axis = y_axis = 0
    trigger = button2 = button3 = \
        button4 = button5 = button6 = \
        button7 = button8 = button9 = \
        button10 = button11 = False

    def __init__(self, port):
        """
        Initializes the joystick with some USB port.
        """
        super().__init__()
        self.j = Joystick(port)

    def poll(self):
        for i, state_id in enumerate(BUTTON_TABLE, 1):
            self.update_state(state_id, self.j.GetRawButton(i))
            # button index is offset by 1 due to wpilib 1-indexing

        self.x_axis = self.j.GetX()
        self.y_axis = self.j.GetY()
Beispiel #2
0
class XboxJoystick(Sensor):
    """
    Sensor wrapper for the Xbox Controller.

    Has boolean attributes for buttons: a/b/x/y/back/start_button,
    l/r_shoulder
    Attributes l/r_x/y_axis for thumbstick positions
    trigger_pos and keypad_pos for trigger and keypad position
    """

    l_x_axis = l_y_axis = r_x_axis = r_y_axis = 0
    trigger_pos = keypad_pos = 0
    a_button = b_button = x_button = y_button = False
    l_shoulder = r_shoulder = back_button = start_button = False

    def __init__(self, port):
        """
        Initializes the joystick with some USB port.
        """
        super().__init__()
        self.j = Joystick(port)

    def poll(self):
        for i, state_id in enumerate(BUTTON_TABLE, 1):
            self.update_state(state_id, self.j.GetRawButton(i))
            # button index is offset by 1 due to wpilib 1-indexing

        self.l_x_axis = self.j.GetX()
        self.l_y_axis = self.j.GetY()
        self.r_x_axis = self.j.GetRawAxis(4)
        self.r_y_axis = self.j.GetRawAxis(5)
        self.trigger_pos = self.j.GetZ()
        self.keypad_pos = self.j.GetRawAxis(6)