Example #1
0
    def __init__(self):
        self.driveRobot = DriveTrain()
        self.arm = ArmSystem()
        self.pneumatics = PneumaticsCommand()
        # self.servo = ServoCommand()

        self.armToggle = Toggle(self.pneumatics.extendArm,
                                self.pneumatics.retractArm)
        self.gripToggle = Toggle(self.pneumatics.openGrip,
                                 self.pneumatics.closeGrip)

        self.joystick = Joystick(0)

        self.armUpButton = JoystickButton(self.joystick, 6)
        self.armDownButton = JoystickButton(self.joystick, 4)
        self.stopButton = JoystickButton(self.joystick, 10)
        ''' Extension and retraction variables - syntax: '''  # JoystickButton(self.joystick, [appointed button number])
        # self.armExtendButton = JoystickButton(self.joystick, 5)
        # self.armRetractButton = JoystickButton(self.joystick, 3)
        # self.armToggle = False
        # self.armLast = False
        # self.grabToggle = False
        # self.grabLast = False

        self.armButton = JoystickButton(self.joystick, 2)
        self.gripButton = JoystickButton(self.joystick, 1)
    def __init__(self, port=0):
        super().__init__("Get Controller Values")

        self.setRunWhenDisabled(True)
        self.joystick = Joystick(port)

        self.numOfAxes = self.joystick.ds.joystickAxes[port].count
        self.numOfButtons = self.joystick.ds.joystickButtons[port].count
Example #3
0
def getJoystick(num):
    joystick0 = Joystick(0)
    joystick1 = Joystick(1)
    xbox = Xbox(2)

    if num == 0: return joystick0
    elif num == 1: return joystick1
    elif num == 2: return xbox
Example #4
0
    def createObjects(self):
        self.chassis_left_motor_master = WPI_TalonSRX(1)
        self.chassis_left_motor_slave = WPI_TalonSRX(2)

        self.chassis_right_motor_master = WPI_TalonSRX(3)
        self.chassis_right_motor_slave = WPI_TalonSRX(4)

        self.chassis_navx = AHRS.create_spi()
        self.joystick = Joystick(0)
Example #5
0
def getJoystick():
    """
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    """

    joystick = Joystick(0)

    button5 = JoystickButton(joystick, 5)
    button6 = JoystickButton(joystick, 6)
    button3 = JoystickButton(joystick, 3)
    button4 = JoystickButton(joystick, 4)
    button1 = JoystickButton(joystick, 1)
    button2 = JoystickButton(joystick, 2)
    button7 = JoystickButton(joystick, 7)

    button5.whenPressed(BallIntake())
    button6.whileHeld(BallOutake())
    button3.whileHeld(LiftArm())
    button4.whileHeld(LowerArm())
    button1.whileHeld(HatchUp())
    button2.whileHeld(HatchDown())
    button7.whileHeld(FindTarget())

    return joystick
Example #6
0
def init():
    global joystick
    joystick = Joystick(0)

    # JoystickButton(joystick, buttons.L_BUMPER).whenPressed(GearShift(Gearing.LOW))
    # JoystickButton(joystick, buttons.R_BUMPER).whenPressed(GearShift(Gearing.HIGH))

    # #JoystickButton(joystick, buttons.SQUARE).whenPressed(Grabber(True))
    # JoystickButton(joystick, buttons.X).whenPressed(Grabber("toggle"))

    gearup = JoystickButton(joystick, 1)
    geardown = JoystickButton(joystick, 2)
    grabberclose = JoystickButton(joystick, 4)
    grabberopen = JoystickButton(joystick, 3)
    shooterdown = JoystickButton(joystick, 5)
    shooterup = JoystickButton(joystick, 6)
    homebutton = JoystickButton(joystick, 13)

    # 5 and 6 are L and R bumpers

    gearup.whenPressed(GearShift(Gearing.HIGH))
    geardown.whenPressed(GearShift(Gearing.LOW))
    grabberclose.whenPressed(Grabber(True))
    grabberopen.whenPressed(Grabber(False))
    shooterup.whenPressed(Shooter(True))
    shooterdown.whenPressed(Shooter(False))
Example #7
0
def init():
    global joystick
    joystick = Joystick(0)

    crossbow_open = JoystickButton(joystick, 1)

    crossbow_open.whenPressed(CrossBow())
Example #8
0
    def __init__(self):
        # Create Joysticks
        self._driveJoy = XboxController(0)
        self._cyController = Joystick(1)

        # Create Buttons
        self._blastenTheHatches = JoystickButton(self._driveJoy, 2)
        self._servoOpen = JoystickButton(self._driveJoy, 4)
        self._servoHalf = JoystickButton(self._driveJoy, 3)
        self._servoClose = JoystickButton(self._driveJoy, 1)

        self._suplexButton = JoystickButton(self._driveJoy, 8)
        self._backButton = JoystickButton(self._driveJoy, 7)

        # Testing
        self._moveMastUpButton = JoystickButton(self._cyController, 8)
        self._moveMastDownButton = JoystickButton(self._cyController, 9)

        # Connect Buttons to Commands
        hatchEffector = Command.getRobot().hatchEffector
        self._blastenTheHatches.whileHeld(hatchEffector.ParallelShoot(hatchEffector))
        self._servoOpen.whileHeld(hatchEffector.ServoOpen(hatchEffector))
        self._servoHalf.whileHeld(hatchEffector.ServoHalf(hatchEffector))
        self._servoClose.whileHeld(hatchEffector.ServoClose(hatchEffector))

        suplex = Command.getRobot().suplex
        self._suplexButton.whileHeld(suplex.Smash(suplex, Flipper.FlipDirection.UP))
        self._backButton.whileHeld(suplex.Smash(suplex, Flipper.FlipDirection.DOWN))

        mastyBoi = Command.getRobot().mastyBoi
        self._moveMastUpButton.whileHeld(mastyBoi.HoistTheColors(mastyBoi))
        self._moveMastDownButton.whileHeld(mastyBoi.RetrieveTheColors(mastyBoi))
Example #9
0
def getJoystick():

    joystick = Joystick(0)

    trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger)

    return joystick
Example #10
0
def getJoystick():
    """This function creates an instance of the joystick, and assigns commands
       to the joystick buttons."""

    joystick = Joystick(0)

    trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger)
    trigger.whileHeld(GrippersIntake())

    thumb = JoystickButton(joystick, Joystick.ButtonType.kTop)
    thumb.whileHeld(GrippersExhaust())

    POV_up = POVButton(joystick, 0)
    POV_down = POVButton(joystick, 180)

    POV_up.whileActive(ElevatorUp())
    POV_down.whileActive(ElevatorDown())

    button_5 = JoystickButton(joystick, 5)
    button_5.whenPressed(HandlesState(HandlesOpen(), HandlesClose()))

    button_6 = JoystickButton(joystick, 6)
    button_6.whenPressed(DrivetrainState(StrengthState(), SpeedState()))

    return joystick
Example #11
0
def init():
    '''
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    '''

    global joystick

    joystick = Joystick(0)
Example #12
0
class Robot(MagicRobot):
    pid_controller: PIDControl
    chassis: Chassis
    joystick: Joystick
    pid_drive: piddrive

    def createObjects(self):
        self.chassis_left_motor_master = WPI_TalonSRX(1)
        self.chassis_left_motor_slave = WPI_TalonSRX(2)

        self.chassis_right_motor_master = WPI_TalonSRX(3)
        self.chassis_right_motor_slave = WPI_TalonSRX(4)

        self.chassis_navx = AHRS.create_spi()
        self.joystick = Joystick(0)

    def teleopPeriodic(self):
        self.chassis.set_speed(-self.joystick.getY(),
                               -self.joystick.getThrottle())
class ControllerDebugCommand(Command):
    def __init__(self, port=0):
        super().__init__("Get Controller Values")

        self.setRunWhenDisabled(True)
        self.joystick = Joystick(port)

        self.numOfAxes = self.joystick.ds.joystickAxes[port].count
        self.numOfButtons = self.joystick.ds.joystickButtons[port].count

    def execute(self):
        for i in range(0, self.numOfAxes):
            value = self.joystick.getRawAxis(i)
            if abs(value) >= 0.5:
                print("Axis %d: %f" % (i, value))

        for i in range(1, self.numOfButtons):
            if self.joystick.getRawButtonPressed(i):
                print("Button %d Pressed" % i)
Example #14
0
class OI():
    def __init__(self):
        self.driveRobot = DriveTrain()
        self.arm = ArmSystem()
        self.pneumatics = PneumaticsCommand()
        # self.servo = ServoCommand()

        self.armToggle = Toggle(self.pneumatics.extendArm,
                                self.pneumatics.retractArm)
        self.gripToggle = Toggle(self.pneumatics.openGrip,
                                 self.pneumatics.closeGrip)

        self.joystick = Joystick(0)

        self.armUpButton = JoystickButton(self.joystick, 6)
        self.armDownButton = JoystickButton(self.joystick, 4)
        self.stopButton = JoystickButton(self.joystick, 10)
        ''' Extension and retraction variables - syntax: '''  # JoystickButton(self.joystick, [appointed button number])
        # self.armExtendButton = JoystickButton(self.joystick, 5)
        # self.armRetractButton = JoystickButton(self.joystick, 3)
        # self.armToggle = False
        # self.armLast = False
        # self.grabToggle = False
        # self.grabLast = False

        self.armButton = JoystickButton(self.joystick, 2)
        self.gripButton = JoystickButton(self.joystick, 1)

    def poll(self):
        ''' Axis control - syntax: '''  # self.joystick.get[axis]()
        self.xAxis = self.joystick.getX()
        self.yAxis = self.joystick.getY()
        self.zAxis = self.joystick.getZ()

        self.driveRobot.drive(self.xAxis, self.yAxis, self.zAxis)

        # print(self.armUpButton.get())
        self.arm.armMove(0.5, self.armUpButton.get(), self.armDownButton.get())

        self.armToggle.togglePneumatics(self.armButton.get())
        self.gripToggle.togglePneumatics(self.gripButton.get())
Example #15
0
def init():
    '''
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    '''

    global joystick

    joystick = Joystick(0)

    trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger)
    trigger.whenPressed(Crash())
Example #16
0
def getJoystick():
    """
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    """

    joystick = Joystick(0)

    trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger)
    trigger.whenPressed(Crash())

    return joystick
Example #17
0
def getJoystick():
    """
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    """

    joystick = Joystick(0)

    button1 = JoystickButton(joystick, 1)

    button1.whileHeld(Targeting())

    return Joystick
Example #18
0
def init():
    '''
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    '''
    global joystick_player

    joystick_player = Joystick(0)
    set_joystick()

    trigger = JoystickButton(joystick_player, Joystick.ButtonType.kTrigger)

    trigger.whenPressed(Record(FollowJoystick()))
Example #19
0
def init():
    global joystick
    joystick = Joystick(0)

    crossbow = JoystickButton(joystick, 5)
    crossbow_in_hold = JoystickButton(joystick, 6)

    solenoid_intake = JoystickButton(joystick, 1)

    crossbow.whenPressed(Crossbow(0.8, 1))
    crossbow_in_hold.whenPressed(Crossbow(-0.6, 1.75))

    solenoid_intake.whenPressed(PullIntake())

    intake = JoystickButton(joystick, 4)
    intake.toggleWhenPressed(Intake())
def init():
    global joystick

    joystick = Joystick(robotmap.portsList.stickID)

    startFuelOutakeButton = JoystickButton(
        joystick, robotmap.buttonsAndAxesList.startFuelOutakeID)
    startFuelOutakeButton.whenPressed(
        RunFuelOutake(robotmap.speedsList.fuelOutakeSpeed))
    stopFuelOutakeButton = JoystickButton(
        joystick, robotmap.buttonsAndAxesList.stopFuelOutakeID)
    stopFuelOutakeButton.whenPressed(StopFuelOutake())

    openGearDoorButton = JoystickButton(joystick,
                                        robotmap.buttonsAndAxesList.openGearID)
    openGearDoorButton.whenPressed(OpenGear())
    closeGearDoorButton = JoystickButton(
        joystick, robotmap.buttonsAndAxesList.closeGearID)
    closeGearDoorButton.whenPressed(CloseGear())
Example #21
0
def init():
    '''
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    '''

    global joystick

    joystick = Joystick(0)

    brakeButton = JoystickButton(joystick, RobotMap.buttons.brake)
    brakeButton.whileHeld(Brake())

    # resetRevolutionsButton = JoystickButton(joystick, RobotMap.buttons.resetRevolutions)
    # resetRevolutionsButton.whenPressed(ResetRevolutions())

    preciseDriveButton = JoystickButton(joystick, RobotMap.buttons.preciseDrive)
    preciseDriveButton.whileHeld(PreciseDriveWithJoystick())

    # climbButton = JoystickButton(joystick, RobotMap.buttons.climb)
    # climbButton.whileHeld(Climb())

    # dropButton = JoystickButton(joystick, RobotMap.buttons.drop)
    # dropButton.whileHeld(Drop())

    # stopClimbButton = JoystickButton(joystick, RobotMap.buttons.stopClimb)
    # stopClimbButton.whileHeld(StopClimb())

    # suckCubeButton = JoystickButton(joystick, RobotMap.buttons.suckCube)
    # suckCubeButton.whileHeld(SuckCube())

    retractCubeButton = JoystickButton(joystick, RobotMap.buttons.retractCube)
    retractCubeButton.whileHeld(RetractCube())

    retractCubeButton2 = JoystickButton(joystick, RobotMap.buttons.retractCube2)
    retractCubeButton2.whileHeld(RetractCube())

    winchUpButton = JoystickButton(joystick, RobotMap.buttons.winchUp)
    winchUpButton.whileHeld(WinchUp())

    winchDownButton = JoystickButton(joystick, RobotMap.buttons.winchDown)
    winchDownButton.whileHeld(WinchDown())
Example #22
0
 def robotInit(self):
     Command.getRobot = lambda x=0: self
     self.driveSubsystem = DriveSubsystem()
             
     self.controller = Joystick(0)
     
     self.forward  = JoystickButton(self.controller, PS4Button["TRIANGLE"])
     self.backward = JoystickButton(self.controller, PS4Button["CROSS"])
     self.right    = JoystickButton(self.controller, PS4Button["CIRCLE"])
     self.left     = JoystickButton(self.controller, PS4Button["SQUARE"])
             
     self.forward.whenPressed(MoveForward())
     self.forward.whenReleased(Stop())
     
     self.backward.whenPressed(MoveBackward())
     self.backward.whenReleased(Stop())
     
     self.right.whenPressed(TurnRight())
     self.right.whenReleased(Stop())
     
     self.left.whenPressed(TurnLeft())
     self.left.whenReleased(Stop())
Example #23
0
    def robotInit(self):
        '''
        Subsystem, Command, OperatorInterface Instantiation
        IN THAT ORDER
        '''

        Command.getRobot = lambda x=0: self

        #self.motor = SingleMotor.SingleMotor(2, self.logger)
        self.drivetrain = DriveTrain(self.logger)
        self.elevator = Elevator(self.logger)
        self.arm = Arm(self.logger)
        self.scooper = Scooper(self.logger)

        self.startCommand = DeployArm()

        self.joystick = Joystick(robotmap.STK_port)
        self.halfPowerModeButton = JoystickButton(self.joystick,
                                                  robotmap.STK_halfPowerMode)
        #  self.automaticMode = JoystickButton(self.joystick, robotmap.STK_automode)
        # self.automaticMode.whenPressed(DockRobot())
        # self.automaticMode.whenReleased(CancelSubsystem(Cancel.DRIVETRAIN))

        self.buttonBoard = Joystick(robotmap.BB_port)
        self.armUpButton = JoystickButton(self.buttonBoard, robotmap.BB_ArmUp)
        self.armDownButton = JoystickButton(self.buttonBoard,
                                            robotmap.BB_ArmDown)
        self.stowArmButton = JoystickButton(self.buttonBoard,
                                            robotmap.BB_StowArm)
        self.elevatorUpButton = JoystickButton(self.buttonBoard,
                                               robotmap.BB_ElevatorUp)
        self.elevatorDownButton = JoystickButton(self.buttonBoard,
                                                 robotmap.BB_ElevatorDown)
        self.ingestButton = JoystickButton(self.buttonBoard,
                                           robotmap.BB_ingest)
        self.expelButton = JoystickButton(self.buttonBoard, robotmap.BB_expel)
        self.deployArmButton = JoystickButton(self.buttonBoard,
                                              robotmap.BB_DeployArm)
        self.midHatchButton = JoystickButton(self.buttonBoard,
                                             robotmap.BB_MidHatch)
        self.lowCargoButton = JoystickButton(self.buttonBoard,
                                             robotmap.BB_LowCargo)
        self.midCargoButton = JoystickButton(self.buttonBoard,
                                             robotmap.BB_MidCargo)

        self.armUpButton.whenPressed(MoveArmUp())
        self.armDownButton.whenPressed(MoveArmDown())
        self.armUpButton.whenReleased(CancelSubsystem(Cancel.ARM))
        self.armDownButton.whenReleased(CancelSubsystem(Cancel.ARM))
        self.stowArmButton.whenPressed(StowArm())
        #self.deployArmButton.whenPressed(DeployArm())

        self.elevatorUpButton.whenPressed(MoveElevatorUp())
        self.elevatorDownButton.whenPressed(MoveElevatorDown())
        self.elevatorUpButton.whenReleased(CancelSubsystem(Cancel.ELEVATOR))
        self.elevatorDownButton.whenReleased(CancelSubsystem(Cancel.ELEVATOR))

        self.ingestButton.whenPressed(Ingest())
        self.expelButton.whenPressed(Expel())

        # self.lowHatchButton.whenPressed(PositionLowHatch())
        # self.midHatchButton.whenPressed(PositionMidHatch())
        # self.lowCargoButton.whenPressed(PositionLowCargo())
        # self.midCargoButton.whenPressed(PositionMidCargo())

        self._smartDashboard = NetworkTables.getTable('SmartDashboard')
        self._smartDashboard.putString("ArmLimit", "InGame")
Example #24
0
def get_joystick():
    """
    Assign commands to button actions, and publish your joysticks so you
    can read values from them later.
    """

    joystick = Joystick(0)
    joystick2 = Joystick(1)

    # TODO lots of commands to map here
    # TODO how are we going to count taps for position?

    # trigger = JoystickButton(joystick=joystick, buttonNumber=5)
    # trigger.whenPressed(gear_shift.gear_shift(True))
    # trigger.whenReleased(gear_shift.gear_shift(False))

    # rtrigger = JoystickButton(joystick=joystick, buttonNumber=6)
    # rtrigger.whenPressed(set_arm_pos.SetArmPosition(1024.0))
    # rtrigger.whenReleased(set_arm_pos.SetArmPosition(0.0))

    buttonB = JoystickButton(joystick=joystick, buttonNumber=2)
    buttonB.whenPressed(hatch_punch(True))
    buttonB.whenReleased(hatch_punch(False))

    buttonX = JoystickButton(joystick=joystick, buttonNumber=3)
    buttonX.whenPressed(SetElvPay(-3000, 470))

    buttonA = JoystickButton(joystick=joystick, buttonNumber=1)
    buttonA.whenPressed(SetElvPay(-3000, 2250))

    buttonL1 = JoystickButton(joystick=joystick, buttonNumber=5)
    buttonL1.whenPressed(BallIn())
    buttonL1.whenReleased(BallStop())

    buttonR1 = JoystickButton(joystick=joystick, buttonNumber=6)
    buttonR1.whenPressed(BallOut())
    buttonR1.whenReleased(BallStop())

    #button12 = JoystickButton(joystick=joystick2, buttonNumber=12)
    #button12.whenPressed(SetElvPay(0, 0))

    #buttonB = JoystickButton(joystick=joystick2, buttonNumber=2)
    #buttonB.whenPressed(SetElvSpeed(0.5))
    #buttonB.whenReleased(SetElvSpeed(0.0))

    #buttonA = JoystickButton(joystick=joystick2, buttonNumber=1)
    #buttonA.whenPressed(SetElvSpeed(-0.5))
    #buttonA.whenReleased(SetElvSpeed(0.0))

    #high hatch
    buttonL1 = JoystickButton(joystick=joystick2, buttonNumber=5)
    buttonL1.whenPressed(SetElvPay(-25000, 470))

    #mid hatch
    buttonX = JoystickButton(joystick=joystick2, buttonNumber=3)
    buttonX.whenPressed(SetElvPay(-17000, 470))

    #stow
    buttonA = JoystickButton(joystick=joystick2, buttonNumber=1)
    buttonA.whenPressed(SetElvPay(0, 0))

    #high ball
    buttonR1 = JoystickButton(joystick=joystick2, buttonNumber=6)
    buttonR1.whenPressed(SetElvPay(-25000, 1100))

    #mid ball
    buttonY = JoystickButton(joystick=joystick2, buttonNumber=4)
    buttonY.whenPressed(SetElvPay(-17000, 1100))

    #low ball
    buttonB = JoystickButton(joystick=joystick2, buttonNumber=2)
    buttonB.whenPressed(SetElvPay(-3000, 1100))

    #elevator up
    buttonLS = JoystickButton(joystick=joystick2, buttonNumber=9)
    buttonLS.whenPressed(SetElvSpeed(-0.7))
    buttonLS.whenReleased(SetElvSpeed(0.0))

    #all stop
    buttonRS = JoystickButton(joystick=joystick2, buttonNumber=10)
    buttonRS.whenPressed(SetElvSpeed(0.0))
    buttonRS.whenPressed(SetPaySpeed(0.0))

    #elbow up
    buttonBack = JoystickButton(joystick=joystick2, buttonNumber=7)
    buttonBack.whenPressed(SetPaySpeed(-0.3))
    buttonBack.whenReleased(SetPaySpeed(0.0))

    #elbow down
    buttonStart = JoystickButton(joystick=joystick2, buttonNumber=8)
    buttonStart.whenPressed(SetPaySpeed(0.3))
    buttonStart.whenReleased(SetPaySpeed(0.0))

    return joystick
Example #25
0
def getJoystick():
    global joystick
    if (joystick is None):
        joystick = Joystick(0)
        trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger)
    return joystick
Example #26
0
def getRightStick():
    rightStick = Joystick(1).getY()
    return rightStick
Example #27
0
def getLeftStick():
    leftStick = Joystick(0).getY()
    return leftStick
Example #28
0
def getTurn():
    leftTurn = Joystick(0).getX()
    return leftTurn
Example #29
0
def flipButton():
    flip = Joystick(1).getButton(1)  # right trigger
    return flip
Example #30
0
def halfSpeedButton():
    halfSpeed = Joystick(0).getButton(1)  # left trigger
    return halfSpeed