Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.lr_motor = wpilib.CANTalon(10)
self.rf_motor = wpilib.CANTalon(15)
self.rr_motor = wpilib.CANTalon(20)
self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
self.leftArm = wpilib.CANTalon(25)
self.rightArm = wpilib.CANTalon(30)
self.leftBall = wpilib.Talon(9)
self.winchMotor = wpilib.Talon(0)
self.kickMotor = wpilib.Talon(1)
self.flashlight = wpilib.Relay(0)
self.lightTimer = wpilib.Timer()
self.turningOffState = 0
self.lastState = False
##DRIVE ENCODERS##
self.rf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontRightMotor, True)
self.lf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontLeftMotor)
##DISTANCE SENSORS##
self.back_sensor = distance_sensors.SharpIRGP2Y0A41SK0F(0)
self.ultrasonic = wpilib.AnalogInput(1)
##NavX##
self.navX = navx.AHRS.create_spi()
##SMART DASHBOARD##
def __init__(self, intake):
self.intake = intake
self.is_running = False
self.state = START_SPIN
self.timer = wpilib.Timer()
self.timer.start()
self.sd = NetworkTable.getTable('SmartDashboard')
self.positions = [
self.sd.getAutoUpdateValue('Arm/Bottom', 3600),
self.sd.getAutoUpdateValue('Arm/Middle', 2635),
self.sd.getAutoUpdateValue('Arm/Top', -20),
]
self.position_threshold = self.sd.getAutoUpdateValue('Arm/On Target Threshold', 25)
self.wanted_pid = (
self.sd.getAutoUpdateValue('Arm/P', 2),
self.sd.getAutoUpdateValue('Arm/I', 0),
self.sd.getAutoUpdateValue('Arm/D', 0)
)
self.calibrate_timer = wpilib.Timer()
def teleop():
dog = wpilib.GetWatchdog()
dog.SetEnabled(True)
dog.SetExpiration(0.25)
shiftTime = wpilib.Timer()
shiftTime.Start()
while wpilib.IsOperatorControl() and wpilib.IsEnabled():
dog.Feed()
checkRestart()
if shiftTime.Get() > 0.3:
shifter1.Set(False)
shifter2.Set(False)
# Shifter control
if rstick.GetTrigger():
shifter1.Set(True)
shifter2.Set(False)
shiftTime.Reset()
import functools
import wpilib
import inspect
import networktables
from robotpy_ext.misc.orderedclass import OrderedClass
from .magic_tunable import tunable
if wpilib.RobotBase.isSimulation():
from wpilib import Timer
getTime = Timer.getFPGATimestamp
else:
import time
getTime = time.monotonic
class IllegalCallError(Exception):
pass
class NoFirstStateError(Exception):
pass
class MultipleFirstStatesError(Exception):
def OperatorControl(self):
dog = self.GetWatchdog()
dog.SetEnabled(True)
dog.SetExpiration(0.25)
shiftTime = wpilib.Timer()
haveTime = wpilib.Timer()
shiftTime.Start()
haveTime.Start()
intakeVelocity = -0.75
while self.IsOperatorControl() and self.IsEnabled():
dog.Feed()
CheckRestart()
if not HaveBall():
haveTime.Reset()
# Reset pneumatics
if shiftTime.Get() > 0.3:
def autonomous(self):
'''Called when autonomous mode is enabled'''
timer = wpilib.Timer()
timer.start()
while self.isAutonomous() and self.isEnabled():
if timer.get() < 2.0:
self.robot_drive.arcadeDrive(-1.0, -.3)
else:
self.robot_drive.arcadeDrive(0, 0)
wpilib.Timer.delay(0.01)
def operatorControl(self):
"""Runs the motors with onnidirectional drive steering.
Implements Field-centric drive control.
Also implements "rotate to angle", where the angle
being rotated to is defined by one of four buttons.
Note that this "rotate to angle" approach can also
be used while driving to implement "straight-line
driving".
"""
tm = wpilib.Timer()
tm.start()
self.myRobot.setSafetyEnabled(True)
while self.isOperatorControl() and self.isEnabled():
if tm.hasPeriodPassed(1.0):
print("NavX Gyro", self.ahrs.getYaw(), self.ahrs.getAngle())
rotateToAngle = False
if self.stick.getRawButton(1):
self.ahrs.reset()
if self.stick.getRawButton(2):
self.turnController.setSetpoint(0.0)
rotateToAngle = True
elif self.stick.getRawButton(3):