Advertisement
Guest User

Python RobotPy problem

a guest
Jan 19th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. import wpilib #Library for robot#
  2. from __future__ import division #Needed for the math#
  3.  
  4.  
  5. class MyRobot(wpilib.IterativeRobot):
  6.  
  7.     def robotInit(self):
  8.         #Set up for pins 8 and 9 on RIO#
  9.         self.motor1=wpilib.Jaguar(8)
  10.         self.slide_motor=wpilib.Jaguar(9)
  11.         #Sets up motor1 and motor2 to drive#
  12.         #Using joystick 1(Works best with xbox controller)#
  13.         self.stick=wpilib.Joystick(1)
  14.         #Calls function for human controlled robot#
  15.         self.teleopPeriodic()
  16.  
  17.        
  18.     def teleopPeriodic(self):
  19.        
  20.         while self.isOperatorControl() and self.isEnabled(): #https://github.com/robotpy/robotpy-wpilib/blob/master/examples/sample/robot.py
  21.  
  22.             #Get the x and y axis from controller#
  23.             controller=self.stick.getY()
  24.             x=self.stick.getX()
  25.            
  26.             #Controller is the y#
  27.             #Depending on value, it will determine the curve#
  28.  
  29.             x=(x/255)*100
  30.             controller=(controller/255)*100
  31.            
  32.             if controller <=50:
  33.                 output=controller*(2/5)
  34.             elif controller >50 and controller <=70:
  35.                 output=controller*(32/70)
  36.             elif controller >70 and controller<=85:
  37.                 output=controller*(65/85)
  38.             elif controller >85 and controller<=90:
  39.                 output=controller*(75/90)
  40.             elif controller >90 and controller<=95:
  41.                 output=controller*(90/95)
  42.             elif controller >95 and controller<=100:
  43.                 output=controller
  44.             else:
  45.                 pass
  46.            
  47.             #x1 is the output of x#
  48.            
  49.             if x <=50:
  50.                 x1=x*(2/5)
  51.             elif x >50 and x<=70:
  52.                 x1=x*(32/70)
  53.             elif x >70 and x<=85:
  54.                 x1=x*(65/85)
  55.             elif x >85 and x<=90:
  56.                 x1=x*(75/90)
  57.             elif x >90 and x<=95:
  58.                 x1=x*(90/95)
  59.             elif x >95 and x<=100:
  60.                 x1=x
  61.             else:
  62.                 pass
  63.            
  64.             #drives the robot#
  65.             # Might need this line later... self.robot_drive.aracadeDrive(output,x1)
  66.             self.slide_motor.set(x1)
  67.             self.motor.set(output)
  68.  
  69.  
  70. #Runs the code#
  71. if __name__=="__main__":
  72.     wpilib.run(MyRobot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement