How to use the wpilib.LiveWindow.addSensor function in wpilib

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 robotpy / robotpy-wpilib / examples / examples / pacgoat / subsystems / drivetrain.py View on Github external
self.leftEncoder = wpilib.Encoder(3, 4,
                                          reverseDirection=False,
                                          encodingType=wpilib.Encoder.EncodingType.k4X)
        self.rightEncoder.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)
        self.leftEncoder.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)

        if robot.isReal():
            # Converts to feet
            self.rightEncoder.setDistancePerPulse(0.0785398)
            self.leftEncoder.setDistancePerPulse(0.0785398)
        else:
            # Convert to feet 4in diameter wheels with 360 tick simulated encoders.
            self.rightEncoder.setDistancePerPulse((4*math.pi)/(360*12))
            self.leftEncoder.setDistancePerPulse((4*math.pi)/(360*12))

        wpilib.LiveWindow.addSensor("DriveTrain", "Right Encoder", self.rightEncoder)
        wpilib.LiveWindow.addSensor("DriveTrain", "Left Encoder", self.leftEncoder)

        # Configure gyro
        # -> the original pacgoat example is at channel 2, but that was before WPILib
        #    moved to zero-based indexing. You need to change the gyro channel in
        #    /usr/share/frcsim/models/PacGoat/robots/PacGoat.SDF, from 2 to 0. 
        self.gyro = wpilib.AnalogGyro(0)
        if robot.isReal():
            # TODO: Handle more gracefully
            self.gyro.setSensitivity(0.007)

        wpilib.LiveWindow.addSensor("DriveTrain", "Gyro", self.gyro)

        super().__init__()
github robotpy / robotpy-wpilib / examples / examples / pacgoat / subsystems / pivot.py View on Github external
# Motor to move the pivot
        self.motor = wpilib.Victor(5)

        # Sensors for measuring the position of the pivot.
        self.upperLimitSwitch = wpilib.DigitalInput(13)
        self.lowerLimitSwitch = wpilib.DigitalInput(12)

        # 0 degrees is vertical facing up.
        # Angle increases the more forward the pivot goes.
        self.pot = wpilib.AnalogPotentiometer(1)

        # Put everything to the LiveWindow for testing.
        wpilib.LiveWindow.addSensor("Pivot", "Upper Limit Switch", self.upperLimitSwitch)
        wpilib.LiveWindow.addSensor("Pivot", "Lower Limit Switch", self.lowerLimitSwitch)
        wpilib.LiveWindow.addSensor("Pivot", "Pot", self.pot)
        wpilib.LiveWindow.addActuator("Pivot", "Motor", self.motor)
        wpilib.LiveWindow.addActuator("Pivot", "PIDSubsystem Controller", self.getPIDController())
github robotpy / robotpy-wpilib / examples / examples / pacgoat / subsystems / collector.py View on Github external
def __init__(self, robot):
        # Configure devices
        self.rollerMotor = wpilib.Victor(6)
        self.ballDetector = wpilib.DigitalInput(10)
        self.openDetector = wpilib.DigitalInput(6)
        self.piston = wpilib.Solenoid(0, 1)
        self.robot = robot

        # Put everything to the LiveWindow for testing.
        wpilib.LiveWindow.addActuator("Collector", "Roller Motor", self.rollerMotor)
        wpilib.LiveWindow.addSensor("Collector", "Ball Detector", self.ballDetector)
        wpilib.LiveWindow.addSensor("Collector", "Claw Open Detector", self.openDetector)
        wpilib.LiveWindow.addActuator("Collector", "Piston", self.piston)

        super().__init__()
github robotpy / robotpy-wpilib / examples / examples / pacgoat / subsystems / drivetrain.py View on Github external
reverseDirection=False,
                                          encodingType=wpilib.Encoder.EncodingType.k4X)
        self.rightEncoder.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)
        self.leftEncoder.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)

        if robot.isReal():
            # Converts to feet
            self.rightEncoder.setDistancePerPulse(0.0785398)
            self.leftEncoder.setDistancePerPulse(0.0785398)
        else:
            # Convert to feet 4in diameter wheels with 360 tick simulated encoders.
            self.rightEncoder.setDistancePerPulse((4*math.pi)/(360*12))
            self.leftEncoder.setDistancePerPulse((4*math.pi)/(360*12))

        wpilib.LiveWindow.addSensor("DriveTrain", "Right Encoder", self.rightEncoder)
        wpilib.LiveWindow.addSensor("DriveTrain", "Left Encoder", self.leftEncoder)

        # Configure gyro
        # -> the original pacgoat example is at channel 2, but that was before WPILib
        #    moved to zero-based indexing. You need to change the gyro channel in
        #    /usr/share/frcsim/models/PacGoat/robots/PacGoat.SDF, from 2 to 0. 
        self.gyro = wpilib.AnalogGyro(0)
        if robot.isReal():
            # TODO: Handle more gracefully
            self.gyro.setSensitivity(0.007)

        wpilib.LiveWindow.addSensor("DriveTrain", "Gyro", self.gyro)

        super().__init__()
github robotpy / robotpy-wpilib / examples / examples / pacgoat / subsystems / pivot.py View on Github external
self.getPIDController().setPID(0.5, 0.001, 2)
            self.setAbsoluteTolerance(5)

        # Motor to move the pivot
        self.motor = wpilib.Victor(5)

        # Sensors for measuring the position of the pivot.
        self.upperLimitSwitch = wpilib.DigitalInput(13)
        self.lowerLimitSwitch = wpilib.DigitalInput(12)

        # 0 degrees is vertical facing up.
        # Angle increases the more forward the pivot goes.
        self.pot = wpilib.AnalogPotentiometer(1)

        # Put everything to the LiveWindow for testing.
        wpilib.LiveWindow.addSensor("Pivot", "Upper Limit Switch", self.upperLimitSwitch)
        wpilib.LiveWindow.addSensor("Pivot", "Lower Limit Switch", self.lowerLimitSwitch)
        wpilib.LiveWindow.addSensor("Pivot", "Pot", self.pot)
        wpilib.LiveWindow.addActuator("Pivot", "Motor", self.motor)
        wpilib.LiveWindow.addActuator("Pivot", "PIDSubsystem Controller", self.getPIDController())
github robotpy / robotpy-wpilib / examples / examples / GearsBot / subsystems / drivetrain.py View on Github external
if robot.isReal():
            self.left_encoder.setDistancePerPulse(0.042)
            self.right_encoder.setDistancePerPulse(0.042)
        else:
            # Circumference in ft = 4in/12(in/ft)*PI
            self.left_encoder.setDistancePerPulse((4.0/12.0*math.pi) / 360.0)
            self.right_encoder.setDistancePerPulse((4.0/12.0*math.pi) / 360.0)

        self.rangefinder = wpilib.AnalogInput(6)
        self.gyro = wpilib.AnalogGyro(1)

        wpilib.LiveWindow.addActuator("Drive Train", "Front_Left Motor", self.front_left_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Back Left Motor", self.back_left_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Front Right Motor", self.front_right_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Back Right Motor", self.back_right_motor)
        wpilib.LiveWindow.addSensor("Drive Train", "Left Encoder", self.left_encoder)
        wpilib.LiveWindow.addSensor("Drive Train", "Right Encoder", self.right_encoder)
        wpilib.LiveWindow.addSensor("Drive Train", "Rangefinder", self.rangefinder)
        wpilib.LiveWindow.addSensor("Drive Train", "Gyro", self.gyro)
github robotpy / robotpy-wpilib / examples / examples / pacgoat / subsystems / drivetrain.py View on Github external
self.rightEncoder.setDistancePerPulse((4*math.pi)/(360*12))
            self.leftEncoder.setDistancePerPulse((4*math.pi)/(360*12))

        wpilib.LiveWindow.addSensor("DriveTrain", "Right Encoder", self.rightEncoder)
        wpilib.LiveWindow.addSensor("DriveTrain", "Left Encoder", self.leftEncoder)

        # Configure gyro
        # -> the original pacgoat example is at channel 2, but that was before WPILib
        #    moved to zero-based indexing. You need to change the gyro channel in
        #    /usr/share/frcsim/models/PacGoat/robots/PacGoat.SDF, from 2 to 0. 
        self.gyro = wpilib.AnalogGyro(0)
        if robot.isReal():
            # TODO: Handle more gracefully
            self.gyro.setSensitivity(0.007)

        wpilib.LiveWindow.addSensor("DriveTrain", "Gyro", self.gyro)

        super().__init__()
github robotpy / robotpy-wpilib / examples / examples / GearsBot / subsystems / drivetrain.py View on Github external
else:
            # Circumference in ft = 4in/12(in/ft)*PI
            self.left_encoder.setDistancePerPulse((4.0/12.0*math.pi) / 360.0)
            self.right_encoder.setDistancePerPulse((4.0/12.0*math.pi) / 360.0)

        self.rangefinder = wpilib.AnalogInput(6)
        self.gyro = wpilib.AnalogGyro(1)

        wpilib.LiveWindow.addActuator("Drive Train", "Front_Left Motor", self.front_left_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Back Left Motor", self.back_left_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Front Right Motor", self.front_right_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Back Right Motor", self.back_right_motor)
        wpilib.LiveWindow.addSensor("Drive Train", "Left Encoder", self.left_encoder)
        wpilib.LiveWindow.addSensor("Drive Train", "Right Encoder", self.right_encoder)
        wpilib.LiveWindow.addSensor("Drive Train", "Rangefinder", self.rangefinder)
        wpilib.LiveWindow.addSensor("Drive Train", "Gyro", self.gyro)
github robotpy / robotpy-wpilib / examples / examples / pacgoat / subsystems / pivot.py View on Github external
self.setAbsoluteTolerance(5)

        # Motor to move the pivot
        self.motor = wpilib.Victor(5)

        # Sensors for measuring the position of the pivot.
        self.upperLimitSwitch = wpilib.DigitalInput(13)
        self.lowerLimitSwitch = wpilib.DigitalInput(12)

        # 0 degrees is vertical facing up.
        # Angle increases the more forward the pivot goes.
        self.pot = wpilib.AnalogPotentiometer(1)

        # Put everything to the LiveWindow for testing.
        wpilib.LiveWindow.addSensor("Pivot", "Upper Limit Switch", self.upperLimitSwitch)
        wpilib.LiveWindow.addSensor("Pivot", "Lower Limit Switch", self.lowerLimitSwitch)
        wpilib.LiveWindow.addSensor("Pivot", "Pot", self.pot)
        wpilib.LiveWindow.addActuator("Pivot", "Motor", self.motor)
        wpilib.LiveWindow.addActuator("Pivot", "PIDSubsystem Controller", self.getPIDController())