After downloading this code:
#region VEXcode Generated Robot Configuration
from vex import *
import urandom
# Brain should be defined by default
brain=Brain()
# Robot configuration code
brain_inertial = Inertial()
left_drive_smart = Motor(Ports.PORT6, 10.4, True)
right_drive_smart = Motor(Ports.PORT7, 10.4, False)
drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)
Lifter = Motor(Ports.PORT4, False)
H_Wheel = Motor(Ports.PORT5, False)
Combine = Motor(Ports.PORT10, False)
# Make random actually random
def setRandomSeedUsingAccel():
wait(100, MSEC)
xaxis = brain_inertial.acceleration(XAXIS) * 1000
yaxis = brain_inertial.acceleration(YAXIS) * 1000
zaxis = brain_inertial.acceleration(ZAXIS) * 1000
urandom.seed(int(xaxis + yaxis + zaxis))
# Set random seed
setRandomSeedUsingAccel()
vexcode_initial_drivetrain_calibration_completed = False
def calibrate_drivetrain():
# Calibrate the Drivetrain Inertial
global vexcode_initial_drivetrain_calibration_completed
sleep(200, MSEC)
brain.screen.print("Calibrating")
brain.screen.next_row()
brain.screen.print("Inertial")
brain_inertial.calibrate()
while brain_inertial.is_calibrating():
sleep(25, MSEC)
vexcode_initial_drivetrain_calibration_completed = True
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
#endregion VEXcode Generated Robot Configuration
global distTraveled
def posPID(setPoint):
wTime = 15
distTraveled = 0
prevError = 0
integral = 0
arrive = False
while arrive == False: #some condition
error = setPoint - distTraveled
integral = integral + error
if error == 0:
integral = 0
if error < 0:
integral = 0
derivative = error - prevError
prevError = error
kP = 1
kI = 1
kD = 1 # to be set later
power = error*kP + integral*kI + derivative*kD
drivetrain.stop()
drivetrain.set_drive_velocity(power, PERCENT)
drivetrain.drive(FORWARD)
distTraveled = drivetrain.velocity(RPM) * 200 * wTime
wait(wTime)
if error == setPoint:
arrive = True
pass
pass
distTraveled = 0
posPID(100)
and running it, I get this error on the robot brain.
Traceback (most recent call last)
File "userpy", line 83. in <module>
File "userpy", line 69. in posPID
NameError: local variable referenced b
First, how do I see the rest of the error (after the b)
Second, does anybody know what this means?
I haven’t used python in a while so it might just be wrong syntax