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())
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)
class OI(object): def __init__(self): # Create Joysticks self.stick = Joystick(0) self.gamepad = Joystick(1) # Create Buttons self.trigger = JoystickButton(self.stick, 1) self.button2 = JoystickButton(self.stick, 2) self.button3 = JoystickButton(self.stick, 3) self.button4 = JoystickButton(self.stick, 4) self.button5 = JoystickButton(self.stick, 5) self.button6 = JoystickButton(self.stick, 6) self.button7 = JoystickButton(self.stick, 7) self.button8 = JoystickButton(self.stick, 8) self.button9 = JoystickButton(self.stick, 9) self.button10 = JoystickButton(self.stick, 10) self.button11 = JoystickButton(self.stick, 11) self.pad1 = JoystickButton(self.gamepad, 1) self.pad2 = JoystickButton(self.gamepad, 2) self.pad3 = JoystickButton(self.gamepad, 3) self.pad4 = JoystickButton(self.gamepad, 4) self.pad5 = JoystickButton(self.gamepad, 5) self.pad6 = JoystickButton(self.gamepad, 6) self.pad7 = JoystickButton(self.gamepad, 7) self.pad8 = JoystickButton(self.gamepad, 8) self.pad9 = JoystickButton(self.gamepad, 9) self.climb2 = ComboButton(self.pad6, self.button6) self.climb3 = ComboButton(self.pad5, self.button6) # Test buttons self.test = ComboButton(self.pad2, self.button6) # Command hookups self.trigger.whenPressed(Intake()) self.trigger.whenReleased(NeutralIntake()) # self.button2.whileHeld(Align(3.0)) self.button8.whenPressed( type( '', (InstantCommand, ), { 'initialize': lambda: Command.getRobot().liftElevator.resetEncoders() })) self.pad1.whenPressed(SetObjectMode( IntakeOutput.BallOrHatchMode.HATCH)) self.pad1.whenReleased(SetObjectMode( IntakeOutput.BallOrHatchMode.BALL)) Command.getRobot().intakeOutput.mode = IntakeOutput.BallOrHatchMode.HATCH if \ self.pad1.get() else IntakeOutput.BallOrHatchMode.HATCH self.test.whenPressed(TopConditional()) self.pad3.whenPressed(MiddleConditional()) self.pad4.whenPressed(LowConditional()) self.climb2.whenPressed(TwoClimbG()) self.climb3.whenPressed(OneClimbG()) self.pad7.whenPressed(MoveElevator(1)) self.pad8.whenPressed(HighCenter()) @property def driveStick(self): return self.stick @property def gamePad(self): return self.gamePad