import buzzer
import line_follower
import light
import time
import sonar

xunxian = None
chaoshengbo = None


我的声音1 = buzzer.sound(500, 1, volume=100)
我的巡线1 = line_follower.LineFollower(base_speed=50, pid_p=5, pid_i=0, pid_d=0.4, pid_imax=50, in_line_diff_thr=600, in_line_sum_thr=3000, L_crossing_thr=1500, T_crossing_thr=5000, pass_crossing_time=300, pass_T_crossing_thr=70)
xunxian = 1
while xunxian == 1:
    我的巡线1.follow()
    if light.get_optical_sensor(1) < 1000 and light.get_optical_sensor(6) < 1000:
        xunxian = 0
我的巡线1.stop(270)
line_follower.turn_in_crossing('left', 1, turn_sensor_thr=1400)
time.sleep(1)
for count in range(3):
    chaoshengbo = sonar.get_distance()
    time.sleep(0.1)
if chaoshengbo < 200:
    for count2 in range(3):
        我的声音1.play()
        time.sleep(0.2)
else:
    line_follower.turn_in_crossing('right', 1, turn_sensor_thr=1400)
    time.sleep(1)
    for count3 in range(3):
        chaoshengbo = sonar.get_distance()
        time.sleep(0.1)
    if chaoshengbo < 200:
        for count4 in range(3):
            我的声音1.play()
            time.sleep(0.2)
