How to use wpilib - 10 common examples

To help you get started, we’ve selected a few wpilib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frc1418 / 2016-robot / electrical_test / robot.py View on Github external
def createObjects(self):
        self.driveStick = xbox_controller.XboxController(0)

        # If the robot is a simulation
        if MyRobot.isSimulation():
            # Change motors to default jaguars
            self.lf_motor = wpilib.Jaguar(1)
            self.lr_motor = wpilib.Jaguar(2)
            self.rf_motor = wpilib.Jaguar(3)
            self.rr_motor = wpilib.Jaguar(4)
        # Set up drive train
        self.drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
github frc1418 / 2016-robot / electrical_test / robot.py View on Github external
def createObjects(self):
        self.driveStick = xbox_controller.XboxController(0)

        # If the robot is a simulation
        if MyRobot.isSimulation():
            # Change motors to default jaguars
            self.lf_motor = wpilib.Jaguar(1)
            self.lr_motor = wpilib.Jaguar(2)
            self.rf_motor = wpilib.Jaguar(3)
            self.rr_motor = wpilib.Jaguar(4)
        # Set up drive train
        self.drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
github wpilibsuite / frc-characterization / elevator_characterization / robot / robot-python-talonsrx / robot.py View on Github external
def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)

        # Left front
        self.arm_motor = ctre.WPI_TalonSRX(1)
        self.arm_motor.setInverted(False)
        self.arm_motor.setSensorPhase(False)

        #
        # Configure encoder related functions -- getpos and getrate should return
        # feet and feet/s
        #

        encoder_constant = (
            (1 / self.ENCODER_PULSE_PER_REV) * self.PULLEY_DIAMETER * math.pi
        )

        self.arm_motor.configSelectedFeedbackSensor(
github wpilibsuite / frc-characterization / drive_characterization / robot / robot-python-talonsrx / robot.py View on Github external
def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)

        # Left front
        left_front_motor = ctre.WPI_TalonSRX(1)
        left_front_motor.setInverted(False)
        left_front_motor.setSensorPhase(False)
        self.left_front_motor = left_front_motor

        # Right front
        right_front_motor = ctre.WPI_TalonSRX(2)
        right_front_motor.setInverted(False)
        right_front_motor.setSensorPhase(False)
        self.right_front_motor = right_front_motor

        # Left rear -- follows front
        left_rear_motor = ctre.WPI_TalonSRX(3)
        left_rear_motor.setInverted(False)
github robotpy / robotpy-crio / samples / SimpleRobot-class / robot.py View on Github external
import wpilib

lstick = wpilib.Joystick(1)

motor = wpilib.CANJaguar(8)

def CheckRestart():
    if lstick.GetRawButton(10):
        raise RuntimeError("Restart")

class MyRobot(wpilib.SimpleRobot):
    def Disabled(self):
        while self.IsDisabled():
            CheckRestart()
            wpilib.Wait(0.01)

    def Autonomous(self):
        self.GetWatchdog().SetEnabled(False)
        while self.IsAutonomous() and self.IsEnabled():
github robotpy / robotpy-wpilib / examples / examples / TankDrive / robot.py View on Github external
def robotInit(self):
        '''Robot initialization function'''
        
        # object that handles basic drive operations
        self.myRobot = wpilib.RobotDrive(0, 1)
        self.myRobot.setExpiration(0.1)
        
        # joysticks 1 & 2 on the driver station
        self.leftStick = wpilib.Joystick(0)
        self.rightStick = wpilib.Joystick(1)
github StuyPulse / frc / robotpy / RobotPy-WPILib / samples / KitBase / robot.py View on Github external
import wpilib

lstick = wpilib.Joystick(1)
rstick = wpilib.Joystick(2)

lmotor = wpilib.CANJaguar(3)
rmotor = wpilib.CANJaguar(5)
drive = wpilib.RobotDrive(lmotor, rmotor)

def CheckRestart():
    if lstick.GetRawButton(10):
        raise RuntimeError("Restart")

class MyRobot(wpilib.SimpleRobot):
    def Disabled(self):
        while self.IsDisabled():
            CheckRestart()
            wpilib.Wait(0.01)
github wpilibsuite / frc-characterization / drive_characterization / robot / robot-python-spark / robot.py View on Github external
def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)

        left_front_motor = wpilib.Spark(1)
        left_front_motor.setInverted(False)

        right_front_motor = wpilib.Spark(2)
        right_front_motor.setInverted(False)

        left_rear_motor = wpilib.Spark(3)
        left_rear_motor.setInverted(False)

        right_rear_motor = wpilib.Spark(4)
        right_rear_motor.setInverted(False)

        #
        # Configure drivetrain movement
        #
github robotpy / robotpy-crio / samples / 294_2010 / robot.py View on Github external
def RobotInit(self):
        wpilib.Wait(0.25)
        winchControl.SetOutputRange(-1.0, 1.0)
        kickerEncoder.Start()
        leftDriveEncoder.Start()
        rightDriveEncoder.Start()
        compressor.Start()
github StuyPulse / frc / robotpy / RobotPy-WPILib / samples / KitBase / robot.py View on Github external
def Disabled(self):
        while self.IsDisabled():
            CheckRestart()
            wpilib.Wait(0.01)