Skip to content

Commit

Permalink
update observation space in configure(),
Browse files Browse the repository at this point in the history
add test to check it
  • Loading branch information
Berducci, Luigi committed Apr 18, 2024
1 parent 5dbba85 commit 88d0c7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions f1tenth_gym/envs/f110_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def configure(self, config: dict) -> None:
self.action_type.space, self.num_agents
)

if hasattr(self, "observation_space"):
self.observation_type = observation_factory(
env=self, **self.config["observation_config"]
)
self.observation_space = self.observation_type.space()

def _check_done(self):
"""
Check if the current rollout is done
Expand Down
18 changes: 18 additions & 0 deletions tests/test_f110_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ def test_configure_action_space(self):
f"Speed action high should be {new_v_max}",
)

def test_configure_observation_space(self):
"""
Try to change the observed features and check if the observation space is correctly updated.
"""
base_env = self._make_env()
new_obs_cfg = {"type": "features", "features": ["pose_x", "pose_y", "pose_theta"]}

base_env.configure(config={"observation_config": new_obs_cfg})

agent_id = base_env.agent_ids[0]
ego_space = base_env.observation_space.spaces[agent_id].spaces
self.assertTrue(
all([k in ego_space for k in new_obs_cfg["features"]]),
)
self.assertTrue(
all([k in new_obs_cfg["features"] for k in ego_space]),
)

def test_acceleration_action_space(self):
"""
Test that the acceleration action space is correctly configured.
Expand Down

0 comments on commit 88d0c7b

Please sign in to comment.