Skip to content

Commit 62ec875

Browse files
committed
yapf
1 parent 7ec50c5 commit 62ec875

9 files changed

Lines changed: 278 additions & 166 deletions

File tree

predicators/envs/pybullet_domino/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
env = PyBulletDominoFanEnv(use_gui=True)
1212
"""
1313

14-
from predicators.envs.pybullet_domino.composed_env import (
15-
PyBulletDominoEnvNew,
16-
PyBulletDominoFanEnvNew,
17-
)
14+
from predicators.envs.pybullet_domino.composed_env import \
15+
PyBulletDominoEnvNew, PyBulletDominoFanEnvNew
1816

1917
# Backward-compatible aliases
2018
PyBulletDominoEnv = PyBulletDominoEnvNew

predicators/envs/pybullet_domino/components/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
"""Domino environment components.
22
33
Each component encapsulates a specific aspect of the domino environment
4-
(e.g., dominoes, fans, balls, ramps) and can be composed together to create
5-
different environment variants.
4+
(e.g., dominoes, fans, balls, ramps) and can be composed together to
5+
create different environment variants.
66
"""
77

8+
from predicators.envs.pybullet_domino.components.ball_component import \
9+
BallComponent
810
from predicators.envs.pybullet_domino.components.base_component import \
911
DominoEnvComponent
1012
from predicators.envs.pybullet_domino.components.domino_component import \
1113
DominoComponent
1214
from predicators.envs.pybullet_domino.components.fan_component import \
1315
FanComponent
14-
from predicators.envs.pybullet_domino.components.ball_component import \
15-
BallComponent
1616

1717
__all__ = [
1818
"DominoEnvComponent",

predicators/envs/pybullet_domino/components/ball_component.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ class BallComponent(DominoEnvComponent):
3939
ball_restitution: ClassVar[float] = 0.3
4040
ball_linear_damping: ClassVar[float] = 0.5
4141
ball_angular_damping: ClassVar[float] = 0.3
42-
ball_color: ClassVar[Tuple[float, float, float, float]] = (0.0, 0.0, 1.0,
43-
1.0)
42+
ball_color: ClassVar[Tuple[float, float, float,
43+
float]] = (0.0, 0.0, 1.0, 1.0)
4444

4545
# =========================================================================
4646
# TARGET CONFIGURATION
4747
# =========================================================================
4848
target_thickness: ClassVar[float] = 0.00001
4949
target_mass: ClassVar[float] = 0.0
5050
target_friction: ClassVar[float] = 0.04
51-
target_color: ClassVar[Tuple[float, float, float, float]] = (0.0, 1.0, 0.0,
52-
1.0)
51+
target_color: ClassVar[Tuple[float, float, float,
52+
float]] = (0.0, 1.0, 0.0, 1.0)
5353

5454
def __init__(self,
5555
workspace_bounds: Optional[Dict[str, float]] = None,
@@ -267,7 +267,8 @@ def get_init_dict_entries(
267267
min_distance: float = 0.15
268268
target_x = rng.uniform(self.x_lb + 0.05, self.x_ub - 0.05)
269269
target_y = rng.uniform(self.y_lb + 0.05, self.y_ub - 0.05)
270-
while np.sqrt((target_x - ball_x)**2 + (target_y - ball_y)**2) < min_distance:
270+
while np.sqrt((target_x - ball_x)**2 +
271+
(target_y - ball_y)**2) < min_distance:
271272
target_x = rng.uniform(self.x_lb + 0.05, self.x_ub - 0.05)
272273
target_y = rng.uniform(self.y_lb + 0.05, self.y_ub - 0.05)
273274
else:

predicators/envs/pybullet_domino/components/base_component.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
class DominoEnvComponent(ABC):
2020
"""Abstract base class for all domino environment components.
2121
22-
Components encapsulate specific functionality (e.g., dominoes, fans, balls)
23-
and can be composed together to create different environment configurations.
22+
Components encapsulate specific functionality (e.g., dominoes, fans,
23+
balls) and can be composed together to create different environment
24+
configurations.
2425
"""
2526

2627
def __init__(self) -> None:
2728
"""Initialize the component.
2829
29-
Subclasses should create their types, predicates, and objects here.
30+
Subclasses should create their types, predicates, and objects
31+
here.
3032
"""
3133
self._physics_client_id: Optional[int] = None
3234

@@ -46,7 +48,8 @@ def get_types(self) -> Set[Type]:
4648
def get_predicates(self) -> Set[Predicate]:
4749
"""Return the predicates introduced by this component.
4850
49-
These predicates will be added to the environment's predicate set.
51+
These predicates will be added to the environment's predicate
52+
set.
5053
"""
5154
raise NotImplementedError
5255

@@ -123,15 +126,16 @@ def extract_feature(self, obj: Object, feature: str) -> Optional[float]:
123126
def set_physics_client_id(self, physics_client_id: int) -> None:
124127
"""Set the physics client ID for this component.
125128
126-
Called by the composed environment after PyBullet initialization.
129+
Called by the composed environment after PyBullet
130+
initialization.
127131
"""
128132
self._physics_client_id = physics_client_id
129133

130134
def step(self) -> None:
131135
"""Called each simulation step.
132136
133-
Override this method to add per-step physics updates (e.g., wind forces
134-
from fans). By default, does nothing.
137+
Override this method to add per-step physics updates (e.g., wind
138+
forces from fans). By default, does nothing.
135139
"""
136140
pass
137141

predicators/envs/pybullet_domino/components/domino_component.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ def _StartBlock_holds(self, state: State,
410410
"""Check if domino is the start block (light green)."""
411411
domino, = objects
412412
eps = 1e-3
413-
return (abs(state.get(domino, "r") - self.start_domino_color[0]) < eps
414-
and abs(state.get(domino, "g") - self.start_domino_color[1]) <
415-
eps and abs(state.get(domino, "b") -
416-
self.start_domino_color[2]) < eps)
413+
return (
414+
abs(state.get(domino, "r") - self.start_domino_color[0]) < eps
415+
and abs(state.get(domino, "g") - self.start_domino_color[1]) < eps
416+
and abs(state.get(domino, "b") - self.start_domino_color[2]) < eps)
417417

418418
def _MovableBlock_holds(self, state: State,
419419
objects: Sequence[Object]) -> bool:
@@ -425,14 +425,14 @@ def _MovableBlock_holds(self, state: State,
425425
and abs(state.get(domino, "b") - self.domino_color[2]) < eps)
426426

427427
def _TargetDomino_holds(self, state: State,
428-
objects: Sequence[Object]) -> bool:
428+
objects: Sequence[Object]) -> bool:
429429
"""Check if domino is a target (pink or glued red)."""
430430
domino, = objects
431431
eps = 1e-3
432432
return (self._DominoGlued_holds(state, objects)) or (
433-
abs(state.get(domino, "r") - self.target_domino_color[0]) < eps
434-
and abs(state.get(domino, "g") - self.target_domino_color[1]) < eps
435-
and abs(state.get(domino, "b") - self.target_domino_color[2]) < eps)
433+
abs(state.get(domino, "r") - self.target_domino_color[0]) < eps and
434+
abs(state.get(domino, "g") - self.target_domino_color[1]) < eps and
435+
abs(state.get(domino, "b") - self.target_domino_color[2]) < eps)
436436

437437
def _DominoNotGlued_holds(self, state: State,
438438
objects: Sequence[Object]) -> bool:
@@ -513,7 +513,9 @@ def place_domino(self,
513513
"is_held": 0.0,
514514
}
515515

516-
def place_pivot_or_target(self, x: float, y: float,
516+
def place_pivot_or_target(self,
517+
x: float,
518+
y: float,
517519
rot: float = 0.0) -> Dict:
518520
"""Create a dictionary with placement parameters for a pivot/target."""
519521
return {
@@ -549,23 +551,23 @@ def Toppled(self) -> Predicate:
549551

550552

551553
def create_domino_block(
552-
color: Tuple[float, float, float, float],
553-
half_extents: Tuple[float, float, float],
554-
mass: float,
555-
friction: float,
556-
position: Pose3D = (0.0, 0.0, 0.0),
557-
orientation: Quaternion = (0.0, 0.0, 0.0, 1.0),
558-
physics_client_id: int = 0,
559-
add_top_triangle: bool = False,
560-
*,
561-
restitution: float = 0.02,
562-
rolling_friction: float = 0.006,
563-
spinning_friction: Optional[float] = None,
564-
linear_damping: float = 0.0,
565-
angular_damping: float = 0.03,
566-
friction_anchor: bool = True,
567-
ccd: bool = True,
568-
ccd_swept_radius: Optional[float] = None,
554+
color: Tuple[float, float, float, float],
555+
half_extents: Tuple[float, float, float],
556+
mass: float,
557+
friction: float,
558+
position: Pose3D = (0.0, 0.0, 0.0),
559+
orientation: Quaternion = (0.0, 0.0, 0.0, 1.0),
560+
physics_client_id: int = 0,
561+
add_top_triangle: bool = False,
562+
*,
563+
restitution: float = 0.02,
564+
rolling_friction: float = 0.006,
565+
spinning_friction: Optional[float] = None,
566+
linear_damping: float = 0.0,
567+
angular_damping: float = 0.03,
568+
friction_anchor: bool = True,
569+
ccd: bool = True,
570+
ccd_swept_radius: Optional[float] = None,
569571
) -> int:
570572
"""Create a domino-tuned block with appropriate physics settings."""
571573
block_id = create_pybullet_block(

predicators/envs/pybullet_domino/components/fan_component.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,8 @@ def initialize_pybullet(self, physics_client_id: int) -> Dict[str, Any]:
239239
def store_pybullet_bodies(self, pybullet_bodies: Dict[str, Any]) -> None:
240240
"""Store PyBullet body IDs on fan and switch objects."""
241241
fan_ids_by_side = [
242-
pybullet_bodies["fan_ids_left"],
243-
pybullet_bodies["fan_ids_right"],
244-
pybullet_bodies["fan_ids_back"],
245-
pybullet_bodies["fan_ids_front"]
242+
pybullet_bodies["fan_ids_left"], pybullet_bodies["fan_ids_right"],
243+
pybullet_bodies["fan_ids_back"], pybullet_bodies["fan_ids_front"]
246244
]
247245

248246
for side_idx, fan_obj in enumerate(self._fans):
@@ -487,7 +485,8 @@ def _Controls_holds(self, state: State, objects: Sequence[Object]) -> bool:
487485
# -------------------------------------------------------------------------
488486

489487
def get_init_dict_entries(
490-
self, rng: "np.random.Generator",
488+
self,
489+
rng: "np.random.Generator",
491490
all_off: bool = True) -> Dict[Object, Dict[str, Any]]:
492491
"""Return initial state dict entries for fans, switches, and sides."""
493492
init_dict: Dict[Object, Dict[str, Any]] = {}

predicators/envs/pybullet_domino/composed_env.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
import pybullet as p
1111

1212
from predicators import utils
13-
from predicators.envs.pybullet_domino.components.base_component import \
14-
DominoEnvComponent
1513
from predicators.envs.pybullet_domino.components.ball_component import \
1614
BallComponent
15+
from predicators.envs.pybullet_domino.components.base_component import \
16+
DominoEnvComponent
1717
from predicators.envs.pybullet_domino.components.domino_component import \
1818
DominoComponent
1919
from predicators.envs.pybullet_domino.components.fan_component import \
2020
FanComponent
21-
from predicators.envs.pybullet_domino.task_generators.domino_task_generator \
22-
import DominoTaskGenerator
21+
from predicators.envs.pybullet_domino.task_generators.domino_task_generator import \
22+
DominoTaskGenerator
2323
from predicators.envs.pybullet_env import PyBulletEnv
2424
from predicators.pybullet_helpers.camera import create_gui_connection
2525
from predicators.pybullet_helpers.geometry import Pose, Pose3D, Quaternion
@@ -201,9 +201,8 @@ def initialize_pybullet(
201201

202202
# Load robot
203203
robot_ee_orn = cls.get_robot_ee_home_orn()
204-
ee_home = Pose(
205-
(cls.robot_init_x, cls.robot_init_y, cls.robot_init_z),
206-
robot_ee_orn)
204+
ee_home = Pose((cls.robot_init_x, cls.robot_init_y, cls.robot_init_z),
205+
robot_ee_orn)
207206
base_pose = Pose(cls.robot_base_pos,
208207
cls.robot_base_orn) if cls.robot_base_pos else None
209208
pybullet_robot = create_single_arm_pybullet_robot(
@@ -221,14 +220,14 @@ def initialize_pybullet(
221220
physics_client_id=physics_client_id)
222221

223222
# Add second table for more space
224-
create_object(
225-
asset_path="urdf/table.urdf",
226-
position=(cls.table_pos[0], cls.table_pos[1] + cls.table_width / 2,
227-
cls.table_pos[2]),
228-
orientation=cls.table_orn,
229-
scale=1.0,
230-
use_fixed_base=True,
231-
physics_client_id=physics_client_id)
223+
create_object(asset_path="urdf/table.urdf",
224+
position=(cls.table_pos[0],
225+
cls.table_pos[1] + cls.table_width / 2,
226+
cls.table_pos[2]),
227+
orientation=cls.table_orn,
228+
scale=1.0,
229+
use_fixed_base=True,
230+
physics_client_id=physics_client_id)
232231

233232
bodies = {"table_id": table_id}
234233
return physics_client_id, pybullet_robot, bodies

predicators/envs/pybullet_domino/task_generators/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Task generators for the domino environment.
22
3-
Task generators create EnvironmentTask instances with initial states and goals.
4-
Different generators can be composed with different component combinations.
3+
Task generators create EnvironmentTask instances with initial states and
4+
goals. Different generators can be composed with different component
5+
combinations.
56
"""
67

78
from predicators.envs.pybullet_domino.task_generators.base_generator import \
89
TaskGenerator
9-
from predicators.envs.pybullet_domino.task_generators.domino_task_generator \
10-
import DominoTaskGenerator
10+
from predicators.envs.pybullet_domino.task_generators.domino_task_generator import \
11+
DominoTaskGenerator
1112

1213
__all__ = [
1314
"TaskGenerator",

0 commit comments

Comments
 (0)