Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def operatorControl(self):
'''Called when operation control mode is enabled'''
while self.isOperatorControl() and self.isEnabled():
self.robot_drive.tankDrive(self.lstick, self.rstick)
wpilib.Timer.delay(0.04)
if rotateToAngle:
self.turnController.enable()
currentRotationRate = self.rotateToAngleRate
else:
self.turnController.disable()
currentRotationRate = self.stick.getTwist()
# Use the joystick X axis for lateral movement,
# Y axis for forward movement, and the current
# calculated rotation rate (or joystick Z axis),
# depending upon whether "rotate to angle" is active.
self.myRobot.mecanumDrive_Cartesian(self.stick.getX(), self.stick.getY(),
currentRotationRate, self.ahrs.getAngle())
wpilib.Timer.delay(0.005) # wait for a motor update time
def disabled(self):
'''Called when the robot is disabled'''
while self.isDisabled():
wpilib.Timer.delay(0.01)
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):
while self.isOperatorControl() and self.isEnabled():
wpilib.Timer.delay(0.02) # wait for a motor update time
def operatorControl(self):
'''Runs the motor from a joystick.'''
while self.isOperatorControl() and self.isEnabled():
# Set the motor's output.
# This takes a number from -1 (100% speed in reverse) to
# +1 (100% speed going forward)
self.motor.set(self.stick.getY())
wpilib.Timer.delay(self.kUpdatePeriod) # wait 5ms to the next update
def read(self, first_address, count):
data = [first_address, count]
data.append(crc7(data))
retcount = self.port.write(data)
if retcount != len(data):
raise IOError("Write error (%s != %s)" % (retcount, len(data)))
Timer.delay(0.001)
data = self.port.read(True, count + 1)
if len(data) != count + 1:
raise IOError("Read error (%s != %s)" % (len(data), count+1))
crc = data[-1]
data = data[:-1]
if crc7(data) != crc:
raise IOError("CRC error")
return data
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.mecanumDrive_Cartesian(0, -1, 1, 0)
else:
self.robot_drive.mecanumDrive_Cartesian(0, 0, 0, 0)
wpilib.Timer.delay(0.01)
def disabled(self):
'''Called when the robot is disabled'''
while self.isDisabled():
wpilib.Timer.delay(0.01)