(self, env, input_states=[], acc_as_action=False)
| 22 | |
| 23 | class RlBirdviewWrapper(gym.Wrapper): |
| 24 | def __init__(self, env, input_states=[], acc_as_action=False): |
| 25 | assert len(env._obs_configs) == 1 |
| 26 | self._ev_id = list(env._obs_configs.keys())[0] |
| 27 | self._input_states = input_states |
| 28 | self._acc_as_action = acc_as_action |
| 29 | self._render_dict = {} |
| 30 | |
| 31 | state_spaces = [] |
| 32 | if 'speed' in self._input_states: |
| 33 | state_spaces.append(env.observation_space[self._ev_id]['speed']['speed_xy']) |
| 34 | if 'speed_limit' in self._input_states: |
| 35 | state_spaces.append(env.observation_space[self._ev_id]['control']['speed_limit']) |
| 36 | if 'control' in self._input_states: |
| 37 | state_spaces.append(env.observation_space[self._ev_id]['control']['throttle']) |
| 38 | state_spaces.append(env.observation_space[self._ev_id]['control']['steer']) |
| 39 | state_spaces.append(env.observation_space[self._ev_id]['control']['brake']) |
| 40 | state_spaces.append(env.observation_space[self._ev_id]['control']['gear']) |
| 41 | if 'acc_xy' in self._input_states: |
| 42 | state_spaces.append(env.observation_space[self._ev_id]['velocity']['acc_xy']) |
| 43 | if 'vel_xy' in self._input_states: |
| 44 | state_spaces.append(env.observation_space[self._ev_id]['velocity']['vel_xy']) |
| 45 | if 'vel_ang_z' in self._input_states: |
| 46 | state_spaces.append(env.observation_space[self._ev_id]['velocity']['vel_ang_z']) |
| 47 | |
| 48 | state_low = np.concatenate([s.low for s in state_spaces]) |
| 49 | state_high = np.concatenate([s.high for s in state_spaces]) |
| 50 | |
| 51 | env.observation_space = gym.spaces.Dict( |
| 52 | {'state': gym.spaces.Box(low=state_low, high=state_high, dtype=np.float32), |
| 53 | 'birdview': env.observation_space[self._ev_id]['birdview']['masks']}) |
| 54 | |
| 55 | if self._acc_as_action: |
| 56 | # act: acc(throttle/brake), steer |
| 57 | env.action_space = gym.spaces.Box(low=np.array([-1, -1]), high=np.array([1, 1]), dtype=np.float32) |
| 58 | else: |
| 59 | # act: throttle, steer, brake |
| 60 | env.action_space = gym.spaces.Box(low=np.array([0, -1, 0]), high=np.array([1, 1, 1]), dtype=np.float32) |
| 61 | |
| 62 | super(RlBirdviewWrapper, self).__init__(env) |
| 63 | |
| 64 | self.eval_mode = False |
| 65 | |
| 66 | def step(self, action): |
| 67 | action_ma = {self._ev_id: self.process_act(action, self._acc_as_action)} |
nothing calls this directly
no outgoing calls
no test coverage detected