From 44fea918bafe6040b6c37c29e6b73befb98b0a20 Mon Sep 17 00:00:00 2001 From: pengzhenghao Date: Thu, 5 Dec 2024 20:35:59 -0800 Subject: [PATCH] Allow to config "set_static", default to False to fix the bug of flickerring visualization. --- metadrive/envs/scenario_env.py | 11 +++++++++-- metadrive/policy/replay_policy.py | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/metadrive/envs/scenario_env.py b/metadrive/envs/scenario_env.py index 1ba065862..fa35f178b 100644 --- a/metadrive/envs/scenario_env.py +++ b/metadrive/envs/scenario_env.py @@ -59,6 +59,12 @@ lane_line_detector=dict(num_lasers=0, distance=50), side_detector=dict(num_lasers=12, distance=50), ), + # If set_static=True, then the agent will not "fall from the sky". This will be helpful if you want to + # capture per-frame data for the agent (for example for collecting static sensor data). + # However, the physics engine will not update the position of the agent. So in the visualization, the image will be + # very chunky as the agent will not suddenly move to the next position for each step. + # Set to False for better visualization. + set_static=False, # ===== Reward Scheme ===== # See: https://github.com/metadriverse/metadrive/issues/283 @@ -410,7 +416,8 @@ def _reset_global_seed(self, force_seed=None): # "no_traffic":True, # "start_scenario_index": 192, # "start_scenario_index": 1000, - "num_scenarios": 30, + "num_scenarios": 3, + "set_static": True, # "force_reuse_object_name": True, # "data_directory": "/home/shady/Downloads/test_processed", "horizon": 1000, @@ -424,7 +431,7 @@ def _reset_global_seed(self, force_seed=None): lane_line_detector=dict(num_lasers=12, distance=50), side_detector=dict(num_lasers=160, distance=50) ), - "data_directory": AssetLoader.file_path("nuplan", unix_style=False), + "data_directory": AssetLoader.file_path("nuscenes", unix_style=False), } ) success = [] diff --git a/metadrive/policy/replay_policy.py b/metadrive/policy/replay_policy.py index 28ccce036..f66b3097d 100644 --- a/metadrive/policy/replay_policy.py +++ b/metadrive/policy/replay_policy.py @@ -63,7 +63,14 @@ def act(self, *args, **kwargs): self.control_object.set_velocity(info["velocity"], in_local_frame=self._velocity_local_frame) self.control_object.set_heading_theta(info["heading"]) self.control_object.set_angular_velocity(info["angular_velocity"]) - self.control_object.set_static(True) + + # If set_static, then the agent will not "fall from the sky". + # However, the physics engine will not update the position of the agent. + # So in the visualization, the image will be very chunky as the agent will not suddenly move to the next + # position for each step. + + if self.engine.global_config.get("set_static", False): + self.control_object.set_static(True) return None # Return None action so the base vehicle will not overwrite the steering & throttle