class Car(object): """ Control of our lego buggy via left, right and gas pins """ def __init__(self): self.left = ExclusivePin(17, None) self.right = ExclusivePin(14, self.left) self.gas = Pin(0) self.left.xpin = self.left def turn(self, s, is_left, angle=0.05): first = self.left if is_left else self.right second = self.right if is_left else self.left first.drive(angle) end = time.time() + s while time.time() < end: sleep(0.25) first.drive(angle/10) second.drive(angle) def turn_left(self, s): self.turn(s, True) def turn_right(self, s): self.turn(s, False) def rev(self, s=0.4): self.gas.drive(s) def start(self, wait=None): self.gas.on() if wait: sleep(wait) def pause(self, s): self.stop() sleep(s) self.start() def stop(self): self.gas.off() def all_stop(self): self.stop() self.left.off() self.right.off()
def __init__(self): self.left = ExclusivePin(17, None) self.right = ExclusivePin(14, self.left) self.gas = Pin(0) self.left.xpin = self.left