def move_motors(): if joystick. loader.run(100) sys.wait_for(lambda: not testb.is_on()) loader.off() def drop_ball(): tube_servo.position(50) sys.sleep(0.1) tube_servo.position(15) def theta_move(): if joystick.axis3() > 5: motor_left.run((joystick.axis3())) motor_right.run((joystick.axis3())) sys.wait_for(lambda: joystick.axis3() < 5) motor_right.off() motor_left.off() elif joystick.axis3() < -5: motor_left.run(-((joystick.axis3()))) motor_right.run(-((joystick.axis3()))) sys.wait_for(lambda: joystick.axis3() > -5) motor_right.off() motor_left.off() def forward(): motor_left.run(100) motor_right.run(100) sys.wait_for(lambda: not testb.is_on()) motor_right.off() motor_left.off() def turn_right(): motor_left.run(100) motor_right.run(-(100)) sys.wait_for(lambda: not testb.is_on()) motor_right.off() motor_left.off() def turn_left(): motor_left.run(-(100)) motor_right.run(100) sys.wait_for(lambda: not testb.is_on()) motor_right.off() motor_left.off() def backward(): motor_left.run(-(100)) motor_right.run(-(100)) sys.wait_for(lambda: not testb.is_on()) motor_right.off() motor_left.off() # main thread while True: theta_move()
def theta_move(): if joystick.axis3() > 5: motor_left.run((joystick.axis3())) motor_right.run((joystick.axis3())) sys.wait_for(lambda: joystick.axis3() < 5) motor_right.off() motor_left.off() elif joystick.axis3() < -5: motor_left.run(-((joystick.axis3()))) motor_right.run(-((joystick.axis3()))) sys.wait_for(lambda: joystick.axis3() > -5) motor_right.off() motor_left.off()
# VEX V5 Python Project import sys import vex from vex import * #region config brain = vex.Brain() motor_right = vex.Motor(vex.Ports.PORT15, vex.GearSetting.RATIO18_1, False) motor_left = vex.Motor(vex.Ports.PORT16, vex.GearSetting.RATIO18_1, False) bumper_a = vex.Bumper(brain.three_wire_port.a) #endregion config # Carefully now... dt.set_velocity(20, vex.VelocityUnits.PCT) while True: # Creep back... dt.drive(vex.DirectionType.REV) sys.wait_for(bumper_a.pressing) # Ran into something, move away from it dt.drive(vex.DirectionType.FWD) sys.sleep(2) # Turn a bit to avoid it... dt.turn_for(vex.TurnType.LEFT, 77, vex.RotationUnits.DEG) # Ready to try again!
import vex import sys #region config bump_ = vex.DigitalInput(5) limit = vex.DigitalInput(8) right_sensor = vex.LineTracker(1) left_sensor = vex.LineTracker(2) right_motor = vex.Motor(2) left_motor = vex.Motor(3) #endregion config # main thread sys.wait_for(bump_.is_on) right_motor.run(20) left_motor.run(20) while True: if right_sensor.line_tracker_percent() > 70: right_motor.off() elif left_sensor.percent() > 70: left_motor.off() elif limit.is_on(): break else: right_motor.run(20) left_motor.run(20) while True: if bump_.is_on(): break else: right_motor.off()
def backward(): motor_left.run(-(100)) motor_right.run(-(100)) sys.wait_for(lambda: not testb.is_on()) motor_right.off() motor_left.off()
def turn_left(): motor_left.run(-(100)) motor_right.run(100) sys.wait_for(lambda: not testb.is_on()) motor_right.off() motor_left.off()
def thread2(): global item sys.wait_for(lambda: item == 1) motor_11.run_until_time(100, 1.12, True) sys.wait_for(lambda: item == 0) motor_11.run_until_time(-(100), 0.25, True)