示例#1
0
 def lift(self, stick: wpilib.Joystick):
     if stick.getRawButton(4):
         self.arm_pivot_motor.set(0.5)  
     elif stick.getRawButton(3):
         self.arm_pivot_motor.set(-0.5)
     else:
         self.arm_pivot_motor.set(0)
示例#2
0
    def __init__(self, robot):

        # Setup the joystick for the driver
        self.driverJoystick = Joystick(DRIVER_JOYSTICK)
        # self.driverRightAnalog = Joystick(DRIVER_JOYSTICK)
        # self.driverRightAnalog.setXChannel(4)
        # self.driverRightAnalog.setYChannel(5)

        # Setup the joystick for the operator
        self.operatorJoystick = Joystick(OPERATOR_JOYSTICK)
        # self.operatorRightAnalog = Joystick(DRIVER_JOYSTICK)
        # self.operatorRightAnalog.setXChannel(4)
        # self.operatorRightAnalog.setYChannel(5)

        # Driver commands and control
        btn(self.driverJoystick, 1).whileHeld(IntakeMotorsIn(robot))
        btn(self.driverJoystick, 2).whileHeld(IntakeMotorsOut(robot, INTAKE_OUT_SWITCH_FAST))
        btn(self.driverJoystick, 3).whileHeld(IntakeMotorsOut(robot, INTAKE_OUT_SCALE))
        btn(self.driverJoystick, 4).whileHeld(IntakeMotorsOut(robot, INTAKE_OUT_SWITCH_SLOW))

        # Operator commands and control
        # Per Dylan, boom control A-intake X-switch Y- scale
        btn(self.operatorJoystick, 1).whenPressed(IntakePneumaticsOpenClose(robot))
        btn(self.operatorJoystick, 3).whenPressed(BoomToSwitch(robot))
        btn(self.operatorJoystick, 2).whenPressed(BoomToIntake(robot))
        btn(self.operatorJoystick, 4).whenPressed(BoomToScale(robot))
示例#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)
示例#4
0
 def robotInit(self):
     """
     This function is called upon program startup and
     should be used for any initialization code.
     """
     self.drive = Drive()
     self.stick = Joystick(0)
示例#5
0
    def shoot(self, stick: wpilib.Joystick):
        if stick.getPOV() == 180:
            self.left_shooter.set(ctre.ControlMode.PercentOutput,
                                  -0.6)  #rocket bajo
            self.right_shooter.set(ctre.ControlMode.PercentOutput, -0.6)

            self.intake_motor.set(-0.6)

        elif stick.getPOV() == 0:
            self.left_shooter.set(ctre.ControlMode.PercentOutput,
                                  -0.5)  #rocket bajo
            self.right_shooter.set(ctre.ControlMode.PercentOutput, -0.5)

            self.intake_motor.set(-0.6)

        elif stick.getRawAxis(2) > 0.50:  #intake main
            self.intake_motor.set(-0.8)

            self.left_shooter.set(ctre.ControlMode.PercentOutput, -0.3)
            self.right_shooter.set(ctre.ControlMode.PercentOutput, -0.3)

        elif stick.getRawButton(5) or stick.getRawButton(6):  #regresar pelota
            self.intake_motor.set(0.4)

            self.left_shooter.set(ctre.ControlMode.PercentOutput, 0.4)
            self.right_shooter.set(ctre.ControlMode.PercentOutput, 0.4)

        else:  #nada presionado
            self.left_shooter.set(ctre.ControlMode.PercentOutput, 0)
            self.right_shooter.set(ctre.ControlMode.PercentOutput, 0)
            self.intake_motor.set(0)
示例#6
0
    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)
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()
    def createControllers(self, ConSpec):
        con = None
        if ConSpec['jobType'] == 'main':
            if ConSpec['Type'] == 'xbox':
                con = XboxController(ConSpec['Id'])
            elif ConSpec['Type'] == 'xtreme':
                con = Joystick(ConSpec['Id'])
            elif ConSpec['Type'] == 'gameCube':
                con = Joystick(ConSpec['Id'])
            else:
                print("IDK your Controller")

        elif ConSpec['jobType'] == 'side':
            if ConSpec['Type'] == 'xbox':
                con = XboxController(ConSpec['Id'])
            elif ConSpec['Type'] == 'xtreme':
                con = Joystick(ConSpec['Id'])
            elif ConSpec['Type'] == 'custom':
                con = Joystick(ConSpec['Id'])
            else:
                print("IDK your Controller")

        else:
            print("IDK your Controller")

        return con
示例#9
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()
示例#10
0
 def handle_shooter_inputs(self, joystick: wpilib.Joystick):
     if joystick.getTriggerPressed():
         self.shooter_controller.driver_input(True)
     if joystick.getTriggerReleased():
         self.shooter_controller.driver_input(False)
     if joystick.getRawButtonPressed(5):
         self.shooter_controller.spin_input()
示例#11
0
 def Climb(self, stick: wpilib.Joystick):
     if stick.getRawButton(9) == True:
         self.main_lift.set(-.7)
     elif stick.getRawButton(7) == True:
         self.main_lift.set(.7)
     else:
         self.main_lift.set(0)
示例#12
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())
示例#13
0
文件: robot.py 项目: Leo428/Magic
    def createObjects(self):

        self.shiftBaseSolenoid = wpilib.DoubleSolenoid(
            rMap.conf_shifterSolenoid1, rMap.conf_shifterSolenoid2)
        self.rightFrontBaseMotor = CANTalon(rMap.conf_rightFrontBaseTalon)
        self.rightRearBaseMotor = CANTalon(rMap.conf_rightRearBaseTalon)
        self.leftFrontBaseMotor = CANTalon(rMap.conf_leftFrontBaseTalon)
        self.leftRearBaseMotor = CANTalon(rMap.conf_leftRearBaseTalon)

        self.rightFrontBaseMotor.enableControl()
        self.rightRearBaseMotor.enableControl()
        self.rightRearBaseMotor.setControlMode(CANTalon.ControlMode.Follower)
        self.rightRearBaseMotor.set(rMap.conf_rightFrontBaseTalon)

        self.leftFrontBaseMotor.enableControl()
        self.leftRearBaseMotor.enableControl()
        self.leftFrontBaseMotor.setInverted(True)
        self.leftRearBaseMotor.setControlMode(CANTalon.ControlMode.Follower)
        self.leftRearBaseMotor.set(rMap.conf_leftFrontBaseTalon)

        self.leftJoy = Joystick(rMap.conf_left_joy)
        self.rightJoy = Joystick(rMap.conf_right_joy)
        self.xbox = Joystick(rMap.conf_xbox)

        self.robotDrive = wpilib.RobotDrive(self.leftFrontBaseMotor,
                                            self.rightFrontBaseMotor)
示例#14
0
 def __init__(self, port):
     """
     :param port: The port on the driver station that the controller is
         plugged into.
     :type  port: int
     """
     self.joy = Joystick(port)
     self.debounce = DpadDebouncer()
示例#15
0
 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)
示例#16
0
 def handle_chassis_inputs(self, joystick: wpilib.Joystick,
                           gamepad: wpilib.XboxController) -> None:
     throttle = scale_value(joystick.getThrottle(), 1, -1, 0.1, 1)
     vx = 3 * throttle * rescale_js(-joystick.getY(), 0.1)
     vz = 3 * throttle * rescale_js(-joystick.getTwist(), 0.1)
     self.chassis.drive(vx, vz)
     if joystick.getRawButtonPressed(3):
         # TODO reset heading
         pass
示例#17
0
文件: robot.py 项目: Leo428/Magic
class MyRobot(MagicRobot):
    solenoids = Solenoids

    def createObjects(self):

        self.shiftBaseSolenoid = wpilib.DoubleSolenoid(
            rMap.conf_shifterSolenoid1, rMap.conf_shifterSolenoid2)
        self.rightFrontBaseMotor = CANTalon(rMap.conf_rightFrontBaseTalon)
        self.rightRearBaseMotor = CANTalon(rMap.conf_rightRearBaseTalon)
        self.leftFrontBaseMotor = CANTalon(rMap.conf_leftFrontBaseTalon)
        self.leftRearBaseMotor = CANTalon(rMap.conf_leftRearBaseTalon)

        self.rightFrontBaseMotor.enableControl()
        self.rightRearBaseMotor.enableControl()
        self.rightRearBaseMotor.setControlMode(CANTalon.ControlMode.Follower)
        self.rightRearBaseMotor.set(rMap.conf_rightFrontBaseTalon)

        self.leftFrontBaseMotor.enableControl()
        self.leftRearBaseMotor.enableControl()
        self.leftFrontBaseMotor.setInverted(True)
        self.leftRearBaseMotor.setControlMode(CANTalon.ControlMode.Follower)
        self.leftRearBaseMotor.set(rMap.conf_leftFrontBaseTalon)

        self.leftJoy = Joystick(rMap.conf_left_joy)
        self.rightJoy = Joystick(rMap.conf_right_joy)
        self.xbox = Joystick(rMap.conf_xbox)

        self.robotDrive = wpilib.RobotDrive(self.leftFrontBaseMotor,
                                            self.rightFrontBaseMotor)

    def autonomous(self):
        """Drive left and right motors for two seconds, then stop."""
        MagicRobot.autonomous(self)

    def teleopInit(self):
        MagicRobot.teleopInit(self)

    def teleopPeriodic(self):

        if self.isSimulation():
            # easier to control in simulation
            self.robotDrive.arcadeDrive(self.leftJoy)
        else:
            self.robotDrive.tankDrive(self.leftJoy.getY(),
                                      self.rightJoy.getY())

        try:
            if self.leftJoy.getRawButton(7):
                self.solenoids.setShift()
                print("RED " + str(self.solenoids.setShift()))

        except:
            self.onException()

    def test(self):
        '''Runs during test mode'''
        wpilib.LiveWindow.run()
示例#18
0
    def BallIntake(self, stick: wpilib.Joystick):
        if stick.getRawButton(1) == True:
            self.intake_motor.set(.8)

        elif stick.getRawButton(10) == True:
            self.intake_motor.set(-.8)

        else:
            self.intake_motor.set(0)
示例#19
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()
示例#20
0
 def handle_chassis_inputs(self, joystick: wpilib.Joystick,
                           gamepad: wpilib.XboxController) -> None:
     throttle = scale_value(joystick.getThrottle(), 1, -1, 0.1, 1)
     vx = 3 * throttle * rescale_js(-joystick.getY(), 0.1)
     vz = 3 * throttle * rescale_js(-joystick.getTwist(), 0.1)
     self.chassis.drive(vx, vz)
     if joystick.getRawButtonPressed(3):
         self.chassis.reset_odometry(
             geometry.Pose2d(-3, 0, geometry.Rotation2d(
                 math.pi)))  # the starting position on the field
         self.target_estimator.reset()
示例#21
0
 def robotInit(self):
     """
     This function is called upon program startup and
     should be used for any initialization code.
     """
     self.pneumaticControlModuleCANID = robotmap.PCM
     self.kDriveTrain = robotmap.DriveTrain
     self.kCubeGrabber = robotmap.CubeGrabber
     self.kSticks = robotmap.Sticks
     self.dStick = Joystick(self.kSticks['drive'])
     self.cStick = Joystick(self.kSticks['control'])
     self.drive = Drive(self)
     self.cubeGrabber = Grabber(self)
示例#22
0
 def handle_spinner_inputs(self, joystick: wpilib.Joystick) -> None:
     if joystick.getRawButtonPressed(7):
         self.spinner_controller.run(test=True, task="position")
         print(f"Spinner Running")
     if joystick.getRawButtonPressed(9):
         self.spinner.piston_up()
         print("Spinner Piston Up")
     if joystick.getRawButtonPressed(10):
         self.spinner.piston_down()
         print("Spinner Piston Down")
     if joystick.getRawButtonPressed(8):
         print(
             f"Detected Colour: {self.spinner_controller.get_current_colour()}"
         )
         print(f"Distance: {self.spinner_controller.get_wheel_dist()}")
示例#23
0
    def __init__(self):
        self.reversed = True
        self.arcade_drive = True
        self.turbo = False

        self.controls = {
            "reverse": 2,  # top
            "arcade_switch": 3,
            "turbo": 1,  # trigger
            "reset": 4
        }

        self.driver_controller = Joystick(0)

        self.left_power = 0
        self.right_power = 0
示例#24
0
    def get_joystick_button(self, stick: wpilib.Joystick):
        stateA  = stick.getRawButton(1)
        stateB  = stick.getRawButton(2)
        stateX  = stick.getRawButton(3)
        stateY  = stick.getRawButton(4)

        if stateA:
            return "A"
        elif stateB:
            return "B"
        elif stateX:
            return "X"
        elif stateY:
            return "Y"
        else:
            return False
示例#25
0
 def robotInit(self):
     """Set up everything we need for a working robot."""
     self.stick = Joystick(0)
             
     self.toLoop = Infinite()
             
     JoystickButton(self.stick, 1).whenHeld(Test())
     JoystickButton(self.stick, 2).whenHeld(SecondTest())
示例#26
0
 def __init__(self, port):
     """
     :param port: The port on the driver station that the controller is
         plugged into.
     :type  port: int
     """
     self.joy = Joystick(port)
     self.debounce = DpadDebouncer()
示例#27
0
class oi:

    ps4_ctrl = Joystick(0)

    def __init__(self):
        pass
        #example button press action
        #triangle = JoystickButton(ps4_ctrl, 3)
        #triangle.whenPressed("place command here")
示例#28
0
    def robotInit(self):
        self.controller = Joystick(0)
        self.joystick = Joystick(1)
        CameraServer.launch('vision.py:main')

        self.autoChooser = SendableChooser()

        self.autoChooser.addDefault("switch_scale", switch_scale)
        # self.autoChooser.addObject("drive_forward", drive_straight)
        SmartDashboard.putData("Autonomous Mode Chooser", self.autoChooser)

        self.autoSideChooser = SendableChooser()

        self.autoSideChooser.addDefault("left", "L")
        self.autoSideChooser.addObject("right", "R")
        self.autoSideChooser.addObject("middle", "M")
        SmartDashboard.putData("Side Chooser", self.autoSideChooser)
        RobotMap.driver_component.set_low_gear()
示例#29
0
 def drive(self, stick: wpilib.Joystick):
     if self.isRBPressed(stick) and not self.changeFrontButtonPressed:
         self.frontStatus = not self.frontStatus
         self.changeFront()
         self.changeFrontButtonPressed = True
     elif not self.isRBPressed(stick) and self.changeFrontButtonPressed:
         self.changeFrontButtonPressed = False
     """
     if self.get_joystick_button(stick) in ("X", "B"):
         if not self.rotation_started:
             self.reset_angle_pid()
             self.rotation_started = True
             if self.get_joystick_button(stick) == "X":
                 self.target_angle = self.navx.getAngle() - 90
             else:
                 self.target_angle = self.navx.getAngle() + 90
         self.rotate_to_angle(stick)
         self.reset_distance_pid()
     """
     
     if self.get_joystick_button(stick) in ("Y", "A"):
         if not self.distance_pid_started:
             self.distance_pid_started = True
             self.right_motor_offset = self.right_motor.getQuadraturePosition()
             self.left_motor_offset  = self.left_motor.getQuadraturePosition()
         
         if self.get_joystick_button(stick) == "Y":
             right_target_encoder_ticks = self.right_motor_offset - ((63-21) * 85.551)
             left_target_encoder_ticks  = self.left_motor_offset + ((63-21) * 85.551)
         else:
             right_target_encoder_ticks = self.right_motor_offset - ((130-21) * 85.551)
             left_target_encoder_ticks  = self.left_motor_offset + ((130-21) * 85.551)
         
         if self.right_motor.getQuadraturePosition() < right_target_encoder_ticks:
             self.right_motor.set(ctre.ControlMode.PercentOutput, 0)
             self.left_motor.set(ctre.ControlMode.PercentOutput, 0)
             return
         else:
             self.right_motor.set(ctre.ControlMode.Velocity, -2400)
         
         if self.left_motor.getQuadraturePosition() > left_target_encoder_ticks:
             self.right_motor.set(ctre.ControlMode.PercentOutput, 0)
             self.left_motor.set(ctre.ControlMode.PercentOutput, 0)
             return
         else:
             self.left_motor.set(ctre.ControlMode.Velocity, -2400)
     
     elif stick.getPOV() != -1:
         self.drive_with_pad(stick)  
         self.reset_angle_pid()
         self.reset_distance_pid()
     
     else:
         self.drive_with_joystick(stick)
         self.reset_angle_pid()
         self.reset_distance_pid()
示例#30
0
    def drive_with_pad(self, stick: wpilib.Joystick):
        trigger = self.get_trigger(stick)
        dpad    = stick.getPOV()

        wpilib.SmartDashboard.putNumber("dpad", dpad)

        left_power  = self.get_left_motor(dpad, trigger)
        right_motor = self.get_right_motor(dpad, trigger)

        self.set_motors(left_power, -right_motor)
示例#31
0
class Robot(wpilib.IterativeRobot):
    def robotInit(self):
        """
        This function is called upon program startup and
        should be used for any initialization code.
        """
        self.drive = Drive()
        self.stick = Joystick(0)

    def robotPeriodic(self):
        pass

    def disabledInit(self):
        pass

    def disabledPeriodic(self):
        self.drive.stop()

    def autonomousInit(self):
        """
        This function is run once each time the robot enters autonomous mode.
        """
        pass

    def autonomousPeriodic(self):
        """This function is called periodically during autonomous."""
        self.drive.moveToPosition(10000, 'left')

    def teleopInit(self):
        pass

    def teleopPeriodic(self):
        """This function is called periodically during operator control."""
        speed = self.stick.getY() * -1
        rotation = self.stick.getTwist()
        # self.drive.moveSpeed(speed, speed)
        self.drive.arcade(speed, rotation)

    def testInit(self):
        pass

    def testPeriodic(self):
        pass
示例#32
0
 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
示例#33
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)
示例#34
0
 def __init__(self, port):
     """
     Initializes the joystick with some USB port.
     """
     super().__init__()
     self.j = Joystick(port)
示例#35
0
class XboxController(object):
    """
        Allows usage of an Xbox controller, with sensible names for xbox
        specific buttons and axes.

    """

    def __init__(self, port):
        """
        :param port: The port on the driver station that the controller is
            plugged into.
        :type  port: int
        """
        self.joy = Joystick(port)
        self.debounce = DpadDebouncer()

    def getLeftX(self):
        """Get the left stick X axis

        :returns: -1 to 1
        :rtype: float
        """
        return self.joy.getRawAxis(0)

    def getLeftY(self):
        """Get the left stick Y axis

        :returns: -1 to 1
        :rtype: float
        """
        return self.joy.getRawAxis(1)

    #getX = self.getLeftX()
    #getY = self.getLeftY()

    def getLeftPressed(self):
        """Determines if the left stick is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(9)

    def getPOV(self):
        """Get the state of the D-Pad
        :returns: The angle of the D-Pad in degrees, or -1 if the D-Pad is not pressed.
        :rtype: float
        """

        return self.debounce.get(self.joy.getPOV())

    def getRightX(self):
        """Get the right stick X axis

        :returns: -1 to 1
        :rtype: float
        """
        return self.joy.getRawAxis(4)

    def getRightY(self):
        """Get the right stick Y axis

        :returns: -1 to 1
        :rtype: float
        """
        return self.joy.getRawAxis(5)

    def getRightPressed(self):
        """Determines if the right stick is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(10)

    def getButtonA(self):
        """Gets whether the A button is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(1)

    def getButtonB(self):
        """Gets whether the B button is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(2)

    def getButtonX(self):
        """Gets whether the X button is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(3)

    def getButtonY(self):
        """Gets whether the X button is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(4)

    def getStart(self):
        """Gets whether the Start button is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(8)

    def getBack(self):
        """Gets whether the Back button is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(7)

    def getLeftBumper(self):
        """Gets whether the left bumper is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(5)

    def getRightBumper(self):
        """Gets whether the right bumper is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawButton(6)

    def getLeftTrigger(self):
        """Gets whether the left trigger is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawAxis(2) > 0

    def getRightTrigger(self):
        """Gets whether the right trigger is pressed

        :returns: True if pressed, False otherwise
        :rtype: bool
        """
        return self.joy.getRawAxis(3) > 0

    def getTriggers(self):
        return self.joy.getRawAxis(2)

    def getRightTriggerRaw(self):
        return self.joy.getRawAxis(3)

    def getLeftTriggerRaw(self):
        return self.joy.getRawAxis(2)


    def rumble(self, left=None, right=None):
        """Sets the rumble amount on one/both side(s) of the controller"""
        if left is not None:
            self.joy.setRumble(Joystick.RumbleType.kLeftRumble_val, left)
        if right is not None:
            self.joy.setRumble(Joystick.RumbleType.kRightRumble_val, right)