def init(): global joystick joystick = Joystick(0) crossbow_open = JoystickButton(joystick, 1) crossbow_open.whenPressed(CrossBow())
def teleopInit(self): '''Called only at the beginning of teleoperated mode''' self.drivetrain.zeroEncoders() #How the buttons for the xbox controller are mapped self.drivetrain.init_logger() b = JoystickButton(self.joystick, 7) #A b2 = JoystickButton(self.joystick, 8) #B #b.whenPressed(self.angle) b2.cancelWhenPressed(self.angle)
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): self.driver = joystick.Joystick(Constants.DRIVER_PORT, Constants.DRIVER_X_MOD, Constants.DRIVER_Y_MOD, Constants.DRIVER_Z_MOD) self.operator = joystick.Joystick(Constants.OPERATOR_PORT, Constants.OPERATOR_X_MOD, Constants.OPERATOR_Y_MOD, Constants.OPERATOR_Z_MOD) self.hatchbutton = JoystickButton(self.driver, 1) self.hatchbutton.whenPressed(togglehatchlatch.ToggleHatchLatch())
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
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())
def __init__(self, port): super().__init__(port) self.xButton = JoystickButton(self, 3) self.yButton = JoystickButton(self, 4) self.aButton = JoystickButton(self, 1) self.bButton = JoystickButton(self, 2) self.rightBumper = JoystickButton(self, 6) self.leftBumper = JoystickButton(self, 5) self.startButton = JoystickButton(self, 8) self.selectButton = JoystickButton(self, 7) self.leftStickButton = JoystickButton(self, 9) self.rightStickButton = JoystickButton(self, 10)
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()))
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
class OI(metaclass=singleton.Singleton): """Deals with anything controller related, be it gamepads, joysticks, or steering wheels.""" def __init__(self): self.driver = joystick.Joystick(Constants.DRIVER_PORT, Constants.DRIVER_X_MOD, Constants.DRIVER_Y_MOD, Constants.DRIVER_Z_MOD) self.operator = joystick.Joystick(Constants.OPERATOR_PORT, Constants.OPERATOR_X_MOD, Constants.OPERATOR_Y_MOD, Constants.OPERATOR_Z_MOD) self.hatchbutton = JoystickButton(self.driver, 1) self.hatchbutton.whenPressed(togglehatchlatch.ToggleHatchLatch())
def teleopInit(self): self.drivetrain.zeroEncoders() self.drivetrain.zeroNavx() buttonA = JoystickButton(self.joystick1, 1) buttonY = JoystickButton(self.joystick1, 4) buttonA.whenPressed(self.elevatorIntake) buttonY.whenPressed(self.elevatorScale)
def getJoystick(): joystick = Joystick(0) trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger) return joystick
def robotInit(self): #**************Camera Initialization******************** #Networktables.initialize('server=roborio.5970-frc.local') #wpilib.CameraServer.launch() #wpilib.CameraServer.launch('vision.py:main') """ This function is called upon program startup and should be used for any initialization code. """ #**************Robot-Side Initialization*************** # Inititalize the Drive motors self.left_motors = [] self.left_motors.append(wpilib.VictorSP(0)) self.left_motors.append(wpilib.VictorSP(1)) self.right_motors = [] self.right_motors.append(wpilib.VictorSP(4)) self.right_motors.append(wpilib.VictorSP(3)) # too lazy to change the formal from a list even though its only 1 thing.deal with it. # Initialize the winch Motor self.winch_motor = [] self.winch_motor.append(wpilib.VictorSP(8)) # Initialize the triger Motor self.Triger_motor = [] self.Trigger_motor.append(wpilib.VictorSP(7)) #***************Driverstation Initialization****************** #TANK DRIVE Xbox # Initialize the Joysticks that will be used self.xbox = wpilib.XboxController(1) #got the pinouts off of google need to test self.WinchUp = JoystickButton(self.xbox, 0) #A self.WinchDown = JoystickButton(self.xbox, 1) #B self.Trigger = JoystickButton(self.xbox, 3) #Y #Initialize the Joysticks that will be used--idk what this does because im doing this @11:45 before comp, so im not deleting it self.throttle = wpilib.Joystick(1) self.steering = wpilib.Joystick(2)
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())
def init(): """ Initialize operator input (OI) objects. """ global joystick, controller, start_btn, divider joystick = Joystick(robotmap.joystick.port) controller = XboxController(robotmap.joystick.port) start_btn = JoystickButton(joystick, 7) divider = 1
class OI(): backwardsButton = False backwardsToggle = False def __init__(self): self.joystick = wpilib.Joystick(robotMap.JOYSTICK) self.gamepad = wpilib.Joystick(robotMap.GAMEPAD) self.winchToggle = JoystickButton(self.joystick, robotMap.WINCHTOGGLE) from commands import teleClimb self.winchToggle.toggleWhenPressed(teleClimb.TeleClimb()) def getLeftSpeed(self): return self.gamepad.getRawAxis(robotMap.LEFTDRIVECONTROL) def getRightSpeed(self): return self.gamepad.getRawAxis(robotMap.RIGHTDRIVECONTROL) def backwardsCheck(self): if (self.backwardsButton and not self.gamepad.getRawButton(robotMap.REVERSE)): self.backwardsButton = False elif (not self.backwardsButton and self.gamepad.getRawButton(robotMap.REVERSE)) : self.backwardsButton = True self.backwardsToggle = not self.backwardsToggle def getBackwards(self): return self.backwardsToggle def getSlowDown(self): return self.gamepad.getRawButton(robotMap.SLOWDOWN) def getWinchSpeed(self): return self.joystick.getRawAxis(robotMap.WINCH) def getPOV(self): return self.gamepad.getPOV()
def init(): """ Assign commands to button actions, and publish your joysticks so you can read values from them later. """ global leftDriverStick global rightDriverStick leftDriverStick = T16000M(0) rightDriverStick = T16000M(1) global btnDriveSlow btnDriveSlow = JoystickButton(leftDriverStick, 1)
def init(): """ Assign commands to button actions, and publish your joysticks so you can read values from them later. """ global leftDriverStick global rightDriverStick global resetYawBtn global autoBtn global autoTurnBtn leftDriverStick = T16000M(0) rightDriverStick = T16000M(1) resetYawBtn = JoystickButton(rightDriverStick, 2) resetYawBtn.whenPressed(ResetYawAngle()) autoBtn = JoystickButton(leftDriverStick, 2) autoBtn.whenPressed(AutoDriveForwardToScale())
def setup_button_bindings(self): cmdcfg = configparser.ConfigParser() cmdcfg.read(self._command_config) arm_max_position = cmdcfg.getint("ArmCommands", "RAISED_BOUND") hook_max_position = cmdcfg.getint("HookCommands", "EXTENDED_BOUND") scoring_right_trigger = JoystickButton(self._controllers[UserController.SCORING], JoystickButtons.RIGHTTRIGGER) scoring_a_button = JoystickButton(self._controllers[UserController.SCORING], JoystickButtons.A) scoring_y_button = JoystickButton(self._controllers[UserController.SCORING], JoystickButtons.Y) scoring_left_trigger = JoystickButton(self._controllers[UserController.SCORING], JoystickButtons.LEFTTRIGGER) scoring_right_trigger.whenPressed(ShootBall(self.robot)) #scoring_y_button.whenPressed(RaiseArmExtendHook(self.robot, arm_max_position, hook_max_position)) #scoring_a_button.whenPressed(RetractHookToCount(self.robot, 1.0, 0)) scoring_left_trigger.whenPressed(PickUpBall(self.robot, 1.0, "PickUpBall", 5.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
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 getJoystick(): global joystick if (joystick is None): joystick = Joystick(0) trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger) return joystick
def get_joystick(): joystick = Joystick(0) thumb = JoystickButton(joystick, Joystick.ButtonType.kTop) thumb.whenPressed(SwitchMode()) trigger = JoystickButton(joystick, Joystick.ButtonType.kTrigger) trigger.whileHeld(OperateConveyor()) button_11 = JoystickButton(joystick, 11) button_11.whenPressed(AutoTargetY()) button_12 = JoystickButton(joystick, 12) button_12.whenPressed(AutoTargetX()) button_9 = JoystickButton(joystick, 9) button_9.whenPressed(AutoTargetAngle()) return joystick
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))
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")
class PyBot(CommandBasedRobot): ''' The CommandBasedRobot base class implements almost everything you need for a working robot program. All you need to do is set up the subsystems and commands. You do not need to override the "periodic" functions, as they will automatically call the scheduler. You may override the "init" functions if you want to do anything special when the mode changes. ''' 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")
def teleopInit(self): '''Called only at the beginning of teleoperated mode''' #How the buttons for the xbox controller are mapped self.drivetrain.init_logger() b = JoystickButton(self.joystick, 1) #A b2 = JoystickButton(self.joystick, 2) #B b.whenPressed(self.angle) b2.cancelWhenPressed(self.angle) b3 = JoystickButton(self.joystick, 3) #X b4 = JoystickButton(self.joystick, 4) #Y b3.whenPressed(self.DriveForward) b4.cancelWhenPressed(self.DriveForward) '''
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
class BeaverTronicsRobot(wpilib.IterativeRobot): def robotInit(self): #**************Camera Initialization******************** #Networktables.initialize('server=roborio.5970-frc.local') #wpilib.CameraServer.launch() #wpilib.CameraServer.launch('vision.py:main') """ This function is called upon program startup and should be used for any initialization code. """ #**************Robot-Side Initialization*************** # Inititalize the Drive motors self.left_motors = [] self.left_motors.append(wpilib.VictorSP(0)) self.left_motors.append(wpilib.VictorSP(1)) self.right_motors = [] self.right_motors.append(wpilib.VictorSP(4)) self.right_motors.append(wpilib.VictorSP(3)) # too lazy to change the formal from a list even though its only 1 thing.deal with it. # Initialize the winch Motor self.winch_motor = [] self.winch_motor.append(wpilib.VictorSP(8)) # Initialize the triger Motor self.Triger_motor = [] self.Trigger_motor.append(wpilib.VictorSP(7)) #***************Driverstation Initialization****************** #TANK DRIVE Xbox # Initialize the Joysticks that will be used self.xbox = wpilib.XboxController(1) #got the pinouts off of google need to test self.WinchUp = JoystickButton(self.xbox, 0) #A self.WinchDown = JoystickButton(self.xbox, 1) #B self.Trigger = JoystickButton(self.xbox, 3) #Y #Initialize the Joysticks that will be used--idk what this does because im doing this @11:45 before comp, so im not deleting it self.throttle = wpilib.Joystick(1) self.steering = wpilib.Joystick(2) def autonomousInit(self): """This function is run once each time the robot enters autonomous mode.""" self.auto_loop_counter = 0 def autonomousPeriodic(self): #old auto code could be used to cross baseline if we wire shit up correctly if self.auto_loop_counter < 10: self.setDriveMotors(1, -1) # forward auto """else: if self.auto_loop_counter < 20/2: self.DoubleSolenoid.set(1) self.auto_loop_counter += 1 else: if self.auto_loop_counter < 30/2: self.DoubleSolenoid.set(2) self.auto_loop_counter += 1 else: if self.auto_loop_counter < 50/2: self.DoubleSolenoid.set(1) self.auto_loop_counter += 1 else: if self.auto_loop_counter < 70/2: self.DoubleSolenoid.set(2) self.auto_loop_counter += 1 self.auto_loop_counter = 0""" def teleopPeriodic(self): """This function is called periodically during operator control.""" self.drivetrainMotorControl() self.Winch() self.Trigger() def testPeriodic(self): """This function is called periodically during test mode.""" def drivetrainMotorControl(self): left = self.steering.getY() right = self.throttle.getY() drive_powers = drive.tankdrive(right, left) self.leftspeeds = drive_powers[0] self.rightspeeds = drive_powers[1] # set the motors to powers self.setDriveMotors(self.leftspeeds, self.rightspeeds) def setDriveMotors(self, leftspeed, rightspeed): for motor in self.right_motors: motor.set(leftspeed * -1) for motor in self.left_motors: motor.set(rightspeed * -1) def winch(self): if self.WinchUp.get(): for motor in self.Winch_motor: motor.set(1) elif setf.WinchDown.get(): for motor in self.Winch_motor: motor.set(-1) else: for motor in self.Winch_motor: motor.set(0) def Trigger(self): if self.Trigger.get(): for motor in self.Trigger_motor: motor.set(1) else: for motor in self.Trigger_motor: motor.set(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
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())