Ejemplo n.º 1
0
	l2.backward()
	s1pressed = False
	s2pressed = False
	while not (s1pressed and s2pressed):
		if (s1.isPressed()):
			s1pressed = True
			l1.stop()
		if (s2.isPressed()):
			s2pressed = True
			l2.stop()
	motor_forward(l1, desync_offset) # add desired desync

sync_legs(motor1, motor2, ts1, ts2, 400) # 400 desync makes it non-butterfly
while True:
	if (us.getDistance() < 40):
		motor1.stop()
		motor2.stop()
		Tools.delay(1500)
		move_forward(motor1, motor2, 3000) # due to motor setup, forward is actually backward
		sync_legs(motor1, motor2, ts1, ts2, 0) # make it stand up
		snap_jaw(jaw, 3)
		if (randint(0,1) == 0):
			turn(motor1, motor2, 4000)
			sync_legs(motor1, motor2, ts1, ts2, 0)
			Tools.delay(1500)
			sync_legs(motor1, motor2, ts1, ts2, 400) # make it non butterfly
		else:
			turn(motor2, motor1, 4000)
			sync_legs(motor1, motor2, ts1, ts2, 0)
			Tools.delay(1500)
			sync_legs(motor1, motor2, ts1, ts2, 400) # make it non butterfly
Ejemplo n.º 2
0
gunmotor = Motor(MotorPort.A)
motor1 = Motor(MotorPort.B)
motor2 = Motor(MotorPort.C)
us = UltrasonicSensor(SensorPort.S4)
robot.addPart(gunmotor)
robot.addPart(motor1)
robot.addPart(motor2)
robot.addPart(us)

def start_turn(m1, m2):
    m1.stop()
    m2.stop()
    m1.backward()
    m2.forward()

def stop(m1, m2, t):
    m1.stop()
    m2.stop()
    Tools.delay(t)

start_turn(motor1, motor2)
while true:
    if (us.getDistance() < 80):
        stop(motor1, motor2, 500)
        gunmotor.forward()
        Tools.delay(1000)
        gunmotor.stop()
        start_turn(motor1, motor2)
        Tools.delay(400) # don't shoot again for awhile
    Tools.delay(20)