Пример #1
0
    def __init__(self,
                 level,
                 port=9090,
                 max_cte_error=3.0,
                 road_style=0,
                 seed=0,
                 turn_increment=1.0):

        self.level = level
        self.verbose = False
        # sensor size - height, width, depth
        self.camera_img_size = INPUT_DIM

        self.address = ('0.0.0.0', port)

        # Socket message handler
        self.handler = DonkeyUnitySimHandler(level,
                                             max_cte_error=max_cte_error,
                                             road_style=road_style,
                                             seed=seed,
                                             turn_increment=turn_increment)
        # Create the server to which the unity sim will connect
        self.server = SimServer(self.address, self.handler)
        # Start the Asynchronous socket handler thread
        self.thread = Thread(target=asyncore.loop)
        self.thread.daemon = True
        self.thread.start()
Пример #2
0
    def __init__(self, level, time_step=0.05, port=9090, max_cte=5.0, verbose=False, cam_resolution=(120, 160, 3)):
        self.address = ('0.0.0.0', port)

        self.handler = DonkeyUnitySimHandler(level, time_step=time_step, max_cte=max_cte, verbose=verbose, cam_resolution=cam_resolution)

        try:
            self.server = SimServer(self.address, self.handler)
        except OSError:
            print('raising custom error')
            raise SimFailed("failed to listen on address %s" % self.address)
        
        self.thread = Thread(target=asyncore.loop)
        self.thread.daemon = True
        self.thread.start()
Пример #3
0
    def __init__(self, level, time_step=0.05, port=9090):
        self.level = level
        self.time_step = time_step
        self.verbose = False
        self.wait_time_for_obs = 0.1

        # sensor size - height, width, depth
        self.camera_img_size = (80, 160, 3)

        self.address = ('0.0.0.0', port)

        self.handler = DonkeyUnitySimHandler(level, time_step=time_step)
        self.server = SimServer(self.address, self.handler)

        self.thread = Thread(target=asyncore.loop)
        self.thread.daemon = True
        self.thread.start()
Пример #4
0
def go(filename, address, constant_throttle, gif):

    model = load_model(filename)

    #In this mode, looks like we have to compile it
    model.compile("sgd", "mse")

    movie_handler = None

    if gif != "none":
        movie_handler = GifCreator(gif)
  
    #setup the server
    handler = DonkeySimMsgHandler(model, constant_throttle, movie_handler)
    server = SimServer(address, handler)

    try:
        #asyncore.loop() will keep looping as long as any asyncore dispatchers are alive
        asyncore.loop()
    except KeyboardInterrupt:
        #unless some hits Ctrl+C and then we get this interrupt
        print('stopping')
class DonkeyUnitySimContoller:
    """
    Wrapper for communicating with unity simulation.

    :param level: (int) Level index
    :param port: (int) Port to use for communicating with the simulator
    :param max_cte_error: (float) Max cross track error before reset
    """
    def __init__(self, level, port=9090, max_cte_error=3.0):
        self.level = level
        self.verbose = False

        # sensor size - height, width, depth
        self.camera_img_size = INPUT_DIM

        self.address = ('0.0.0.0', port)

        # Socket message handler
        self.handler = DonkeyUnitySimHandler(level,
                                             max_cte_error=max_cte_error)
        # Create the server to which the unity sim will connect
        self.server = SimServer(self.address, self.handler)
        # Start the Asynchronous socket handler thread
        self.thread = Thread(target=asyncore.loop)
        self.thread.daemon = True
        self.thread.start()

    def close_connection(self):
        return self.server.handle_close()

    def wait_until_loaded(self):
        while not self.handler.loaded:
            print("Waiting for sim to start...")
            time.sleep(3.0)

    def reset(self):
        self.handler.reset()

    def get_sensor_size(self):
        return self.handler.get_sensor_size()

    def take_action(self, action):
        self.handler.take_action(action)

    def get_original_image(self):
        return self.handler.original_image

    def observe(self):
        return self.handler.observe()

    def quit(self):
        pass

    def render(self, mode):
        pass

    def is_game_over(self):
        return self.handler.is_game_over()

    def calc_reward(self, done):
        return self.handler.calc_reward(done)
Пример #6
0
class DonkeyUnitySimContoller:
    """
    Wrapper for communicating with unity simulation.

    :param level: (int) Level index
    :param port: (int) Port to use for communicating with the simulator
    :param max_cte_error: (float) Max cross track error before reset
    :param road_style: (int)
    :param seed: (int)
    :param turn_increment: (float)
    """
    def __init__(self,
                 level,
                 port=9090,
                 max_cte_error=3.0,
                 road_style=0,
                 seed=0,
                 turn_increment=1.0):

        self.level = level
        self.verbose = False
        # sensor size - height, width, depth
        self.camera_img_size = INPUT_DIM

        self.address = ('0.0.0.0', port)

        # Socket message handler
        self.handler = DonkeyUnitySimHandler(level,
                                             max_cte_error=max_cte_error,
                                             road_style=road_style,
                                             seed=seed,
                                             turn_increment=turn_increment)
        # Create the server to which the unity sim will connect
        self.server = SimServer(self.address, self.handler)
        # Start the Asynchronous socket handler thread
        self.thread = Thread(target=asyncore.loop)
        self.thread.daemon = True
        self.thread.start()

    def close_connection(self):
        return self.server.handle_close()

    def wait_until_loaded(self):
        """
        Wait for a client (Unity simulator).
        """
        while not self.handler.loaded:
            print(
                "Waiting for sim to start..."
                "if the simulation is running, press EXIT to go back to the menu"
            )
            time.sleep(3.0)
        self.regen_road()

    def reset(self):
        self.handler.reset()

    def regen_road(self):
        self.handler.send_regen_road()

    def seed(self, seed):
        self.handler.seed = seed

    def get_sensor_size(self):
        """
        :return: (int, int, int)
        """
        return self.handler.get_sensor_size()

    def take_action(self, action):
        self.handler.take_action(action)

    def observe(self):
        """
        :return: (np.ndarray)
        """
        return self.handler.observe()

    def quit(self):
        pass

    def render(self, mode):
        pass

    def is_game_over(self):
        return self.handler.is_game_over()

    def calc_reward(self, done):
        return self.handler.calc_reward(done)