Beispiel #1
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)
Beispiel #2
0
class Joker(magicbot.MagicRobot):
    drivePID: DriveController

    chassis: Chassis

    def createObjects(self):
        """ Create motors, sensors and all your components here. """
        self.chassis_left_master = WPI_TalonSRX(1)
        self.chassis_left_slave = WPI_TalonSRX(2)
        self.chassis_right_master = WPI_TalonSRX(3)
        self.chassis_right_slave = WPI_TalonSRX(4)
        self.chassis_gyro = AHRS.create_spi()
        self.joystick = Joystick(0)

    def disabledInit(self):
        if self.drivePID.enabled:
            self.drivePID.close()

    def robotPeriodic(self):
        if self.isAutonomousEnabled():
            self.chassis.set_auto()
        elif self.isOperatorControlEnabled():
            self.chassis.set_teleop()

    def teleopInit(self):
        """ Called when teleop starts. """
        NetworkTables.initialize(server="10.43.20.149")
        self.sd = NetworkTables.getTable("SmartDashboard")
        self.chassis.reset_encoders()

    def teleopPeriodic(self):
        """ Called on each iteration of the control loop. """
        self.chassis.set_speed(-self.joystick.getY(), -self.joystick.getZ())
Beispiel #3
0
 def upadte_operator(self,
                     left_stick: Joystick,
                     right_stick: Joystick = None):
     if right_stick is None:
         self.arcade_mode = True
         self.y_speed = -left_stick.getY()
         self.z_speed = -left_stick.getZ()
     else:
         self.arcade_mode = True
         self.left_speed = -left_stick.getY()
         self.right_speed = -right_stick.getY()