def action(pred, lbl): global text_overlay if (pred < threshold): text_overlay = "__" ut.camera_light("OFF") if (pred >= threshold): percent = round(pred * 100) text_overlay = "Saw a " + lbl + ", i am " + str(percent) + "% sure" ut.speak_tts(lbl, "f") sleep(1) #text_to_speech(lbl,"f") ut.camera_light("ON")
sys.path.insert(0, '/var/www/html/earthrover') import util as ut local_path = os.path.dirname(os.path.realpath(__file__)) TRIG = 23 ECHO = 24 GPIO.setmode(GPIO.BCM) GPIO.setup(TRIG, GPIO.OUT) GPIO.setup(ECHO, GPIO.IN) GPIO.output(TRIG, False) ut.speak_tts("sensor ON", "f") print "Waiting For Sensor To Settle" time.sleep(1) #settling time prev_distance = 0 while 1: try: GPIO.output(TRIG, True) time.sleep(0.00001) GPIO.output(TRIG, False) while GPIO.input(ECHO) == 0: pulse_start = time.time()
local_path=os.path.dirname(os.path.realpath(__file__)) status = sys.argv[1] #ut.speak_tts(status,"f") if (status=="1"): #print "starting 2 python scripts" os.system("sudo python /var/www/html/earthrover/range_sensor/range_sensor.py &") time.sleep(1) #should be equal to settling time of range sensor os.system("sudo python /var/www/html/earthrover/range_sensor/monitorSensor.py &") time.sleep(0.1) os.system("sudo python /var/www/html/earthrover/range_sensor/avoid_collision.py &") if (status=="0"): ut.speak_tts("sensor off ","f") os.system("sudo pkill -f monitorSensor.py") time.sleep(0.1) os.system("sudo pkill -f range_sensor.py") time.sleep(0.1) os.system("sudo pkill -f avoid_collision.py") f1 = open(local_path+"/web/range.txt", "wb") f1.write("--") f1.close()
#Project: Earthrover #Created by: Jitesh Saini import time, os import sys sys.path.insert(0, '/var/www/html/earthrover') import util as ut local_path = os.path.dirname(os.path.realpath(__file__)) prev_distance = 0 counter = 0 ut.speak_tts("monitoring", "m") while 1: f0 = open(local_path + "/web/range.txt", "r+") distance = f0.read(15) f0.close() if (distance == prev_distance): counter = counter + 1 else: counter = 0 print(counter), distance if (counter == 3): ut.speak_tts("restarting", "m") os.system("sudo pkill -f range_sensor.py") print("stopped range_sensor.py !!!") time.sleep(0.1)
sys.path.insert(0, '/var/www/html/earthrover') import util as ut #dynamically obtain path of current file local_path = os.path.dirname(os.path.realpath(__file__)) ut.init_gpio() while 1: f1 = open(local_path + "/web/range.txt", "r+") distance = f1.read(20) f1.close() print("distance:", distance) #if due to some reason file is empty, ignore such occurance if (distance == "" or distance == "--"): print("blank file") continue if (float(distance) < 30): #to be removed from here, move to seperate python file ut.back() ut.speak_tts("obstacle detected", "f") time.sleep(1) ut.stop() time.sleep(0.2)