Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update observation space in configure(), #128

Open
wants to merge 1 commit into
base: v1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading