import pybullet as pb import pybullet_data from llm_panda import config class SimEngine: """Manages the lifecycle of the PyBullet simulation.""" def __init__(self, gui=False, real_time=False): self.gui = gui self.real_time = real_time self.client = None def connect(self): self.client = pb.connect(pb.GUI if self.gui else pb.DIRECT) pb.setAdditionalSearchPath(pybullet_data.getDataPath()) pb.setGravity(0, 0, config.GRAVITY) pb.setTimeStep(config.SIM_TIMESTEP) if self.gui: pb.configureDebugVisualizer(pb.COV_ENABLE_GUI, 0) pb.resetDebugVisualizerCamera(1.2, 50, -35, [0.5, 0.0, 0.2]) if self.real_time: pb.setRealTimeSimulation(1) return self.client def disconnect(self): if self.client is not None: try: pb.disconnect(self.client) except Exception: pass self.client = None def step(self): if self.client is not None: pb.stepSimulation(self.client)