Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wpilib #Library for robot#
- from __future__ import division #Needed for the math#
- class MyRobot(wpilib.IterativeRobot):
- def robotInit(self):
- #Set up for pins 8 and 9 on RIO#
- self.motor1=wpilib.Jaguar(8)
- self.slide_motor=wpilib.Jaguar(9)
- #Sets up motor1 and motor2 to drive#
- #Using joystick 1(Works best with xbox controller)#
- self.stick=wpilib.Joystick(1)
- #Calls function for human controlled robot#
- self.teleopPeriodic()
- def teleopPeriodic(self):
- while self.isOperatorControl() and self.isEnabled(): #https://github.com/robotpy/robotpy-wpilib/blob/master/examples/sample/robot.py
- #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#
- x=(x/255)*100
- controller=(controller/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.slide_motor.set(x1)
- self.motor.set(output)
- #Runs the code#
- if __name__=="__main__":
- wpilib.run(MyRobot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement