Skip to content

Commit 9a1f4d6

Browse files
committed
Enhances PyBullet client with debug GUI option
Introduces an `enable_debug_gui` parameter to the `PyBulletBase.connect()` method, allowing users to enable or disable the GUI sidebar and parameter views. This update improves the flexibility of the PyBullet client for debugging and visualization purposes.
1 parent 180681b commit 9a1f4d6

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/compas_fab/backends/pybullet/client.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242

4343

4444
# If Pybullet is not defined, load it from LazyLoader
45-
if "pybullet" not in sys.modules:
45+
try:
46+
import pybullet # Try to import directly
47+
except ImportError:
48+
# Fallback to LazyLoader if import fails
4649
pybullet = LazyLoader("pybullet", globals(), "pybullet") # noqa: F811
4750

4851
__all__ = [
@@ -68,6 +71,7 @@ def connect(
6871
width: Optional[int] = None,
6972
height: Optional[int] = None,
7073
verbose: bool = False,
74+
enable_debug_gui: bool = False,
7175
):
7276
"""Connect from the PyBullet server.
7377
@@ -81,6 +85,10 @@ def connect(
8185
Set the width in pixels of the GUI. Defaults to ``None``.
8286
height : :obj:`int`
8387
Set the height in pixels of GUI. Defaults to ``None``.
88+
verbose : :obj:`bool`
89+
Enable verbose output. Defaults to ``False``.
90+
enable_debug_gui : :obj:`bool`
91+
Enable the GUI sidebar and parameter views. Defaults to ``False``.
8492
8593
Returns
8694
-------
@@ -103,7 +111,7 @@ def connect(
103111
if self.client_id < 0:
104112
raise Exception("Error in establishing connection with PyBullet.")
105113
if self.connection_type == "gui":
106-
self._configure_debug_visualizer(shadows)
114+
self._configure_debug_visualizer(shadows, enable_debug_gui)
107115

108116
@staticmethod
109117
def _compose_options(
@@ -118,9 +126,9 @@ def _compose_options(
118126
options += "--height={}".format(height)
119127
return options
120128

121-
def _configure_debug_visualizer(self, shadows: bool = True):
122-
# COV_ENABLE_GUI = False turns off the sidebar and parameter views in the GUI
123-
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_GUI, False, physicsClientId=self.client_id)
129+
def _configure_debug_visualizer(self, shadows: bool = True, enable_debug_gui: bool = False):
130+
# COV_ENABLE_GUI controls the sidebar and parameter views in the GUI
131+
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_GUI, enable_debug_gui, physicsClientId=self.client_id)
124132
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_TINY_RENDERER, False, physicsClientId=self.client_id)
125133
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_RGB_BUFFER_PREVIEW, False, physicsClientId=self.client_id)
126134
pybullet.configureDebugVisualizer(
@@ -187,9 +195,10 @@ class PyBulletClient(PyBulletBase, ClientInterface):
187195
188196
"""
189197

190-
def __init__(self, connection_type: str = "gui", verbose: bool = False):
198+
def __init__(self, connection_type: str = "gui", verbose: bool = False, enable_gui: bool = False):
191199
super(PyBulletClient, self).__init__(connection_type)
192200
self.verbose = verbose
201+
self.enable_debug_gui = enable_debug_gui
193202

194203
# Robot Cell
195204
# The Pybullet client will not keep track of the Robot object directly but uses the one embedded in the RobotCell
@@ -239,7 +248,7 @@ def robot_cell_state(self) -> RobotCellState:
239248

240249
def __enter__(self):
241250
self._cache_dir = tempfile.TemporaryDirectory(prefix="compas_fab")
242-
self.connect(verbose=self.verbose)
251+
self.connect(verbose=self.verbose, enable_debug_gui=self.enable_debug_gui)
243252
return self
244253

245254
def __exit__(self, *args):
@@ -1014,7 +1023,7 @@ def _get_geometry_args(path, concavity=False, scale=1.0):
10141023
class AnalyticalPyBulletClient(PyBulletClient):
10151024
"""Combination of PyBullet as the client for Collision Detection and Analytical Inverse Kinematics."""
10161025

1017-
def __init__(self, connection_type="gui", verbose=False):
1026+
def __init__(self, connection_type="gui", verbose=False, enable_gui=False):
10181027
super(AnalyticalPyBulletClient, self).__init__(connection_type=connection_type, verbose=verbose)
10191028

10201029
# TODO: Move the following function to AnalyticalPyBulletPlanner

0 commit comments

Comments
 (0)