Hello –
I have a Gen2 brain and the following code runs all the way to the last line and then the brain freezes, with the last command running until I pull the battery. I can’t see any specific problem with it. I did some various testing, and the only thing that caused it to stop failing was to get rid of the Brain Inertial. However, we’d like to use that as it is pretty accurate. Can someone set up a Gen 2 brain and verify if they are also seeing the crash, or do I have a bad brain?
Thank you!
Corey
#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.PORT12, 1, False)
right_drive_smart = Motor(Ports.PORT6, 1, True)
drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)
Touch_Btn = Touchled(Ports.PORT8)
ArmSensor = Optical(Ports.PORT2)
ChooChoo_motor_a = Motor(Ports.PORT11, False)
ChooChoo_motor_b = Motor(Ports.PORT5, True)
ChooChoo = MotorGroup(ChooChoo_motor_a, ChooChoo_motor_b)
Sweeper_motor_a = Motor(Ports.PORT7, False)
Sweeper_motor_b = Motor(Ports.PORT1, True)
Sweeper = MotorGroup(Sweeper_motor_a, Sweeper_motor_b)
def calibrate_drivetrain():
# Calibrate the Drivetrain Inertial
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)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
#endregion VEXcode Generated Robot Configuration
# Define events
def onevent_ArmSensor_detects_object_0():
Touch_Btn.set_color(Color.GREEN)
ChooChoo.stop()
def onevent_ArmSensor_loses_object_0():
Touch_Btn.set_color(Color.YELLOW)
# Other methods
def init_gutenberg():
# Set the speed for the motor groups
ChooChoo.set_velocity(100, PERCENT)
Sweeper.set_velocity(100, PERCENT)
# Set the speed for the drivetrain
drivetrain.set_drive_velocity(100, PERCENT)
# Arm the catapult
if not ArmSensor.is_near_object():
while not ArmSensor.is_near_object():
ChooChoo.spin(FORWARD)
# # Done? Set the blinker to blink
# Thread(blinker_thread)
def blinker_thread():
state = True
while True:
wait(500, MSEC)
if state:
Touch_Btn.set_brightness(10)
else:
Touch_Btn.set_brightness(100)
state = not state
# Pretty colors
Touch_Btn.set_color(Color.RED)
Touch_Btn.set_brightness(100)
# Calibrate the Drivetrain Gyro
calibrate_drivetrain()
# system event handlers
ArmSensor.object_detected(onevent_ArmSensor_detects_object_0)
ArmSensor.object_lost(onevent_ArmSensor_loses_object_0)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)
## Runnable code here
init_gutenberg()
# bt = Thread(blinker_thread)
ChooChoo.spin(FORWARD)
wait(2, SECONDS)
# Some dummy code to drive around for testing
drivetrain.turn_for(LEFT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 6, INCHES)
Sweeper.spin_for(FORWARD, 600)
drivetrain.drive_for(REVERSE, 6, INCHES)
drivetrain.turn_for(RIGHT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 12, INCHES)
drivetrain.turn_for(LEFT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 6, INCHES)
Sweeper.spin_for(FORWARD, 600)
drivetrain.drive_for(REVERSE, 10, INCHES)
drivetrain.turn_for(RIGHT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 10, INCHES)
drivetrain.turn_for(LEFT, 90, DEGREES)
drivetrain.drive_for(REVERSE, 10, INCHES)
ChooChoo.spin(FORWARD)