SHARE
TWEET
Python Problems
a guest
Jan 21st, 2015
19
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- from __future__ import division #Needed for the math#
- import wpilib #Library for robot#
- import wpilib.buttons
- #####NOTE: Might not need future divison on Python 3.4#######
- #####NOTE: This is kinda set up for Omni with the slide motor but more ajustments might be needed!##########
- class MyRobot(wpilib.IterativeRobot):
- def robotInit(self):
- #Set up for pins 8 and 9 on RIO#
- self.motor1=wpilib.Jaguar(8)
- self.motor2=wpilib.Jaguar(9)
- self.slide_motor=wpilib.Jaguar(7)
- #Sets up motor1 and motor2 to drive#
- self.robot_drive=wpilib.RobotDrive(self.motor1,self.motor2)
- #Using joystick 0(Works best with xbox controller)#
- #Note that this joystick number may need to change#
- self.stick=wpilib.Joystick(0)
- self.right_stickX=self.stick.getAxis(4)
- self.xbox_a=wpilib.buttons.JoystickButton(self.stick, 4)#Might need to change button number#
- #If you want Y...it is here.... self.right_stickY=self.stick.getAxis(5)
- #Calls function for human controlled robot#
- #Compressor and Solenoid#
- #It is set up on 0 channel CAN ID and the 4th channel#
- self.solenoid=wpilib.Solenoid(0,4)
- self.compressor=wpilib.Compressor()
- self.teleopPeriodic()
- def teleopPeriodic(self):
- #while self.isOperatorControl() and self.isEnabled(): #https://github.com/robotpy/robotpy-wpilib/blob/master/examples/sample/robot.py
- self.compressor.setClosedLoopControl(True)
- if self.xbox_a.get()==True:
- self.solenoid.set(True)
- #Get the x and y axis from controller#
- controller=self.stick.getY()
- x=self.stick.getX()
- #Controller is the y#
- #Depending on value, it will determine the curve#
- ##########################################NOT DONE, DON'T RUN####################################################################################
- ###################NEED TO FIGURE OUT THE RADIUS OF XBOX JOYSTICK######################################
- controller=(controller/255)*100
- x=(x/255)*100
- if controller <=50:
- output=controller*(2/5)
- elif controller >50 and controller <=70:
- output=controller*(32/70)
- elif controller >70 and controller<=85:
- output=controller*(65/85)
- elif controller >85 and controller<=90:
- output=controller*(75/90)
- elif controller >90 and controller<=95:
- output=controller*(90/95)
- elif controller >95 and controller<=100:
- output=controller
- else:
- pass
- #x1 is the output of x#
- if x <=50:
- x1=x*(2/5)
- elif x >50 and x <=70:
- x1=x*(32/70)
- elif x >70 and x<=85:
- x1=x*(65/85)
- elif x >85 and x<=90:
- x1=x*(75/90)
- elif x >90 and x<=95:
- x1=x*(90/95)
- elif x >95 and x<=100:
- x1=x
- else:
- pass
- #drives the robot#
- # Might need this line later... self.robot_drive.aracadeDrive(output,x1)
- #self.robot_drive.aracadeDrive(output,x1)
- #For slide motor#
- #self.slide_motor.set(self.right_stickX.getX())
- #Runs the code#
- if __name__=="__main__":
- wpilib.run(MyRobot)
RAW Paste Data
