Esempio n. 1
0
    def __init__(self, robot):
        '''The Constructor - assign Xbox controller buttons to specific Commands.
        '''

        print("In OI:__init__")

        robot.xbox0 = wpilib.XboxController(0)
        robot.xbox1 = wpilib.XboxController(1)

        stickbutton = StickButton(robot.xbox0, .1)
        shoot = JoystickButton(robot.xbox0, XboxController.Button.kA)
        block = JoystickButton(robot.xbox0, XboxController.Button.kY)
        intake = JoystickButton(robot.xbox0, XboxController.Button.kX)
        shiftup = JoystickButton(robot.xbox0,
                                 XboxController.Button.kBumperRight)
        shiftdown = JoystickButton(robot.xbox0,
                                   XboxController.Button.kBumperLeft)

        togglecamera = JoystickButton(robot.xbox0,
                                      XboxController.Button.kStart)
        togglecamera.whenPressed(ToggleCamera(robot))
        stickbutton.whenPressed(DifferentialDriveWithXbox(robot))
        shoot.whileHeld(Shoot(robot))
        block.toggleWhenPressed(Block(robot))
        intake.whileHeld(Intake_Com(robot))
        shiftup.whenPressed(ShiftUp(robot))
        shiftdown.whenPressed(ShiftDown(robot))
Esempio n. 2
0
    def __init__(self, robot):
        '''The Constructor - assign Xbox controller buttons to specific Commands.
        '''

        print("In OI:__init__")

        robot.xbox0 = wpilib.XboxController(0)
        robot.xbox1 = wpilib.XboxController(1)
        """liftleft = JoystickButton(robot.xbox1, XboxController.Button.kA)
        lowerleft = JoystickButton(robot.xbox1, XboxController.Button.kB)
        liftright = JoystickButton(robot.xbox1, XboxController.Button.kX)
        lowerright = JoystickButton(robot.xbox1, XboxController.Button.kY)
        liftfront = JoystickButton(robot.xbox1, XboxController.Button.kStickLeft)
        lowerfront = JoystickButton(robot.xbox1, XboxController.Button.kStickRight)
        liftrear = JoystickButton(robot.xbox1, XboxController.Button.kBumperRight)
        lowerrear = JoystickButton(robot.xbox1, XboxController.Button.kBumperLeft)
        lift = JoystickButton(robot.xbox1, XboxController.Button.kStart)
        lower = JoystickButton(robot.xbox1, XboxController.Button.kBack)"""

        #claw = JoystickButton(robot.xbox1, XboxController.Button.kY)
        intake = JoystickButton(robot.xbox1, XboxController.Button.kA)
        liftwinch = JoystickButton(robot.xbox1,
                                   XboxController.Button.kBumperRight)
        lowerwinch = JoystickButton(robot.xbox1,
                                    XboxController.Button.kBumperLeft)
        ejectcargo = JoystickButton(robot.xbox1, XboxController.Button.kX)

        triggerbutton = TriggerButton(robot.xbox0, .1)
        punch = JoystickButton(robot.xbox0, XboxController.Button.kY)
        punchrear = JoystickButton(robot.xbox1, XboxController.Button.kY)
        hatch = JoystickButton(robot.xbox0, XboxController.Button.kX)
        #park = JoystickButton(robot.xbox0, XboxController.Button.kA)
        """liftleft.whileHeld(LiftLeft(robot))
        lowerleft.whileHeld(LowerLeft(robot))
        liftright.whileHeld(LiftRight(robot))
        lowerright.whileHeld(LowerRight(robot))
        liftfront.whileHeld(LiftFront(robot))#
        lowerfront.whileHeld(LowerFront(robot#
        liftrear.whileHeld(LiftRear(robot))
        lowerrear.whileHeld(LowerRear(robot))#
        lift.whileHeld(Lift(robot))
        lower.whileHeld(Lower(robot))"""

        triggerbutton.whenPressed(MoveArmWithTriggers(robot))
        intake.toggleWhenPressed(IntakeCargo(robot))
        ejectcargo.toggleWhenPressed(EjectCargo(robot))
        #claw.toggleWhenPressed(OpenClaw(robot))
        punch.whenPressed(Punch(robot))
        punch.whenReleased(Pull(robot))
        hatch.toggleWhenPressed(CoverHatch(robot))
        liftwinch.whileHeld(LiftWinch(robot))
        lowerwinch.whileHeld(LowerWinch(robot))
        punchrear.whenPressed(PunchRear(robot))
        punchrear.whenReleased(PullRear(robot))
Esempio n. 3
0
class OI:
    def __init__(self, robot):

        self.robot = robot
        self.xbox = wpilib.Joystick(0)

        self.l_trigger = self.xbox.getRawAxis(2)
        self.r_trigger = self.xbox.getRawAxis(3)

        self.l_bumper = JoystickButton(self.xbox, 6)
        self.r_bumper = JoystickButton(self.xbox, 5)

        self.a_button = JoystickButton(self.xbox, 1)
        self.b_button = JoystickButton(self.xbox, 2)
        self.steer = self.xbox.getRawAxis(0)
        self.speed = self.l_trigger - self.r_trigger

        self.a_button.whileHeld(Pop(self.robot))

        self.r_bumper.whileHeld(LiftFront(self.robot))
        self.l_bumper.whileHeld(LiftRear(self.robot))
        #self.a_button.toggleWhenPressed(DriveBot(self.robot))
        #self.b_button.toggleWhenPressed(Circles(self.robot))

    def getSteer(self):
        return 0.8 * (self.xbox.getRawAxis(0)**3)

    def getSpeed(self):
        l_trigger = self.xbox.getRawAxis(2)
        r_trigger = self.xbox.getRawAxis(3)
        return 0.8 * ((l_trigger - r_trigger)**3)

    def getIntakeSpeed(self):

        return self.xbox.getRawAxis(5)
Esempio n. 4
0
class MyRobot(wpilib.IterativeRobot):
    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.whileHeld(MoveForward())
        self.forward.whenReleased(Stop())

        self.backward.whileHeld(MoveBackward())
        self.backward.whenReleased(Stop())

        self.right.whileHeld(TurnRight())
        self.right.whenReleased(Stop())

        self.left.whileHeld(TurnLeft())
        self.left.whenReleased(Stop())

    def autonomousInit(self):
        '''Called only at the beginning of autonomous mode'''
        pass

    def autonomousPeriodic(self):
        '''Called every 20ms in autonomous mode'''
        pass

    def disabledInit(self):
        '''Called only at the beginning of disabled mode'''
        pass

    def disabledPeriodic(self):
        '''Called every 20ms in disabled mode'''
        pass

    def teleopInit(self):
        '''Called only at the beginning of teleoperated mode'''
        pass

    def teleopPeriodic(self):
        '''Called every 20ms in teleoperated mode'''
        Scheduler.getInstance().run()
Esempio n. 5
0
    def __init__(self, robot):
        '''The Constructor - assign Xbox controller buttons to specific Commands.
        '''

        print("In OI:__init__")

        robot.xbox0 = wpilib.XboxController(0)
        robot.xbox1 = wpilib.XboxController(1)

        stickbutton = StickButton(robot.xbox0, .1)
        shoot = JoystickButton(robot.xbox0, XboxController.Button.kA)
        block = JoystickButton(robot.xbox0, XboxController.Button.kY)
        intake = JoystickButton(robot.xbox0, XboxController.Button.kX)
        shiftup = JoystickButton(robot.xbox0,
                                 XboxController.Button.kBumperRight)
        shiftdown = JoystickButton(robot.xbox0,
                                   XboxController.Button.kBumperLeft)
        triggerbutton = TriggerButton(robot.xbox1, .1)
        extendclimber = JoystickButton(robot.xbox1, XboxController.Button.kA)

        agitate = JoystickButton(robot.xbox0, XboxController.Button.kA)

        #releaseshoot = JoystickButton(robot.xbox0, XboxController.Button.kA)
        eject = JoystickButton(robot.xbox0, XboxController.Button.kB)

        togglecamera = JoystickButton(robot.xbox0,
                                      XboxController.Button.kStart)
        togglecamera.whenPressed(ToggleCamera(robot))
        stickbutton.whenPressed(DifferentialDriveWithXbox(robot))
        shoot.whileHeld(Shoot(robot))
        block.toggleWhenPressed(Block(robot))
        intake.whileHeld(Intake_Com(robot))
        shiftup.whenPressed(ShiftUp(robot))
        shiftdown.whenPressed(ShiftDown(robot))
        triggerbutton.whenPressed(Climbwithtriggers(robot))
        extendclimber.toggleWhenPressed(Extendclimber(robot))

        agitate.whileHeld(Agitate(robot))

        #releaseshoot.whileHeld(ReleaseShoot(robot))
        eject.whileHeld(Cuntake(robot))
Esempio n. 6
0
File: oi.py Progetto: dklann/frc2019
    def __init__(self, robot):
        '''The Constructor - assign Xbox controller buttons to specific Commands.
        '''

        print("In OI:__init__")

        robot.xbox0 = wpilib.XboxController(0)
        robot.xbox1 = wpilib.XboxController(1)

        hatch = JoystickButton(robot.xbox0, XboxController.Button.kX)
        park = JoystickButton(robot.xbox0, XboxController.Button.kBack)
        togglecamera = JoystickButton(robot.xbox0,
                                      XboxController.Button.kStart)
        triggerbutton = TriggerButton(robot.xbox0, .1)
        stickbutton = StickButton(robot.xbox0, .1)

        ejectcargo = JoystickButton(robot.xbox1, XboxController.Button.kX)
        intakecargo = JoystickButton(robot.xbox1, XboxController.Button.kA)
        frontlift = JoystickButton(robot.xbox1, XboxController.Button.kStart)
        rearlift = JoystickButton(robot.xbox1, XboxController.Button.kBack)
        invertfront = JoystickButton(robot.xbox1,
                                     XboxController.Button.kStickRight)
        liftwinch = JoystickButton(robot.xbox1,
                                   XboxController.Button.kBumperRight)
        lowerwinch = JoystickButton(robot.xbox1,
                                    XboxController.Button.kBumperLeft)
        punchrear = JoystickButton(robot.xbox1, XboxController.Button.kY)

        hatch.toggleWhenPressed(CoverHatch(robot))
        park.whileHeld(Park(robot))
        togglecamera.whenPressed(ToggleCamera(robot))
        triggerbutton.whenPressed(MoveArmWithTriggers(robot))
        stickbutton.whenPressed(DifferentialDriveWithXbox(robot))

        ejectcargo.toggleWhenPressed(EjectCargo(robot))
        intakecargo.toggleWhenPressed(IntakeCargo(robot))
        frontlift.toggleWhenPressed(LiftFront(robot))
        rearlift.toggleWhenPressed(LiftRear(robot))
        invertfront.toggleWhenPressed(InvertFront(robot))
        liftwinch.whileHeld(LiftWinch(robot))
        lowerwinch.whileHeld(LowerWinch(robot))
        punchrear.whenReleased(PullRear(robot))
        punchrear.whenPressed(PunchRear(robot))
Esempio n. 7
0
    def __init__(self, robot):
        """Double joysticks WOOT"""
        print("Initializing joysticks...")

        #Initialise the stick and the smart dashboard (in case we need stuff for auton):
        self.stick = wpilib.Joystick(0)
        self.setpointStick = wpilib.Joystick(1)
        self.smart_dashboard = NetworkTable.getTable("SmartDashboard")

        #Main stick POV.
        #-----------------------------------------------------------------------
        drive_north = POVButton(self.stick, 0)
        drive_northeast = POVButton(self.stick, 45)
        drive_east = POVButton(self.stick, 90)
        drive_southeast = POVButton(self.stick, 135)
        drive_south = POVButton(self.stick, 180)
        drive_southwest = POVButton(self.stick, 225)
        drive_west = POVButton(self.stick, 270)
        drive_northwest = POVButton(self.stick, 315)

        #Setpoint stick button mapping.
        #-----------------------------------------------------------------------
        drive_trigger = JoystickButton(self.stick, 1)
        drive_thumb = JoystickButton(self.stick, 2)
        drive_bottom_left = JoystickButton(self.stick, 3)
        drive_bottom_right = JoystickButton(self.stick, 4)
        drive_top_left = JoystickButton(self.stick, 5)
        drive_top_right = JoystickButton(self.stick, 6)

        #Goes from front to back. outer_base is the outer ring of buttons on
        #the base, inner_base is the inner ring of buttons on the base.
        #-----------------------------------------------------------------------
        drive_outer_base_one = JoystickButton(self.stick, 7)
        drive_inner_base_one = JoystickButton(self.stick, 8)
        drive_outer_base_two = JoystickButton(self.stick, 9)
        drive_inner_base_two = JoystickButton(self.stick, 10)
        drive_outer_base_three = JoystickButton(self.stick, 11)
        drive_inner_base_three = JoystickButton(self.stick, 12)

        #Hat switch POV stuff.
        #-----------------------------------------------------------------------
        pov_north = POVButton(self.setpointStick, 0)
        pov_northeast = POVButton(self.setpointStick, 45)
        pov_east = POVButton(self.setpointStick, 90)
        pov_southeast = POVButton(self.setpointStick, 135)
        pov_south = POVButton(self.setpointStick, 180)
        pov_southwest = POVButton(self.setpointStick, 225)
        pov_west = POVButton(self.setpointStick, 270)
        pov_northwest = POVButton(self.setpointStick, 315)

        #Setpoint stick button mapping.
        #-----------------------------------------------------------------------
        bad_trigger = JoystickButton(self.setpointStick, 1)
        thumb = JoystickButton(self.setpointStick, 2)
        bottom_left = JoystickButton(self.setpointStick, 3)
        bottom_right = JoystickButton(self.setpointStick, 4)
        top_left = JoystickButton(self.setpointStick, 5)
        top_right = JoystickButton(self.setpointStick, 6)

        #Goes from front to back. outer_base is the outer ring of buttons on
        #the base, inner_base is the inner ring of buttons on the base.
        #-----------------------------------------------------------------------
        seven = JoystickButton(self.setpointStick, 7)
        eight = JoystickButton(self.setpointStick, 8)
        nine = JoystickButton(self.setpointStick, 9)
        ten = JoystickButton(self.setpointStick, 10)
        eleven = JoystickButton(self.setpointStick, 11)
        twelve = JoystickButton(self.setpointStick, 12)

        #-----------------------------------------------------------------------

        #Mapping of buttons.
        bad_trigger.whileHeld(HatButton(robot, 1))
        thumb.whileHeld(TiltButton(robot))
        pov_north.whileHeld(Intake(robot, .45, .3))
        pov_south.whileHeld(Intake(robot, -.5, -.5))
        bottom_left.whileHeld(EarsButton(robot, 1))
        bottom_right.whileHeld(EarsButton(robot, .4))
        top_left.whileHeld(Intake(robot, -.5, -.5))
        drive_thumb.whileHeld(Intake(robot, -.5, -.5))

        #Give the message to confirm initialisation
        print("Joysticks initialized")
Esempio n. 8
0
    def __init__(self, robot):

        self.robot = robot

        self.left_joy = robot.left_joy
        self.right_joy = robot.right_joy
        self.xbox = robot.xbox

        # First character indicates self.right or self.left,
        # second indicates position,
        # third indicates which button of the position specified
        # Ex: ltop0 is self.left top 0
        '''
		JoystickButton and Xbox button assignments
		'''
        ltop1 = JoystickButton(self.left_joy, 1)
        ltop2 = JoystickButton(self.left_joy, 2)
        ltop3 = JoystickButton(self.left_joy, 3)
        ltop4 = JoystickButton(self.left_joy, 4)
        ltop5 = JoystickButton(self.left_joy, 5)
        ltop6 = JoystickButton(self.left_joy, 6)

        rtop1 = JoystickButton(self.right_joy, 1)
        rtop2 = JoystickButton(self.right_joy, 2)
        rtop3 = JoystickButton(self.right_joy, 3)
        rtop4 = JoystickButton(self.right_joy, 4)
        rtop5 = JoystickButton(self.right_joy, 5)
        rtop6 = JoystickButton(self.right_joy, 6)

        xboxX = JoystickButton(self.xbox, 3)
        xboxY = JoystickButton(self.xbox, 4)
        xboxB = JoystickButton(self.xbox, 2)
        xboxA = JoystickButton(self.xbox, 1)
        xboxLB = JoystickButton(self.xbox, 5)
        xboxRB = JoystickButton(self.xbox, 6)
        #xbox_left_XY = self.xbox.getY(9)
        #self.xbox_XY = JoystickButton(self.xbox, 9)
        self.xbox_left_XY = self.xbox.getX()
        xboxBACK = JoystickButton(self.xbox, 7)
        xboxSTART = JoystickButton(self.xbox, 8)

        # whenActive and whenInactive allows toggle between 2 commands
        '''
		Joystick 0 / Left Joystick Commands
		'''
        # Button 1 causes cargo motor to spin outwards for 0.5s
        #ltop1.whileHeld(Do_Cargo_Eject(robot))

        # Button 2 shuts down arm
        #ltop2.whileHeld(Do_Die_You_Gravy_Sucking_Pig(robot))

        #XXX
        #ltop4.whenPressed(Do_Encoder_Check(robot))

        ltop5.whileHeld(Do_Beak_Open(robot))
        '''
		Joystick 1 / Right Joystick Commands
		'''
        # Button 2 toggles shifters
        rtop2.toggleWhenPressed(Do_Shifters_Toggle(robot))

        # All the way back, 0 deg

        # for testing in sim
        #rtop5.whenPressed(Do_Axis_Button_5(robot))
        '''
		Joystick 2 / Xbox Controller Commands
		'''
        #xboxSTART.whenPressed(Command_Ramp(robot))

        # Y = Defence Position (straight up)
        #xboxY.whenPressed(Command_Defense(robot))

        # B = Hatch Panel Intake (front of robot)
        # B for BEAK
        xboxB.whileHeld(Do_Beak_Open(robot))
        # Out of Frame
        xboxX.whenPressed(Do_Four_Bar(robot))
        # In frame
        xboxA.whenPressed(Do_Undo_Four_Bar(robot))
Esempio n. 9
0
    def __init__(self, robot):
        """Double joysticks WOOT"""
        print("Initializing joysticks...")

        #Initialise the stick and the smart dashboard (in case we need stuff for auton):
        self.stick = wpilib.Joystick(0)
        self.setpointStick = wpilib.Joystick(1)
        self.smart_dashboard = NetworkTable.getTable("SmartDashboard")

        #Main stick POV.
        #-----------------------------------------------------------------------
        drive_north = POVButton(self.stick, 0)
        drive_northeast = POVButton(self.stick, 45)
        drive_east = POVButton(self.stick, 90)
        drive_southeast = POVButton(self.stick, 135)
        drive_south = POVButton(self.stick, 180)
        drive_southwest = POVButton(self.stick, 225)
        drive_west = POVButton(self.stick, 270)
        drive_northwest = POVButton(self.stick, 315)

        #Setpoint stick button mapping.
        #-----------------------------------------------------------------------
        drive_trigger = JoystickButton(self.stick, 1)
        drive_thumb = JoystickButton(self.stick, 2)
        drive_bottom_left = JoystickButton(self.stick, 3)
        drive_bottom_right = JoystickButton(self.stick, 4)
        drive_top_left = JoystickButton(self.stick, 5)
        drive_top_right = JoystickButton(self.stick, 6)


        #Goes from front to back. outer_base is the outer ring of buttons on
        #the base, inner_base is the inner ring of buttons on the base.
        #-----------------------------------------------------------------------
        drive_outer_base_one = JoystickButton(self.stick, 7)
        drive_inner_base_one = JoystickButton(self.stick, 8)
        drive_outer_base_two = JoystickButton(self.stick, 9)
        drive_inner_base_two = JoystickButton(self.stick, 10)
        drive_outer_base_three = JoystickButton(self.stick, 11)
        drive_inner_base_three = JoystickButton(self.stick, 12)


        #Hat switch POV stuff.
        #-----------------------------------------------------------------------
        pov_north = POVButton(self.setpointStick, 0)
        pov_northeast = POVButton(self.setpointStick, 45)
        pov_east = POVButton(self.setpointStick, 90)
        pov_southeast = POVButton(self.setpointStick, 135)
        pov_south = POVButton(self.setpointStick, 180)
        pov_southwest = POVButton(self.setpointStick, 225)
        pov_west = POVButton(self.setpointStick, 270)
        pov_northwest = POVButton(self.setpointStick, 315)


        #Setpoint stick button mapping.
        #-----------------------------------------------------------------------
        bad_trigger = JoystickButton(self.setpointStick, 1)
        thumb = JoystickButton(self.setpointStick, 2)
        bottom_left = JoystickButton(self.setpointStick, 3)
        bottom_right = JoystickButton(self.setpointStick, 4)
        top_left = JoystickButton(self.setpointStick, 5)
        top_right = JoystickButton(self.setpointStick, 6)


        #Goes from front to back. outer_base is the outer ring of buttons on
        #the base, inner_base is the inner ring of buttons on the base.
        #-----------------------------------------------------------------------
        seven = JoystickButton(self.setpointStick, 7)
        eight = JoystickButton(self.setpointStick, 8)
        nine = JoystickButton(self.setpointStick, 9)
        ten = JoystickButton(self.setpointStick, 10)
        eleven = JoystickButton(self.setpointStick, 11)
        twelve = JoystickButton(self.setpointStick, 12)

        #-----------------------------------------------------------------------

        #Mapping of buttons.
        bad_trigger.whileHeld(HatButton(robot, 1))
        thumb.whileHeld(TiltButton(robot))
        pov_north.whileHeld(Intake(robot, .45, .3))
        pov_south.whileHeld(Intake(robot, -.5, -.5))
        bottom_left.whileHeld(EarsButton(robot, 1))
        bottom_right.whileHeld(EarsButton(robot, .4))
        top_left.whileHeld(Intake(robot, -.5, -.5))
        drive_thumb.whileHeld(Intake(robot, -.5, -.5))

        #Give the message to confirm initialisation
        print("Joysticks initialized")
Esempio n. 10
0
    def __init__(self, robot):
        """Warning: Metric tonnes of code here. May need to be tidied up a wee bit."""

        self.stick_left = wpilib.Joystick(0)
        self.pad = wpilib.Joystick(1)
        self.smart_dashboard = NetworkTable.getTable("SmartDashboard")

        #Buttons? Aw, man, I love buttons! *bleep bloop*
        #-----------------------------------------------

        # Create some buttons on the left stick (which is really not, but I don't wanna disturb the preexisting code).
        left_trigger = JoystickButton(self.stick_left, 1)
        left_thumb = JoystickButton(self.stick_left, 2)
        left_three = JoystickButton(self.stick_left, 3)
        left_four = JoystickButton(self.stick_left, 4)
        left_five = JoystickButton(self.stick_left, 5)
        left_six = JoystickButton(self.stick_left, 6)
        left_seven = JoystickButton(self.stick_left, 7)
        left_eight = JoystickButton(self.stick_left, 8)
        left_nine = JoystickButton(self.stick_left, 9)
        left_ten = JoystickButton(self.stick_left, 10)
        left_eleven = JoystickButton(self.stick_left, 11)
        left_twelve = JoystickButton(self.stick_left, 12)
        #Create some POV stuff on the left stick, based on angles and the hat switch
        left_north = POVButton(self.stick_left, 0)
        left_northeast = POVButton(self.stick_left, 45)
        left_east = POVButton(self.stick_left, 90)
        left_southeast = POVButton(self.stick_left, 135)
        left_south = POVButton(self.stick_left, 180)
        left_southwest = POVButton(self.stick_left, 225)
        left_west = POVButton(self.stick_left, 270)
        left_northwest = POVButton(self.stick_left, 315)

        #Keypad Buttons
        g0 = JoystickButton(self.pad, 1)
        g1 = KeyButton(self.smart_dashboard, 10)
        g2 = KeyButton(self.smart_dashboard, 11)
        g3 = KeyButton(self.smart_dashboard, 12)
        g4 = KeyButton(self.smart_dashboard, 13)
        g5 = KeyButton(self.smart_dashboard, 14)
        g6 = KeyButton(self.smart_dashboard, 15)
        g7 = KeyButton(self.smart_dashboard, 16)
        g8 = KeyButton(self.smart_dashboard, 17)
        g9 = KeyButton(self.smart_dashboard, 18)
        g10 = KeyButton(self.smart_dashboard, 19)
        g11 = KeyButton(self.smart_dashboard, 20)
        g12 = KeyButton(self.smart_dashboard, 21)
        g13 = KeyButton(self.smart_dashboard, 22)
        g14 = KeyButton(self.smart_dashboard, 23)
        g15 = KeyButton(self.smart_dashboard, 24)
        g16 = KeyButton(self.smart_dashboard, 25)
        g17 = KeyButton(self.smart_dashboard, 26)
        g18 = KeyButton(self.smart_dashboard, 27)
        g19 = KeyButton(self.smart_dashboard, 28)
        g20 = KeyButton(self.smart_dashboard, 29)
        g21 = KeyButton(self.smart_dashboard, 30)
        g22 = KeyButton(self.smart_dashboard, 31)
        topshift = KeyButton(self.smart_dashboard, 32)
        bottomshift = KeyButton(self.smart_dashboard, 33)

        # Connect buttons & commands
        #---------------------------

        #Bump commands
        left_south.whenPressed(DriveStraight(robot, 0, .25, timeout=.25))
        left_north.whenPressed(DriveStraight(robot, 0, -.25, timeout=.25))
        left_east.whenPressed(DriveStraight(robot, .25, 0, timeout=.35))
        left_west.whenPressed(DriveStraight(robot, -.25, 0, timeout=.35))

        #Mast control
        left_thumb.whileHeld(Shaker(robot))
        left_five.whileHeld(MastButton(robot, .38))
        left_six.whileHeld(MastButton(robot, -.38))

        #SuperStrafe
        left_seven.whenPressed(SuperStrafe64(robot, SuperStrafe64.kForward))
        left_eight.whenPressed(SuperStrafe64(robot, SuperStrafe64.kBack))
        left_nine.whenPressed(SuperStrafe64(robot, SuperStrafe64.kLeft))
        left_ten.whenPressed(SuperStrafe64(robot, SuperStrafe64.kRight))

        #Lift presets
        g1.whileHeld(LiftGoToLevelShift(robot, 1, topshift, bottomshift))
        g2.whileHeld(LiftGoToLevelShift(robot, 2, topshift, bottomshift))
        g3.whileHeld(LiftGoToLevelShift(robot, 4, topshift, bottomshift))
        g4.whileHeld(LiftGoToLevelShift(robot, 0, topshift, bottomshift))
        g5.whenPressed(OpenClaw(robot))
        g6.whenPressed(GrabTote(robot))
        g7.whenPressed(GrabCan(robot))

        #Never, under ANY circumstances, run these during a match.
        #g9.whenPressed(RecordMacro(robot, "macro.csv"))
        #g10.whenPressed(PlayMacro(robot, "macro.csv"))
        #RecordMacro(robot, "macro.csv")
        #PlayMacro(robot, "macro.csv")

        g11.whenPressed(RecordMacro(robot, "macro_1.csv"))
        g12.whenPressed(PlayMacro(robot, "macro_1.csv"))
        #RecordMacro(robot, "macro_1.csv")
        #PlayMacro(robot, "macro_1.csv")

        #g13.whenPressed(RecordMacro(robot, "autonomous.csv"))
        #g14.whenPressed(PlayMacro(robot, "autonomous.csv"))
        #RecordMacro(robot, "autonomous.csv")
        #PlayMacro(robot, "autonomous.csv")

        #g15.whenPressed(RecordMacro(robot, "macro_3.csv"))
        #g16.whenPressed(PlayMacro(robot, "macro_3.csv"))

        #Winchy thing
        g17.whileHeld(WinchButton(robot, .5))
        g18.whileHeld(WinchButton(robot, -.5))

        g19.whenPressed(GrabSpecialTote(robot))

        #Mast
        g20.whileHeld(MastBack(robot))
        g21.whileHeld(MastLevel(robot))
        g22.whileHeld(MastForward(robot))
Esempio n. 11
0
    def __init__(self, robot):
        """Warning: Metric tonnes of code here. May need to be tidied up a wee bit."""

        self.stick_left = wpilib.Joystick(0)
        self.pad = wpilib.Joystick(1)
        self.smart_dashboard = NetworkTable.getTable("SmartDashboard")

        #Buttons? Aw, man, I love buttons! *bleep bloop*
        #-----------------------------------------------

        # Create some buttons on the left stick (which is really not, but I don't wanna disturb the preexisting code).
        left_trigger = JoystickButton(self.stick_left, 1)
        left_thumb = JoystickButton(self.stick_left, 2)
        left_three = JoystickButton(self.stick_left, 3)
        left_four = JoystickButton(self.stick_left, 4)
        left_five = JoystickButton(self.stick_left, 5)
        left_six = JoystickButton(self.stick_left, 6)
        left_seven = JoystickButton(self.stick_left, 7)
        left_eight = JoystickButton(self.stick_left, 8)
        left_nine = JoystickButton(self.stick_left, 9)
        left_ten = JoystickButton(self.stick_left, 10)
        left_eleven = JoystickButton(self.stick_left, 11)
        left_twelve = JoystickButton(self.stick_left, 12)
        #Create some POV stuff on the left stick, based on angles and the hat switch
        left_north = POVButton(self.stick_left, 0)
        left_northeast = POVButton(self.stick_left, 45)
        left_east = POVButton(self.stick_left, 90)
        left_southeast = POVButton(self.stick_left, 135)
        left_south = POVButton(self.stick_left, 180)
        left_southwest = POVButton(self.stick_left, 225)
        left_west = POVButton(self.stick_left, 270)
        left_northwest = POVButton(self.stick_left, 315)

        #Keypad Buttons
        g0 = JoystickButton(self.pad, 1)
        g1 = KeyButton(self.smart_dashboard, 10)
        g2 = KeyButton(self.smart_dashboard, 11)
        g3 = KeyButton(self.smart_dashboard, 12)
        g4 = KeyButton(self.smart_dashboard, 13)
        g5 = KeyButton(self.smart_dashboard, 14)
        g6 = KeyButton(self.smart_dashboard, 15)
        g7 = KeyButton(self.smart_dashboard, 16)
        g8 = KeyButton(self.smart_dashboard, 17)
        g9 = KeyButton(self.smart_dashboard, 18)
        g10 = KeyButton(self.smart_dashboard, 19)
        g11 = KeyButton(self.smart_dashboard, 20)
        g12 = KeyButton(self.smart_dashboard, 21)
        g13 = KeyButton(self.smart_dashboard, 22)
        g14 = KeyButton(self.smart_dashboard, 23)
        g15 = KeyButton(self.smart_dashboard, 24)
        g16 = KeyButton(self.smart_dashboard, 25)
        g17 = KeyButton(self.smart_dashboard, 26)
        g18 = KeyButton(self.smart_dashboard, 27)
        g19 = KeyButton(self.smart_dashboard, 28)
        g20 = KeyButton(self.smart_dashboard, 29)
        g21 = KeyButton(self.smart_dashboard, 30)
        g22 = KeyButton(self.smart_dashboard, 31)
        topshift = KeyButton(self.smart_dashboard, 32)
        bottomshift = KeyButton(self.smart_dashboard, 33)

        # Connect buttons & commands
        #---------------------------

        #Bump commands
        left_south.whenPressed(DriveStraight(robot, 0, .25, timeout = .25))
        left_north.whenPressed(DriveStraight(robot, 0, -.25, timeout = .25))
        left_east.whenPressed(DriveStraight(robot, .25, 0, timeout = .35))
        left_west.whenPressed(DriveStraight(robot, -.25, 0, timeout = .35))

        #Mast control
        left_thumb.whileHeld(Shaker(robot))
        left_five.whileHeld(MastButton(robot, .38))
        left_six.whileHeld(MastButton(robot, -.38))

        #SuperStrafe
        left_seven.whenPressed(SuperStrafe64(robot, SuperStrafe64.kForward))
        left_eight.whenPressed(SuperStrafe64(robot, SuperStrafe64.kBack))
        left_nine.whenPressed(SuperStrafe64(robot, SuperStrafe64.kLeft))
        left_ten.whenPressed(SuperStrafe64(robot, SuperStrafe64.kRight))

        #Lift presets
        g1.whileHeld(LiftGoToLevelShift(robot, 1, topshift, bottomshift))
        g2.whileHeld(LiftGoToLevelShift(robot, 2, topshift, bottomshift))
        g3.whileHeld(LiftGoToLevelShift(robot, 4, topshift, bottomshift))
        g4.whileHeld(LiftGoToLevelShift(robot, 0, topshift, bottomshift))
        g5.whenPressed(OpenClaw(robot))
        g6.whenPressed(GrabTote(robot))
        g7.whenPressed(GrabCan(robot))

        #Never, under ANY circumstances, run these during a match.
        #g9.whenPressed(RecordMacro(robot, "macro.csv"))
        #g10.whenPressed(PlayMacro(robot, "macro.csv"))
        #RecordMacro(robot, "macro.csv")
        #PlayMacro(robot, "macro.csv")

        g11.whenPressed(RecordMacro(robot, "macro_1.csv"))
        g12.whenPressed(PlayMacro(robot, "macro_1.csv"))
        #RecordMacro(robot, "macro_1.csv")
        #PlayMacro(robot, "macro_1.csv")

        #g13.whenPressed(RecordMacro(robot, "autonomous.csv"))
        #g14.whenPressed(PlayMacro(robot, "autonomous.csv"))
        #RecordMacro(robot, "autonomous.csv")
        #PlayMacro(robot, "autonomous.csv")


        #g15.whenPressed(RecordMacro(robot, "macro_3.csv"))
        #g16.whenPressed(PlayMacro(robot, "macro_3.csv"))

        #Winchy thing
        g17.whileHeld(WinchButton(robot, .5))
        g18.whileHeld(WinchButton(robot, -.5))

        g19.whenPressed(GrabSpecialTote(robot))

        #Mast
        g20.whileHeld(MastBack(robot))
        g21.whileHeld(MastLevel(robot))
        g22.whileHeld(MastForward(robot))
Esempio n. 12
0
class OI:
    """
    OI defines the operator interface for Ares.
        - two joysticks with many associated buttons
        - smartdashboard widgets
    """
    # Joysticks
    k_driveStickPort = 0
    k_launcherStickPort = 1

    # DriveStick Commands - controls for driver:
    #   move, turn, throttle, intake, drive, intake ball
    k_intakeBallButton = 3
    k_aimIntakeButton = 4
    k_driveStopIntakeWheelsButton = 5
    k_aimNeutralButton = 6
    k_turnThrottleButton = 8
    k_driveStrightButton = 11 # experimental

    # LauncherStick Commands - controls for mechanism operator:
    #   aim, shoot, portcullis
    k_lightSwitchButton = 2
    k_kickBallButton = 3
    k_spinIntakeWheelsOutButton = 4
    k_stopIntakeWheelsButton = 5
    k_pcUpButton = 6  # Pc is portcullis
    k_pcDownButton = 7
    k_pcBarStopButton = 9
    k_pcBarInButton = 10
    k_pcBarOutButton = 11

    # Auto positions are numbered (1-5), position 1 is special
    k_LowBarPosition = 1

    # Auto barrier
    k_LowBarBarrier = 0
    k_MoatBarrier = 1
    k_RoughTerrainBarrier = 2
    k_RockWallBarrier = 3
    k_PortcullisBarrier = 4
    k_RampartsBarrier = 5

    # Auto strategy
    k_NoMoveStrategy = 0
    k_CrossStrategy = 1
    k_CrossBlindShotStrategy = 2
    k_CrossVisionShotStrategy = 3

    def __init__(self, robot):
        self.robot = robot
        self.driveStick = wpilib.Joystick(OI.k_driveStickPort)
        self.aimStick = wpilib.Joystick(OI.k_launcherStickPort)

        self.initDriveTrain()
        self.initLauncher()
        self.initPortcullis()
        self.initAutonomous()
        self.initVision()

        self.initSmartDashboard()

    def initDriveTrain(self):
        ds = self.driveStick
        self.dtTurnThrottleButton = JoystickButton(ds, OI.k_turnThrottleButton)
        # TODO: convert whileHeld/whenRealsed pair to a single command
        self.dtTurnThrottleButton.whileHeld(DTCmds.TurnSpeedSlow(self.robot))
        self.dtTurnThrottleButton.whenReleased(DTCmds.TurnSpeedFast(self.robot))

    def initLauncher(self):
        aS = self.aimStick
        dS = self.driveStick

        self.kickBallButton = JoystickButton(aS, OI.k_kickBallButton)
        self.kickBallButton.whenPressed(ILCmds.LaunchBallCommandGroup(self.robot))

        # TODO: Java code had two buttons for stop wheels
        self.mechStopWheelsButton = JoystickButton(aS, OI.k_stopIntakeWheelsButton)
        self.mechStopWheelsButton.whenPressed(ILCmds.StopWheelsCommand(self.robot))

        self.grabBallButton = JoystickButton(dS, OI.k_intakeBallButton)
        self.grabBallButton.whenPressed(ILCmds.IntakeBallCommandGroup(self.robot))

        self.spinIntakeWheelsOutButton = JoystickButton(aS, OI.k_spinIntakeWheelsOutButton)
        self.spinIntakeWheelsOutButton.whenPressed(ILCmds.SpinIntakeWheelsCommand(self.robot, "out"))

        self.driveLauncherJumpToIntakeButton = JoystickButton(dS, OI.k_aimIntakeButton)
        self.driveLauncherJumpToIntakeButton.whenPressed(ILCmds.LauncherGoToIntakeCommand(self.robot))

        # TODO: Java code had two buttons for neutral
        self.driveLauncherJumpToNeutralButton = JoystickButton(aS, OI.k_aimNeutralButton)
        self.driveLauncherJumpToNeutralButton.whenPressed(ILCmds.LauncherGoToNeutralCommand(self.robot))

    def initVision(self):
        s = self.aimStick
        self.lightSwitchButton = JoystickButton(s, OI.k_lightSwitchButton)
        self.lightSwitchButton.whenPressed(VCmds.LightSwitchCmd(self.robot))

    def initPortcullis(self):
        s = self.aimStick
        self.pcUpButton = JoystickButton(s, OI.k_pcUpButton)
        self.pcUpButton.whenPressed(PCmds.MoveUp(self.robot))

        self.pcDownButton = JoystickButton(s, OI.k_pcDownButton)
        self.pcDownButton.whenPressed(PCmds.MoveDown(self.robot))

        self.pcBarInButton = JoystickButton(s, OI.k_pcBarInButton)
        self.pcBarInButton.whenPressed(PCmds.BarIn(self.robot))

        self.pcBarOutButton = JoystickButton(s, OI.k_pcBarOutButton)
        self.pcBarOutButton.whenPressed(PCmds.BarOut(self.robot))

        self.pcBarStopButton = JoystickButton(s, OI.k_pcBarStopButton)
        self.pcBarStopButton.whenPressed(PCmds.BarStop(self.robot))

    def initAutonomous(self):
        ch = SendableChooser()
        ch.addDefault("1: Low Bar", self.k_LowBarPosition)
        ch.addObject("2", 2)
        ch.addObject("3", 3)
        ch.addObject("4", 4)
        ch.addObject("5", 5)
        self.startingFieldPosition = ch

        ch = SendableChooser()
        ch.addDefault("Low Bar", self.k_LowBarBarrier)
        ch.addObject("Moat", self.k_MoatBarrier)
        ch.addObject("Rough Terrain", self.k_RoughTerrainBarrier)
        ch.addObject("Rock Wall", self.k_RockWallBarrier)
        ch.addObject("Portcullis", self.k_PortcullisBarrier)
        ch.addObject("Ramparts", self.k_RampartsBarrier)
        self.barrierType = ch

        ch = SendableChooser()
        ch.addDefault("None", self.k_NoMoveStrategy)
        ch.addObject("Cross Only", self.k_CrossStrategy)
        ch.addObject("Cross, Blind Shot", self.k_CrossBlindShotStrategy)
        ch.addObject("Cross, Vision Shot",self.k_CrossVisionShotStrategy)
        self.strategy = ch

    def initSmartDashboard(self):
        SmartDashboard.putData("AutoFieldPosition", self.startingFieldPosition)
        SmartDashboard.putData("AutoBarrierType", self.barrierType)
        SmartDashboard.putData("AutoStrategy", self.strategy)