def runThread(trig, echo, sensor): global LOOP global sf_distance global sr_distance global sl_distance while LOOP: if sensor == 'Front': #s_time = time.clock() sf_distance = dist_avg(trig, echo, sensor) #print time.clock() - s_time elif sensor == 'Right': sr_distance = dist_avg(trig, echo, sensor) elif sensor == 'Left': s1_distance = dist_avg(trig, echo, sensor)
def c_mode(mode): mode_num = 0 while True: start = time.clock() distance = dist_avg(pin[0].trig, pin[0].echo, pin[0].sensor) print time.clock() - start if distance < detection_range and distance > 10: print "Checking" warning = cur_pos(pin[0].trig, pin[0].echo, pin[0].sensor) if warning == 1: warn_msg(pin[0].sensor) elif warning == 0: print "Object Moving Forward" for i in range(3): if GPIO.input(btn[i].pin) == 0: print "Button pressed..." mode_num = call_mode(mode, btn[i].pin, btn[i].button) break if mode_num == 10 or mode_num == 11 or mode_num == 22: break elif mode_num == 30: global send_msg_temp if mode == 1: send_msg_temp = 11 elif mode == 3: send_msg_temp = 22 break return mode_num
def c_mode(): while True: start = time.clock() distance = dist_avg(pin[0].trig, pin[0].echo, pin[0].sensor) print spid, " - ", time.clock() - start if distance < detection_range and distance > 10: print "Checking" warning = cur_pos(pin[0].trig, pin[0].echo, pin[0].sensor) if warning == 1: warn_msg(pin[0].sensor) elif warning == 0: print "Object Moving Forward" return
def c_mode(mode): mode_num = 0 count1 = 0 count2 = 0 count3 = 0 avg_dist = 0 rec_time = 0 s_time = timer() n_small = 200 n_high = 200 while True: distancex = 20 for x in range(mode): distance = dist_avg(pin[x].trig, pin[x].echo, pin[x].sensor) if pin[x].sensor == "Right": count2 += 1 if pin[x].sensor == "Front": count1 += 1 print distance avg_dist = distance if pin[x].sensor == "Left": count3 += 1 if distance <= distancex: distancex = distance i = x #count+=1 #avg_dist+=distance if (timer() - s_time) >= 60: mode_num = 10 print "Time", timer() - s_time print "Total Readings", "F: ", count1, "R: ", count2, "L: ", count3 print "Avegare Distance", avg_dist / count1 print "Lowest: ", n_small, " Highest: ", n_high break if distancex < detection_range and distancex > 10: print "Checking" warning = cur_pos(pin[i].trig, pin[i].echo, pin[i].sensor) if warning == 1: warn_msg(pin[i].sensor) elif warning == 0: print "Object Moving Forward" for i in range(4): if GPIO.input(btn[i].pin) == 0: print "Button pressed..." mode_num = call_mode(mode, btn[i].pin, btn[i].button) s_time = timer() break if mode_num == 10 or mode_num == 11 or mode_num == 22: break elif mode_num == 30: global send_msg_temp if mode == 1: send_msg_temp = 11 elif mode == 3: send_msg_temp = 22 break return mode_num