Exemplo n.º 1
0
def main():
  arduino = Arduino()
  pid_client = PidClient()

  if(LOG):
    timestr = time.strftime("%Y%m%d-%H%M%S")
    filename = "pid_log-" + timestr + ".txt"
    file = open(filename,"w+")
    loglines = 0

  while(True):
    print("waiting for state...")
    state = arduino.waitForState() # blocking
    newControl = pid_client.determineControl(state)

    if(LOG):
      logLine = str(state) + "," + str(newControl) + "\n"
      logLine = logLine.strip("[]")
      file.write(logLine)
      loglines += 1
      if(loglines % 1000 == 0):
        print("loglines: {}".format(loglines))
        file.flush()

    arduino.accelerateMotorPower(newControl)
Exemplo n.º 2
0
def main():

    if (len(sys.argv) != 2):
        print("give me a model file as argument please!")
        exit()

    modelfile = sys.argv[1]

    arduino = Arduino()
    model = load_model(modelfile)
    print("waiting for first state...")
    obs = arduino.waitForState()
    print("neat found first state!")

    while (True):
        obs = arduino.waitForState()
        foo = np.array(obs)
        bar = foo.reshape((1, -1))
        action = model.predict(bar, batch_size=1)
        action = action[0][0]
        print(action)
        arduino.updateMotorPower(action)