Skip to content

Instantly share code, notes, and snippets.

@astronautlevel2
Created October 11, 2017 23:53
Show Gist options
  • Save astronautlevel2/4eac92411837ca82101f52c3ec892fdf to your computer and use it in GitHub Desktop.
Save astronautlevel2/4eac92411837ca82101f52c3ec892fdf to your computer and use it in GitHub Desktop.
Sample robot.py code
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