def create_sample_tub(path, records=128): inputs = [ 'cam/image_array', 'user/angle', 'user/throttle', 'location/one_hot_state_array' ] types = ['image_array', 'float', 'float', 'vector'] t = Tub(path, inputs=inputs, types=types) cam = SquareBoxCamera() tel = MovingSquareTelemetry() num_loc = 10 for _ in range(records): x, y = tel.run() img_arr = cam.run(x, y) loc = [0 for i in range(num_loc)] loc[1] = 1.0 t.put_record({ 'cam/image_array': img_arr, 'user/angle': x, 'user/throttle': y, 'location/one_hot_state_array': loc }) global temp_tub_path temp_tub_path = t print("setting temp tub path to:", temp_tub_path) return t
def create_sample_tub(path, records=10): inputs = ['cam/image_array', 'angle', 'throttle'] types = ['image_array', 'float', 'float'] t = Tub(path, inputs=inputs, types=types) cam = SquareBoxCamera() tel = MovingSquareTelemetry() for _ in range(records): x, y = tel.run() img_arr = cam.run(x, y) t.put_record({'cam/image_array': img_arr, 'angle': x, 'throttle': y}) return t
class TestSquareBoxCamera(unittest.TestCase): def setUp(self): self.cam = SquareBoxCamera() def test_run_types(self): arr = self.cam.run(50, 50) assert type(arr) == np.ndarray
def create_sample_tub(path, records=128): inputs = ['cam/image_array', 'user/angle', 'user/throttle'] types = ['image_array', 'float', 'float'] t = Tub(path, inputs=inputs, types=types) cam = SquareBoxCamera() tel = MovingSquareTelemetry() for _ in range(records): x, y = tel.run() img_arr = cam.run(x, y) t.put_record({ 'cam/image_array': img_arr, 'user/angle': x, 'user/throttle': y }) global temp_tub_path temp_tub_path = t print("setting temp tub path to:", temp_tub_path) return t
def drive(cfg, model_path=None): V = dk.vehicle.Vehicle() V.mem.put(['square/angle', 'square/throttle'], (100, 100)) # display square box given by cooridantes. cam = SquareBoxCamera(resolution=cfg.CAMERA_RESOLUTION) V.add(cam, inputs=['square/angle', 'square/throttle'], outputs=['cam/image_array']) # display the image and read user values from a local web controller ctr = LocalWebController() V.add(ctr, inputs=['cam/image_array'], outputs=['user/angle', 'user/throttle', 'user/mode', 'recording'], threaded=True) # See if we should even run the pilot module. # This is only needed because the part run_contion only accepts boolean def pilot_condition(mode): if mode == 'user': return False else: return True pilot_condition_part = Lambda(pilot_condition) V.add(pilot_condition_part, inputs=['user/mode'], outputs=['run_pilot']) # Run the pilot if the mode is not user. kl = KerasCategorical() if model_path: kl.load(model_path) V.add(kl, inputs=['cam/image_array'], outputs=['pilot/angle', 'pilot/throttle'], run_condition='run_pilot') # See if we should even run the pilot module. def drive_mode(mode, user_angle, user_throttle, pilot_angle, pilot_throttle): if mode == 'user': return user_angle, user_throttle elif mode == 'pilot_angle': return pilot_angle, user_throttle else: return pilot_angle, pilot_throttle drive_mode_part = Lambda(drive_mode) V.add(drive_mode_part, inputs=['user/mode', 'user/angle', 'user/throttle', 'pilot/angle', 'pilot/throttle'], outputs=['angle', 'throttle']) clock = Timestamp() V.add(clock, outputs=['timestamp']) # transform angle and throttle values to coordinate values def f(x): return int(x * 100 + 100) l = Lambda(f) V.add(l, inputs=['user/angle'], outputs=['square/angle']) V.add(l, inputs=['user/throttle'], outputs=['square/throttle']) # add tub to save data inputs=['cam/image_array', 'user/angle', 'user/throttle', 'pilot/angle', 'pilot/throttle', 'square/angle', 'square/throttle', 'user/mode', 'timestamp'] types=['image_array', 'float', 'float', 'float', 'float', 'float', 'float', 'str', 'str'] #multiple tubs #th = TubHandler(path=cfg.DATA_PATH) #tub = th.new_tub_writer(inputs=inputs, types=types) # single tub tub = TubWriter(path=cfg.TUB_PATH, inputs=inputs, types=types) V.add(tub, inputs=inputs, run_condition='recording') # run the vehicle for 20 seconds V.start(rate_hz=50, max_loop_count=10000)
def create_sample_record(): cam = SquareBoxCamera() tel = MovingSquareTelemetry() x, y = tel.run() img_arr = cam.run(x, y) return {'cam/image_array': img_arr, 'angle': x, 'throttle':y}
def setUp(self): self.cam = SquareBoxCamera()