File size: 1,100 Bytes
00b6c5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)