From 3e7d9bee4b7f5852b6a4b4e6a6afb93a24606dae Mon Sep 17 00:00:00 2001 From: Elis Axelsson Date: Sat, 26 Aug 2017 19:07:20 +0200 Subject: [PATCH] Make distance measuring more accurate --- code/table.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/table.py b/code/table.py index dfef0a9..0e8d711 100644 --- a/code/table.py +++ b/code/table.py @@ -26,7 +26,15 @@ class Table: Might return False if measuring error. """ - distance = self.hcsr04.distance_cm() + + distances = [] + + # Measure a bunch of times... + for x in range(0, 20): + distances.append(self.hcsr04.distance_cm()) + + # Take the longest distance, I've not seen any that is too far + distance = max(distances) if distance > 0: return distance