def __init__(self, ): self.fetcher = Fetcher() self.actions = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] self.curr_score = 0 self.curr_step = 0
def run(): fetcher = Fetcher() while True: outputData = fetcher.sync() if outputData is None: continue print "Timestep: {0}".format(fetcher.timestep) print outputData if fetcher.skippedTimesteps > 0: print("Warning: skipped {0} timesteps, " "now at {1}").format(fetcher.skippedTimesteps, fetcher.timestep) if outputData["reset"]: print "Reset." print "============"
def collectDepthData(outputDir=_OUTPUT_DIR): fetcher = Fetcher() holdingDownKey = False while True: outputData = fetcher.sync() if outputData is None or "collectKeyPressed" not in outputData: holdingDownKey = False continue if outputData["collectKeyPressed"] == 0: holdingDownKey = False continue if holdingDownKey: print "Stop holding down the key!" continue print "Collecting data." holdingDownKey = True sensor = outputData["ForwardsSweepSensor"] depthData = np.array(sensor) dt = time.strftime("%y%m%d%H%M%S") depthID = 'depth_'+dt+'.txt' depthOutputPath = os.path.join(os.path.dirname(__file__), outputDir, depthID) np.savetxt(depthOutputPath, depthData) print "Wrote out to ", depthOutputPath