class Agent: def __init__(self): self.arduino = Arduino() def run(self): self.ensureStopped() loops = 0 issueTime = current_milli_time() self.arduino.writeMessage("W10") while True: observation = self.arduino.getState() wheelSpeed = float(observation[3]) if (wheelSpeed > 0.0): responseTime = current_milli_time() - issueTime print("response time: {}".format(responseTime)) break else: loops += 1 self.ensureStopped() print("End of experiment! Loops: {}".format(loops)) def ensureStopped(self): print("Ensuring stopped...") self.arduino.writeMessage("W0") while True: observation = self.arduino.getState() wheelSpeed = float(observation[3]) if (wheelSpeed == 0.0): print("Stopped! :)") return else: time.sleep(0.5)
class Agent: def __init__(self): self.arduino = Arduino() def run(self): while True: print( "Type H for help. Prefix a command with ! if not expecting a response." ) userString = input() if userString[0] == '!': userString = userString[1:] self.arduino.writeMessage(userString) else: print(self.arduino.writeMessageAndWait(userString))