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!
  1. import wpilib
  2. import wpilib.buttons
  3.  
  4. class MyRobot(wpilib.IterativeRobot):
  5.    
  6.    
  7.     ##############SET UP FOR XBOX CONTROLLER###################
  8.    
  9.    
  10.     def robotInit(self):
  11.         """
  12.            This function is called upon program startup and
  13.            should be used for any initialization code.
  14.            """
  15.         self.motor1=wpilib.Jaguar(0)
  16.         self.motor2=wpilib.Jaguar(1)
  17.         self.slide_motor=wpilib.Jaguar(2)
  18.         self.non_existant_motor=wpilib.Jaguar(4)
  19.         self.sol=wpilib.Solenoid(0,4)
  20.         self.compress=wpilib.Compressor()
  21.         self.robot_drive = wpilib.RobotDrive(self.motor2,self.motor1)
  22.         self.stick1 = wpilib.Joystick(0)
  23.         self.joystick_button=wpilib.buttons.JoystickButton(self.stick1, 1)
  24.         #I run into a problem with the DigitalInput on the pyfrc sim but that might just be the sim#
  25.         self.clicky1=wpilib.DigitalInput(9)
  26.         self.ground=wpilib.DigitalOutput(0)
  27.         self.red=wpilib.DigitalOutput(1)
  28.         self.green=wpilib.DigitalOutput(2)
  29.         self.blue=wpilib.DigitalOutput(3)
  30.         wpilib.SmartDashboard.putNumber("Clicky1",self.clicky1.get())
  31.         self.chooser=wpilib.SendableChooser()
  32.         self.chooser.addObject("Auto 1","1")
  33.         wpilib.SmartDashboard.putData('What Automous', self.chooser)
  34.    
  35.    
  36.     def autonomousInit(self):
  37.         """This function is run once each time the robot enters autonomous mode."""
  38.         self.auto_loop_counter = 0
  39.     #self.user_choice=self.chooser.getSelected()
  40.    
  41.     def autonomousPeriodic(self):
  42.         """This function is called periodically during autonomous."""
  43.         # Check if we've completed 100 loops (approximately 2 seconds)
  44.         if self.auto_loop_counter < 100:
  45.             self.robot_drive.drive(-0.5, 0) # Drive forwards at half speed
  46.             self.auto_loop_counter += 1
  47.         else:
  48.             self.robot_drive.drive(0, 0)    #Stop robot
  49.    
  50.    
  51.    
  52.     def teleopPeriodic(self):
  53.         """This function is called periodically dturing operator control."""
  54.         #Smart Dashboad things
  55.         #wpilib.SmartDashboard.putNumber("Clicky1",self.clicky1.get())
  56.        
  57.         self.compress.setClosedLoopControl(True)
  58.        
  59.         #Getting the right stick of the xbox controller#
  60.         self.right_stickX=self.stick1.getRawAxis(4)
  61.        
  62.         #Getting the triggers#
  63.         self.right_trig=self.stick1.getRawAxis(3)
  64.         self.left_trig=-1*self.stick1.getRawAxis(2)
  65.  
  66.         if self.joystick_button.get()==True: #If "a" is pressed, fire the piston on port 4#
  67.             self.sol.set(True)
  68.         else:
  69.             self.sol.set(False)
  70.  
  71.         total=.4*(self.right_trig+self.left_trig)
  72.  
  73.         if self.right_stickX<.1 and self.right_stickX >-.1:
  74.             new_right=0
  75.         else:
  76.             new_right=self.right_stickX
  77.        
  78.         #Running all the motors#
  79.         self.non_existant_motor.set(total)
  80.         self.slide_motor.set(new_right)
  81.         self.robot_drive.arcadeDrive(self.stick1.getY(),self.stick1.getX(),True)
  82.  
  83. if __name__ == "__main__":
  84.     wpilib.run(MyRobot)
RAW Paste Data
Top