SHARE
TWEET
Python RobotPy Problems
a guest
Feb 3rd, 2015
7
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import wpilib
- import wpilib.buttons
- class MyRobot(wpilib.IterativeRobot):
- ##############SET UP FOR XBOX CONTROLLER###################
- def robotInit(self):
- """
- This function is called upon program startup and
- should be used for any initialization code.
- """
- self.motor1=wpilib.Jaguar(0)
- self.motor2=wpilib.Jaguar(1)
- self.slide_motor=wpilib.Jaguar(2)
- self.non_existant_motor=wpilib.Jaguar(4)
- self.sol=wpilib.Solenoid(0,4)
- self.compress=wpilib.Compressor()
- self.robot_drive = wpilib.RobotDrive(self.motor2,self.motor1)
- self.stick1 = wpilib.Joystick(0)
- self.joystick_button=wpilib.buttons.JoystickButton(self.stick1, 1)
- #I run into a problem with the DigitalInput on the pyfrc sim but that might just be the sim#
- self.clicky1=wpilib.DigitalInput(9)
- self.ground=wpilib.DigitalOutput(0)
- self.red=wpilib.DigitalOutput(1)
- self.green=wpilib.DigitalOutput(2)
- self.blue=wpilib.DigitalOutput(3)
- wpilib.SmartDashboard.putNumber("Clicky1",self.clicky1.get())
- self.chooser=wpilib.SendableChooser()
- self.chooser.addObject("Auto 1","1")
- wpilib.SmartDashboard.putData('What Automous', self.chooser)
- def autonomousInit(self):
- """This function is run once each time the robot enters autonomous mode."""
- self.auto_loop_counter = 0
- #self.user_choice=self.chooser.getSelected()
- def autonomousPeriodic(self):
- """This function is called periodically during autonomous."""
- # Check if we've completed 100 loops (approximately 2 seconds)
- if self.auto_loop_counter < 100:
- self.robot_drive.drive(-0.5, 0) # Drive forwards at half speed
- self.auto_loop_counter += 1
- else:
- self.robot_drive.drive(0, 0) #Stop robot
- def teleopPeriodic(self):
- """This function is called periodically dturing operator control."""
- #Smart Dashboad things
- #wpilib.SmartDashboard.putNumber("Clicky1",self.clicky1.get())
- self.compress.setClosedLoopControl(True)
- #Getting the right stick of the xbox controller#
- self.right_stickX=self.stick1.getRawAxis(4)
- #Getting the triggers#
- self.right_trig=self.stick1.getRawAxis(3)
- self.left_trig=-1*self.stick1.getRawAxis(2)
- if self.joystick_button.get()==True: #If "a" is pressed, fire the piston on port 4#
- self.sol.set(True)
- else:
- self.sol.set(False)
- total=.4*(self.right_trig+self.left_trig)
- if self.right_stickX<.1 and self.right_stickX >-.1:
- new_right=0
- else:
- new_right=self.right_stickX
- #Running all the motors#
- self.non_existant_motor.set(total)
- self.slide_motor.set(new_right)
- self.robot_drive.arcadeDrive(self.stick1.getY(),self.stick1.getX(),True)
- if __name__ == "__main__":
- wpilib.run(MyRobot)
RAW Paste Data
