def isBayOccupied(self, door): """Checks to see if the specified `bay` is open. Parameters ---------- door : str Acceptable values are right or left, otherwise object defaults will be used. Returns ------- bool True for occupied False for empty """ config = self._getConfig() mode = self._getMode(config) us = self._ConfigSectionMap(config, "UltraSonic") if door == "right": # setup right sensor trigger = int(us['righttrigger']) echo = int(us['rightecho']) elif door == "left": # setup left sensor trigger = int(us['lefttrigger']) echo = int(us['leftecho']) usonic = USonic(trigger, echo, mode) if usonic.get_distance() < 305: return True else: return False
class TestUSonic: def setup(self): self.usonic = USonic(TRIGGER=10, ECHO=9) def teardown(self): self.usonic.cleanup() def test_get_distance(self): self.usonic.get_distance()
def park_assist(channel): usonic = USonic() relay = Relay() while 1: distance = usonic.get_distance() # 10 feet if distance > 305: relay.turn_on_only(relay.GREEN) # 1 foot elif distance > 95: relay.turn_on_only(relay.YELLOW) else: relay.turn_on_only(relay.RED) time.sleep(1)
def park_assist(channel): usonic = USonic() relay = Relay() while 1: distance = usonic.get_distance() # 10 feet if distance > 305: relay.turn_on_only(relay.green) # 1 foot elif distance > 95: relay.turn_on_only(relay.yellow) else: relay.turn_on_only(relay.red) time.sleep(1)
def setup(self): self.usonic = USonic(TRIGGER=10, ECHO=9)