Beispiel #1
0
    def __init__(self,
                 env_fns: List[Tuple[Callable[[], Union[str, gym.Env]],
                                     Callable[[torch.Tensor],
                                              Union[torch.Tensor, np.ndarray,
                                                    list]]]]):
        """ Constructor

        Args:
            env_fns: a list of pairs of functions, the first of which create one environment and the second is the mapper
                that converts the action outputs from the model to what can be accepted by the env object. 
                See VectorizedMultiAgentEnvWrapper.MultiAgentEnvWrapper for details
        """
        self.envs = [
            self.MultiAgentEnvWrapper(fn_pair[0](), fn_pair[1])
            for fn_pair in env_fns
        ]
        env = self.envs[0]
        VecEnv.__init__(self, len(env_fns), env.observation_space,
                        env.action_space)
        obs_space = env.observation_space
        self.keys, shapes, dtypes = obs_space_info(obs_space)

        self.buf_obs = OrderedDict([(k,
                                     np.zeros(
                                         (self.num_envs, ) + tuple(shapes[k]),
                                         dtype=dtypes[k])) for k in self.keys])
        self.buf_dones = np.zeros((self.num_envs, 1), dtype=bool)
        self.buf_rews = np.zeros((self.num_envs, 1, env.agent_num),
                                 dtype=np.float32)
        self.buf_infos = [{} for _ in range(self.num_envs)]
        self.actions = None
        self.metadata = env.metadata
Beispiel #2
0
    def __init__(self):
        # self.stackSize = 10
        self.scanSize = 1080
        self.action_space = spaces.Box(low=np.array([-1, -1]),
                                       high=np.array([1, 1]),
                                       dtype=np.float32)
        # stacked self.stackSize latest observations of (scan, x,y,theta,vel_x, vel_y, vel_z)*2 (we get the data from the opponent as well)
        self.observation_space = spaces.Box(low=0.0,
                                            high=1.0,
                                            shape=((self.scanSize + 6) * 2, ),
                                            dtype=np.float32)
        VecEnv.__init__(self, 2, self.observation_space, self.action_space)
        self.keys, shapes, dtypes = obs_space_info(self.observation_space)

        self.actions = None

        # simualtor params
        self.params_set = False
        self.map_inited = False
        # params list is [mu, h_cg, l_r, cs_f, cs_r, I_z, mass]
        self.params = []
        self.num_agents = 2
        self.timestep = 0.01
        self.map_path = None
        self.map_img = None
        self.ego_idx = 0
        self.timeout = 120.0
        # radius to consider done
        self.start_thresh = 0.5  # 10cm
        # env states
        # more accurate description should be ego car state
        # might not need to keep scan
        self.x = None
        self.y = None
        self.theta = None

        self.in_collision = False
        self.collision_angle = None

        # loop completion
        self.near_start = True
        self.num_toggles = 0

        # race info
        self.lap_times = [0.0, 0.0]
        self.lap_counts = [0, 0]

        self.map_height = 0.0
        self.map_width = 0.0
        self.map_resolution = 0.0
        self.free_thresh = 0.0
        self.origin = []
        self.port = 6666
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.PAIR)
        self.socket.connect('tcp://localhost:6666')
        print('Gym env - Connected env to port: ' + str(self.port))
        self.sim_p = None
        print('Gym env - env created, waiting for params...')
Beispiel #3
0
    def __init__(self, env_fns: List[Callable[[], gym.Env]]):
        self.envs = [fn() for fn in env_fns]
        env = self.envs[0]
        VecEnv.__init__(self, len(env_fns), env.observation_space, env.action_space)
        obs_space = env.observation_space
        self.keys, shapes, dtypes = obs_space_info(obs_space)

        self.buf_obs = OrderedDict([(k, np.zeros((self.num_envs,) + tuple(shapes[k]), dtype=dtypes[k])) for k in self.keys])
        self.buf_dones = np.zeros((self.num_envs,), dtype=np.bool)
        self.buf_rews = np.zeros((self.num_envs,), dtype=np.float32)
        self.buf_infos = [{} for _ in range(self.num_envs)]
        self.actions = None
        self.metadata = env.metadata