diff --git a/self_driving/beamng_brewer.py b/self_driving/beamng_brewer.py index c293f4d..0abc4f1 100644 --- a/self_driving/beamng_brewer.py +++ b/self_driving/beamng_brewer.py @@ -53,8 +53,13 @@ def __init__(self, beamng_home=None, beamng_user=None, reuse_beamng=True, road_n self.camera: BeamNGCamera = None if road_nodes: self.setup_road_nodes(road_nodes) - steps = 5 - self.params = SimulationParams(beamng_steps=steps, delay_msec=int(steps * 0.05 * 1000)) + + # TODO Make this configurable + # Configure the simulator to monitor at 20Hz frequency, i.e., every 60/3 steps in a second + steps_per_second = 60 + steps = 3 + # + self.params = SimulationParams(beamng_steps=steps, beamng_steps_per_second=steps_per_second, delay_msec=int(steps * 0.05 * 1000)) self.vehicle_start_pose = BeamNGPose() def setup_road_nodes(self, road_nodes): @@ -91,15 +96,24 @@ def bring_up(self): self.scenario.make(self.beamng) - self.beamng.set_deterministic() - self.beamng.load_scenario(self.scenario) + # Ensure the simulation runs deterministically at the given frequency + self.beamng.set_deterministic() + self.beamng.set_steps_per_second(self.params.beamng_steps_per_second) + + # Start the simulation but pause it rightaway self.beamng.start_scenario() # Pause the simulator only after loading and starting the scenario self.beamng.pause() + frequency = self.params.beamng_steps_per_second / self.params.beamng_steps + log.info("Starting a new simulation with params: Step %s, Step/Second %s (Freq %s Hz)", self.params.beamng_steps, self.params.beamng_steps_per_second, frequency) + + + + def __del__(self): if self.beamng: try: diff --git a/self_driving/simulation_data.py b/self_driving/simulation_data.py index c306434..264c301 100644 --- a/self_driving/simulation_data.py +++ b/self_driving/simulation_data.py @@ -19,7 +19,7 @@ SimulationDataRecord = namedtuple('SimulationDataRecord', SimulationDataRecordProperties) SimulationDataRecords = List[SimulationDataRecord] -SimulationParams = namedtuple('SimulationParameters', ['beamng_steps', 'delay_msec']) +SimulationParams = namedtuple('SimulationParameters', ['beamng_steps', 'beamng_steps_per_second', 'delay_msec']) def delete_folder_recursively(path: Union[str, Path], exception_if_fail: bool = True): path = str(path)