class OI(): __instances = None DEADZONE = 1 / 128 def __init__(self): self.driverController = XboxController(0) self.manipulatorController = XboxController(1) self.aButtonDriver = JoystickButton(self.driverController, 0) self.aButtonDriver.whenPressed(DriveStraightCommand(10)) @staticmethod def getInstance() -> OI: if (OI.__instances == None): OI.__instances = OI() return OI.__instances def __deadzone(self, input, deadzone=DEADZONE) -> Number: absValue = math.fabs(input) # no signum ;-; return 0 if abs < deadzone else ((absValue - deadzone) / (1.0 - deadzone) * math.copysign(1, input)) def getLeftY(self): return self.__deadzone( self.driverController.getY(GenericHID.Hand.kLeft)) def getRightY(self): return self.__deadzone( self.driverController.getY(GenericHID.Hand.kRight))
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))
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.kTriggerButton) trigger.whenPressed(Crash()) return joystick
def init(): global driverOne global driverTwo driverOne = XboxController(robotmap.USB_PORT_DRIVER_ONE) driverTwo = XboxController(robotmap.USB_PORT_DRIVER_TWO) toggleLauncher = JoystickButton(driverTwo, robotmap.BUTTON_A) toggleLauncher.whenPressed(LaunchHatchCommand()) toggleLauncher.whenReleased(RetractCommand()) toggleFront = JoystickButton(driverTwo, robotmap.BUTTON_RIGHT_BUMPER) toggleFront.whenReleased(ToggleFrontCommand()) toggleRear = JoystickButton(driverTwo, robotmap.BUTTON_LEFT_BUMPER) toggleRear.whenReleased(ToggleRearCommand())
class OI: """ Operator interface of the robot. Manages commands to run based on driver input. """ def __init__(self, robot): self.robot = robot self.driver_joystick = wpilib.Joystick(0) self.copilot_joystick = wpilib.Joystick(1) self.driver_a_button = JoystickButton(self.driver_joystick, ctrlmap.BUTTON_A) self.driver_b_button = JoystickButton(self.driver_joystick, ctrlmap.BUTTON_B) self.driver_a_button.whenPressed(dcmds.SetDriveSpeedMult(robot, 1)) self.driver_b_button.whenPressed(dcmds.SetDriveSpeedMult(robot, 0.5))
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))
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))
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.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()) 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()
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))
def __init__ (self, robot): robot.joystick = wpilib.Joystick(0) robot.joystick1 = wpilib.Joystick(1) L3_button = JoystickButton(robot.joystick1, 9) LB_button = JoystickButton(robot.joystick1, 5) A_button = JoystickButton(robot.joystick1, 1) B_button = JoystickButton(robot.joystick1, 2) X_button = JoystickButton(robot.joystick1, 3) Y_button = JoystickButton(robot.joystick1, 4) L3_button.whenPressed(TurboDrive()) L3_button.whenReleased(FollowJoystick()) LB_button.whenPressed(Align()) LB_button.whenReleased(FollowJoystick()) X_button.whenPressed(MoveClawTo(power=-.5)) X_button.whenReleased(MoveClawTo(power=0)) B_button.whenPressed(MoveClawTo(power=.5)) B_button.whenReleased(MoveClawTo(power=0)) Y_button.whenPressed(MoveArmTo(power=-1)) Y_button.whenReleased(MoveArmTo(power=0)) A_button.whenPressed(MoveArmTo(power=1)) A_button.whenReleased(MoveArmTo(power=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)
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))
def __init__(self, robot): self.joy = wpilib.Joystick(0) # Put Some buttons on the SmartDashboard SmartDashboard.putData("Elevator Bottom", SetElevatorSetpoint(robot, 0)); SmartDashboard.putData("Elevator Platform", SetElevatorSetpoint(robot, 0.2)); SmartDashboard.putData("Elevator Top", SetElevatorSetpoint(robot, 0.3)); SmartDashboard.putData("Wrist Horizontal", SetWristSetpoint(robot, 0)); SmartDashboard.putData("Raise Wrist", SetWristSetpoint(robot, -45)); SmartDashboard.putData("Open Claw", OpenClaw(robot)); SmartDashboard.putData("Close Claw", CloseClaw(robot)); SmartDashboard.putData("Deliver Soda", Autonomous(robot)); # Create some buttons d_up = JoystickButton(self.joy, 5) d_right = JoystickButton(self.joy, 6) d_down = JoystickButton(self.joy, 7) d_left = JoystickButton(self.joy, 8) l2 = JoystickButton(self.joy, 9) r2 = JoystickButton(self.joy, 10) l1 = JoystickButton(self.joy, 11) r1 = JoystickButton(self.joy, 12) # Connect the buttons to commands d_up.whenPressed(SetElevatorSetpoint(robot, 0.2)) d_down.whenPressed(SetElevatorSetpoint(robot, -0.2)) d_right.whenPressed(CloseClaw(robot)) d_left.whenPressed(OpenClaw(robot)) r1.whenPressed(PrepareToPickup(robot)) r2.whenPressed(Pickup(robot)) l1.whenPressed(Place(robot)) l2.whenPressed(Autonomous(robot))
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))
def __init__(self, robot): self.joy = wpilib.Joystick(0) # Put Some buttons on the SmartDashboard SmartDashboard.putData("Elevator Bottom", SetElevatorSetpoint(robot, 0)) SmartDashboard.putData("Elevator Platform", SetElevatorSetpoint(robot, 0.2)) SmartDashboard.putData("Elevator Top", SetElevatorSetpoint(robot, 0.3)) SmartDashboard.putData("Wrist Horizontal", SetWristSetpoint(robot, 0)) SmartDashboard.putData("Raise Wrist", SetWristSetpoint(robot, -45)) SmartDashboard.putData("Open Claw", OpenClaw(robot)) SmartDashboard.putData("Close Claw", CloseClaw(robot)) SmartDashboard.putData("Deliver Soda", Autonomous(robot)) # Create some buttons d_up = JoystickButton(self.joy, 5) d_right = JoystickButton(self.joy, 6) d_down = JoystickButton(self.joy, 7) d_left = JoystickButton(self.joy, 8) l2 = JoystickButton(self.joy, 9) r2 = JoystickButton(self.joy, 10) l1 = JoystickButton(self.joy, 11) r1 = JoystickButton(self.joy, 12) # Connect the buttons to commands d_up.whenPressed(SetElevatorSetpoint(robot, 0.2)) d_down.whenPressed(SetElevatorSetpoint(robot, -0.2)) d_right.whenPressed(CloseClaw(robot)) d_left.whenPressed(OpenClaw(robot)) r1.whenPressed(PrepareToPickup(robot)) r2.whenPressed(Pickup(robot)) l1.whenPressed(Place(robot)) l2.whenPressed(Autonomous(robot))
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))
class OI(object): """ The operator interface of the robot. Note we use competition_mode to determine if we will initialize a second joystick """ def __init__(self, robot): self.robot = robot if not robot.debug: self.initialize_joysitics() else: self.stick = wpilib.Joystick(0) # SmartDashboard Buttons - test some autonomous commands here SmartDashboard.putNumber("Auto Distance", 10) SmartDashboard.putNumber("Auto Rotation", 10) SmartDashboard.putData("Drive Forward", AutonomousDrive(robot, setpoint=None, control_type='position', timeout=6)) SmartDashboard.putData("Rotate X", AutonomousRotate(robot, setpoint=None, timeout=6)) SmartDashboard.putData("Update Pos PIDs", (UpdatePIDs(robot, factor=1, from_dashboard='position'))) SmartDashboard.putData("Update Vel PIDs", (UpdatePIDs(robot, factor=1, from_dashboard='velocity'))) def initialize_joysitics(self): robot = self.robot self.stick = wpilib.Joystick(0) self.buttonA = JoystickButton(self.stick, 1) self.buttonB = JoystickButton(self.stick, 2) self.buttonX = JoystickButton(self.stick, 3) self.buttonY = JoystickButton(self.stick, 4) self.buttonLB = JoystickButton(self.stick, 5) self.buttonRB = JoystickButton(self.stick, 6) self.buttonBack = JoystickButton(self.stick, 7) self.buttonStart = JoystickButton(self.stick, 8) self.povButtonUp = POVButton(self.stick, 0) self.povButtonDown = POVButton(self.stick, 180) self.povButtonRight = POVButton(self.stick, 90) self.povButtonLeft = POVButton(self.stick, 270) self.axisButtonLT = AxisButton(self.stick, 2) self.axisButtonRT = AxisButton(self.stick, 3) # binding button to commands self.axisButtonRT.whenPressed(Intake(robot, power=0, button=self.axisButtonRT)) self.axisButtonLT.whenPressed(Intake(robot, power=0, button=self.axisButtonLT)) self.buttonRB.whenPressed(ActuateGate(robot, direction="open")) self.buttonLB.whenPressed(ActuateGate(robot, direction="close")) self.buttonA.whenPressed(UpdatePIDs(robot,1.5, from_dashboard=False)) self.buttonB.whenPressed(UpdatePIDs(robot,0.66, from_dashboard=False)) self.buttonX.whenPressed(PneumaticPiston(robot, 'open')) self.buttonY.whenPressed(PneumaticPiston(robot, 'close')) #self.buttonLB.whenPressed(AutonomousDrive(robot, setpoint=250, control_type='velocity', button=self.buttonLB, from_dashboard=False)) #self.buttonRB.whenPressed(AutonomousDrive(robot, setpoint=500, control_type='velocity', button=self.buttonRB, from_dashboard=False)) # self.buttonBack.whenPressed # self.buttonStart.whenPressed # self.axisButtonLT.whenPressed # self.axisButtonRT.whenPressed self.povButtonUp.whenPressed(DpadDrive(robot,"up",self.povButtonUp)) self.povButtonDown.whenPressed(DpadDrive(robot, "down", self.povButtonDown)) self.povButtonRight.whenPressed(DpadDrive(robot, "right", self.povButtonRight)) self.povButtonLeft.whenPressed(DpadDrive(robot, "left", self.povButtonLeft)) # add/change bindings if we are using more than one joystick self.competition_mode = True if self.competition_mode: self.co_stick = wpilib.Joystick(1) self.co_buttonA = JoystickButton(self.co_stick, 1) self.co_buttonB = JoystickButton(self.co_stick, 2) self.co_buttonX = JoystickButton(self.co_stick, 3) self.co_buttonY = JoystickButton(self.co_stick, 4) self.co_buttonLB = JoystickButton(self.co_stick, 5) self.co_buttonRB = JoystickButton(self.co_stick, 6) self.co_buttonBack = JoystickButton(self.co_stick, 7) self.co_buttonStart = JoystickButton(self.co_stick, 8) self.co_povButtonUp = POVButton(self.co_stick, 0) self.co_povButtonDown = POVButton(self.co_stick, 180) self.co_povButtonRight = POVButton(self.co_stick, 90) self.co_povButtonLeft = POVButton(self.co_stick, 270) self.co_axisButtonLT = AxisButton(self.co_stick, 2) self.co_axisButtonRT = AxisButton(self.co_stick, 3) # co-pilot joystick to commands self.co_axisButtonRT.whenPressed(Intake(robot, power=0, button=self.co_axisButtonRT)) self.co_axisButtonLT.whenPressed(Intake(robot, power=0, button=self.co_axisButtonLT)) self.co_buttonRB.whenPressed(ActuateGate(robot, direction="open")) self.co_buttonLB.whenPressed(ActuateGate(robot, direction="close")) self.co_buttonA.whenPressed(PanelSpinner(robot, button=self.co_buttonA, power=0)) self.co_povButtonUp.whenPressed(DpadDrive(robot, "up", self.co_povButtonUp)) self.co_povButtonDown.whenPressed(DpadDrive(robot, "down", self.co_povButtonDown)) self.co_povButtonRight.whenPressed(DpadDrive(robot, "right", self.co_povButtonRight)) self.co_povButtonLeft.whenPressed(DpadDrive(robot, "left", self.co_povButtonLeft)) def getJoystick(self): return self.stick