From 2700a2c30034179fb3887502cdc8cad698fe31a5 Mon Sep 17 00:00:00 2001 From: bartbutenaers Date: Mon, 8 May 2017 09:57:29 +0200 Subject: [PATCH] Pisrf performance fix (#309) * performance fix * performance fix --- hardware/PiSrf/nrsrf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hardware/PiSrf/nrsrf.py b/hardware/PiSrf/nrsrf.py index 7cffa5c0..945c497f 100755 --- a/hardware/PiSrf/nrsrf.py +++ b/hardware/PiSrf/nrsrf.py @@ -33,6 +33,12 @@ def Measure(): Main() while GPIO.input(ECHO)==1: stop = time.time() + Dif = time.time() - realstart + if Dif > 5: + print("Ultrasonic Sensor Timed out, Restarting.") + time.sleep(0.4) + Main() + elapsed = stop-start distance = (elapsed * 36000)/2 @@ -65,7 +71,7 @@ if len(sys.argv) > 1: distance = int( Measure() + 0.5 ) if distance != OLD: print(distance) - OLD = distance + OLD = distance time.sleep(0.5) except: # try to clean up on exit print("0.0");