Created
October 11, 2017 23:53
-
-
Save astronautlevel2/4eac92411837ca82101f52c3ec892fdf to your computer and use it in GitHub Desktop.
Sample robot.py code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wpilib | |
class MyRobot(wpilib.IterativeRobot): | |
"""Main robot class which represents the physical robot. Contains methods that describe how the robot works""" | |
def robotInit(self): | |
"""robotInit method which determines what the robot does when it first turns on""" | |
self.leftJoystick = wpilib.Joystick(0) # Assign the joystick on port 0 to leftJoystick | |
self.rightJoystick = wpilib.Joystick(1) # Assign the joystick on port 1 to rightJoystick | |
self.leftMotor = wpilib.Talon(0) # Assign the motor on port 0 to leftMotor | |
self.rightMotor = wpilib.Talon(1) # Assign the motor on port 1 to rightMotor | |
def teleopPeriodic(self): | |
"""teleopPeriodic which loops forever while the robot is enabled""" | |
self.leftMotor.set(-self.leftJoystick.getRawAxis(1) * 0.4) # Assign the value on the left joystick to the motor | |
self.rightMotor.set(self.rightJoystick.getRawAxis(1) * 0.4) # Assign the value on the right joystick to motor | |
if __name__ == "__main__": # Assuming is being run as a file rather than a package, run the MyRobot class | |
wpilib.run(MyRobot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment