Use Buttons In RobotPy?

Hello everyone,

Our team has decided to start using Python as our main language next year, instead of FRC LabVIEW. As the lead programmer, I’m trying to get ahead on learning the basics.

So far, I’ve gotten the bare essentials from the RobotPy documentation but I’m having some difficulty understanding how to link buttons to commands, such as running an intake or shooting a ball. If anyone can provide some code examples, that’d be great! I’ll provide my code below.

# Created by Ian Fettes
# Lead Programmer of 5503

import wpilib
import rev

class MyRobot(wpilib.TimedRobot):

    def robotInit(self):
        # Drivetrain
        self.leftDrive = wpilib.VictorSP(0) # PWM 0
        self.rightDrive = wpilib.VictorSP(1) # PWM 1

        # Ball Shooter
        self.topShooter = rev.CANSparkMax(1) # CAN ID 1
        self.bottomShooter = rev.CANSparkMax(4) # CAN ID 4

       # Ball Intake
        self.intake = wpilib.VictorSP(5)

        # MISC
        self.joystick = wpilib.Joystick(0) =, self.rightDrive)

    def teleopPeroidic(self):
        # Run Drivetrain at 65% * 0.65, self.joystick.getX() * 0.65) 

if __name__ == "__main__":

Two places you can find examples:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.