diff --git a/f1tenth_gym/envs/f110_env.py b/f1tenth_gym/envs/f110_env.py index 89a8064b..920089b0 100644 --- a/f1tenth_gym/envs/f110_env.py +++ b/f1tenth_gym/envs/f110_env.py @@ -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 diff --git a/tests/test_f110_env.py b/tests/test_f110_env.py index bd1888c5..c5c6e51e 100644 --- a/tests/test_f110_env.py +++ b/tests/test_f110_env.py @@ -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.