From f65f083347db161b7d55d326679186d3821f82e1 Mon Sep 17 00:00:00 2001 From: Elis Axelsson Date: Sat, 26 Aug 2017 18:40:42 +0200 Subject: [PATCH] Reverse some calculations to measure distance to the ceiling instead of the floor --- code/table.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/code/table.py b/code/table.py index 09281aa..dfef0a9 100644 --- a/code/table.py +++ b/code/table.py @@ -68,21 +68,23 @@ class Table: - Zero distances is stop """ - # Calculate target height - targetHeight = self.currentHeight() + distance + # Calculate target height (Assuming we're measuring the distance + # to the ceiling) + targetHeight = self.currentHeight() - distance # Default to not move in any direction direction = 0 while True: # Calculate how far to move - currentHeightDiff = targetHeight - self.currentHeight() + currentHeightDiff = (self.currentHeight() - targetHeight) * -1 - # Calculate which direction to move in + # Calculate which direction to move in (Assuming that we're + # measuring the diff height to the ceiling) if currentHeightDiff > 1: - direction = 1 - elif currentHeightDiff < -1: direction = -1 + elif currentHeightDiff < -1: + direction = 1 else: # Reset the relays self.triggerRelay(0)