from vex import *
import urandom
import math
# Brain should be defined by default
brain=Brain()
# Robot configuration code
brain_inertial = Inertial()
LeftDiff = Motor(Ports.PORT4, False)
RightDiff = Motor(Ports.PORT10, False)
controller = Controller()
Pneumatic3 = Pneumatic(Ports.PORT12)
left_motor_a = Motor(Ports.PORT1, 1.0, False)
left_motor_b = Motor(Ports.PORT3, 1.0, False)
left_drive_smart = MotorGroup(left_motor_a, left_motor_b)
right_motor_a = Motor(Ports.PORT7, 1.0, True)
right_motor_b = Motor(Ports.PORT9, 1.0, True)
right_drive_smart = MotorGroup(right_motor_a, right_motor_b)
drivetrain = DriveTrain(left_drive_smart, right_drive_smart, 200, 173, 76, MM, 1)
bumper_2 = Bumper(Ports.PORT2)
touchled_8 = Touchled(Ports.PORT8)
# generating and setting random seed
def initializeRandomSeed():
wait(100, MSEC)
xaxis = brain_inertial.acceleration(XAXIS) * 1000
yaxis = brain_inertial.acceleration(YAXIS) * 1000
zaxis = brain_inertial.acceleration(ZAXIS) * 1000
systemTime = brain.timer.system() * 100
urandom.seed(int(xaxis + yaxis + zaxis + systemTime))
# Initialize random seed
initializeRandomSeed()
#endregion VEXcode Generated Robot Configuration
screen_precision = 0
console_precision = 0
myVariable = 0
my_event = Event()
claw = False
console_thingy = False
Fl4 = False
l3l4 = False
def Wind_up():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
LeftDiff.spin(REVERSE)
RightDiff.spin(REVERSE)
while not bumper_2.pressing():
wait(20, MSEC)
LeftDiff.stop()
RightDiff.stop()
def shoot():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
LeftDiff.set_velocity(100, PERCENT)
RightDiff.set_velocity(100, PERCENT)
LeftDiff.spin_for(FORWARD, 50, DEGREES, wait=False)
RightDiff.spin_for(FORWARD, 50, DEGREES)
wait(0.2, SECONDS)
Wind_up()
def controllerbuttonLUp_pressed_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
Wind_up()
def controllerbuttonRDown_pressed_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
shoot()
def controllerbuttonRUp_pressed_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
if l3l4:
touchled_8.set_color(Color.RED)
Pneumatic3.retract(CYLINDER2)
l3l4 = False
else:
touchled_8.set_color(Color.BLUE)
Pneumatic3.extend(CYLINDER2)
l3l4 = True
def when_started1():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
claw = True
console_precision = 6
drivetrain.set_stopping(HOLD)
left_drive_smart.set_max_torque(100,PERCENT)
right_drive_smart.set_max_torque(100,PERCENT)
def dol4forsomereason():
global Fl4
touchled_8.set_color(Color.BLUE)
Pneumatic3.extend(CYLINDER2)
l3l4 = True
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.set_turn_velocity(50, PERCENT)
drivetrain.drive_for(REVERSE, 90, MM)
drivetrain.turn_for(LEFT, 17, DEGREES)
drivetrain.set_timeout(0.6, SECONDS)
drivetrain.drive_for(REVERSE, 100, MM)
wait(0.1, SECONDS)
my_event.broadcast()
Fl4 = True
def when_started2():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
print("\033[2J")
Fl4 = False
l3l4 = True
LeftDiff.set_max_torque(100, PERCENT)
RightDiff.set_max_torque(100, PERCENT)
LeftDiff.set_velocity(100, PERCENT)
RightDiff.set_velocity(100, PERCENT)
Wind_up()
def controllerbuttonEUp_pressed_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
brain.program_stop()
def controllerbuttonFDown_pressed_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
Pneumatic3.retract(CYLINDER1)
claw = True
LeftDiff.set_timeout(2, SECONDS)
RightDiff.set_timeout(2, SECONDS)
RightDiff.spin_for(FORWARD, 235, DEGREES, wait=False)
LeftDiff.spin_for(REVERSE, 235, DEGREES)
Pneumatic3.extend(CYLINDER1)
wait(0.05, SECONDS)
claw = False
LeftDiff.set_timeout(0, SECONDS)
RightDiff.set_timeout(0, SECONDS)
LeftDiff.set_velocity(50, PERCENT)
RightDiff.set_velocity(50, PERCENT)
RightDiff.spin_for(REVERSE, 235, DEGREES, wait=False)
LeftDiff.spin_for(FORWARD, 235, DEGREES)
LeftDiff.set_velocity(100, PERCENT)
RightDiff.set_velocity(100, PERCENT)
def controllerbuttonFUp_pressed_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
if claw:
Pneumatic3.extend(CYLINDER1)
claw = False
else:
Pneumatic3.retract(CYLINDER1)
claw = True
def controllerbuttonLUp_pressed_callback_1():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
Fl4 = True
def when_started3():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
while True:
if Fl4:
drivetrain.drive(FORWARD)
left_drive_smart.set_velocity((controller.axisA.position()*0.9 + controller.axisC.position() * 0.27), PERCENT)
right_drive_smart.set_velocity((controller.axisA.position()*0.9 - controller.axisC.position() * 0.27), PERCENT)
wait(20, MSEC)
def controllerbuttonEDown_pressed_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
if not Fl4:
dol4forsomereason()
def my_event_callback_0():
global myVariable, my_event, claw, console_thingy, Fl4, l3l4, screen_precision, console_precision
shoot()
# system event handlers
controller.buttonLUp.pressed(controllerbuttonLUp_pressed_callback_0)
controller.buttonLUp.pressed(controllerbuttonLUp_pressed_callback_1)
controller.buttonRDown.pressed(controllerbuttonRDown_pressed_callback_0)
controller.buttonRUp.pressed(controllerbuttonRUp_pressed_callback_0)
controller.buttonEUp.pressed(controllerbuttonEUp_pressed_callback_0)
controller.buttonFDown.pressed(controllerbuttonFDown_pressed_callback_0)
controller.buttonFUp.pressed(controllerbuttonFUp_pressed_callback_0)
controller.buttonEDown.pressed(controllerbuttonEDown_pressed_callback_0)
my_event(my_event_callback_0)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)
ws2 = Thread( when_started2 )
ws3 = Thread( when_started3 )
when_started1()