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))

        self.x_axis = self.j.getX()
        self.y_axis = self.j.getY()
Beispiel #2
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))

        self.x_axis = self.j.getX()
        self.y_axis = self.j.getY()
Beispiel #3
0
class MyRobot(TimedRobot):
    # Defines the channels that are used on the inputs. In the simulator, they have to match up with the physics.py file
    # This is really useful when you have a variable used hundreds of times and you want to have it set so you can
    # change it all in one go.

    RLMotorChannel = 2
    RRMotorChannel = 0
    FLMotorChannel = 3
    FRMotorChannel = 4

    DriveStickChannel = 0

    # RobotInit is where all of the things we are using is initialized.
    def robotInit(self):
        # Note the lack of the camera server initialization here.

        # Initializing drive motors
        RLMotor = Spark(self.RLMotorChannel)
        RRMotor = Spark(self.RRMotorChannel)
        FLMotor = Spark(self.FLMotorChannel)
        FRMotor = Spark(self.FRMotorChannel)

        # Grouping drive motors into left and right.
        self.Left = SpeedControllerGroup(RLMotor, FLMotor)
        self.Right = SpeedControllerGroup(RRMotor, FRMotor)

        # Initializing drive Joystick.
        self.DriveStick = Joystick(self.DriveStickChannel)

        # Initializing drive function.
        self.drive = DifferentialDrive(self.Left, self.Right)

        # Sets the right side motors to be inverted.
        self.drive.setRightSideInverted(rightSideInverted=True)

        # Turns the drive off after .1 seconds of inactivity.
        self.drive.setExpiration(0.1)

        # Components is a dictionary that contains any variables you want to put into it. All of the variables put into
        # components dictionary is given to the autonomous modes.
        self.components = {"drive": self.drive}

        # Sets up the autonomous mode selector by telling it where the autonomous modes are at and what the autonomous
        # modes should inherit.
        self.automodes = autonomous.AutonomousModeSelector(
            "Sim_Autonomous", self.components)

        # Autonomous and teleop periodic both run the code on a fixed loop time. A part of TimedRobot.
    def autonomousPeriodic(self):
        # runs the autonomous modes when Autonomous is activated.
        self.automodes.run()

    def teleopPeriodic(self):
        # Turns on drive safety and checks to se if operator control and the robot is enabled.
        self.drive.setSafetyEnabled(True)
        if self.isOperatorControl() and self.isEnabled():
            # Drives the robot with controller inputs. You can use buttons with self.DriveStick.getRawButton(ButtonNum).
            self.drive.arcadeDrive(self.DriveStick.getY(),
                                   -self.DriveStick.getX(),
                                   squareInputs=False)
Beispiel #4
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)