SHARE
TWEET

Python Problems

a guest Jan 21st, 2015 19 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from __future__ import division #Needed for the math#
  2. import wpilib #Library for robot#
  3. import wpilib.buttons
  4. #####NOTE: Might not need future divison on Python 3.4#######
  5.  
  6. #####NOTE: This is kinda set up for Omni with the slide motor but more ajustments might be needed!##########
  7. class MyRobot(wpilib.IterativeRobot):
  8.  
  9.     def robotInit(self):
  10.         #Set up for pins 8 and 9 on RIO#
  11.         self.motor1=wpilib.Jaguar(8)
  12.         self.motor2=wpilib.Jaguar(9)
  13.         self.slide_motor=wpilib.Jaguar(7)
  14.        
  15.         #Sets up motor1 and motor2 to drive#
  16.         self.robot_drive=wpilib.RobotDrive(self.motor1,self.motor2)
  17.        
  18.         #Using joystick 0(Works best with xbox controller)#
  19.         #Note that this joystick number may need to change#
  20.         self.stick=wpilib.Joystick(0)
  21.         self.right_stickX=self.stick.getAxis(4)
  22.         self.xbox_a=wpilib.buttons.JoystickButton(self.stick, 4)#Might need to change button number#
  23.         #If you want Y...it is here.... self.right_stickY=self.stick.getAxis(5)
  24.         #Calls function for human controlled robot#
  25.  
  26.         #Compressor and Solenoid#
  27.  
  28.         #It is set up on 0 channel CAN ID and the 4th channel#
  29.         self.solenoid=wpilib.Solenoid(0,4)
  30.         self.compressor=wpilib.Compressor()
  31.        
  32.         self.teleopPeriodic()
  33.  
  34.        
  35.     def teleopPeriodic(self):
  36.        
  37.         #while self.isOperatorControl() and self.isEnabled(): #https://github.com/robotpy/robotpy-wpilib/blob/master/examples/sample/robot.py
  38.         self.compressor.setClosedLoopControl(True)
  39.         if self.xbox_a.get()==True:
  40.             self.solenoid.set(True)
  41.        
  42.         #Get the x and y axis from controller#
  43.         controller=self.stick.getY()
  44.         x=self.stick.getX()
  45.        
  46.         #Controller is the y#
  47.         #Depending on value, it will determine the curve#
  48.  
  49. ##########################################NOT DONE, DON'T RUN####################################################################################
  50.         ###################NEED TO FIGURE OUT THE RADIUS OF XBOX JOYSTICK######################################
  51.        
  52.         controller=(controller/255)*100
  53.         x=(x/255)*100
  54.        
  55.         if controller <=50:
  56.             output=controller*(2/5)
  57.         elif controller >50 and controller <=70:
  58.             output=controller*(32/70)
  59.         elif controller >70 and controller<=85:
  60.             output=controller*(65/85)
  61.         elif controller >85 and controller<=90:
  62.             output=controller*(75/90)
  63.         elif controller >90 and controller<=95:
  64.             output=controller*(90/95)
  65.         elif controller >95 and controller<=100:
  66.             output=controller
  67.         else:
  68.             pass
  69.        
  70.         #x1 is the output of x#
  71.        
  72.         if x <=50:
  73.             x1=x*(2/5)
  74.         elif x >50 and x <=70:
  75.             x1=x*(32/70)
  76.         elif x >70 and x<=85:
  77.             x1=x*(65/85)
  78.         elif x >85 and x<=90:
  79.             x1=x*(75/90)
  80.         elif x >90 and x<=95:
  81.             x1=x*(90/95)
  82.         elif x >95 and x<=100:
  83.             x1=x
  84.         else:
  85.             pass
  86.        
  87.        
  88.         #drives the robot#
  89.         # Might need this line later... self.robot_drive.aracadeDrive(output,x1)
  90.         #self.robot_drive.aracadeDrive(output,x1)
  91.         #For slide motor#
  92.         #self.slide_motor.set(self.right_stickX.getX())
  93.  
  94.  
  95. #Runs the code#
  96. if __name__=="__main__":
  97.     wpilib.run(MyRobot)
RAW Paste Data
Top