Skip to content

Commit 1de547c

Browse files
authored
Merge branch 'main' into touch_object_jun25_23
2 parents 21a7aa0 + fb993bf commit 1de547c

File tree

4 files changed

+118
-12
lines changed

4 files changed

+118
-12
lines changed

src/tbp/monty/frameworks/environments/embodied_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from tbp.monty.frameworks.actions.actions import Action
1616

17-
__all__ = ["EmbodiedEnvironment", "ActionSpace"]
17+
__all__ = ["EmbodiedEnvironment", "ActionSpace", "VectorXYZ", "QuaternionWXYZ"]
1818

1919
VectorXYZ = Tuple[float, float, float]
2020
QuaternionWXYZ = Tuple[float, float, float, float]

src/tbp/monty/simulators/habitat/environment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"SingleSensorAgentArgs",
3737
]
3838

39+
from tbp.monty.simulators.simulator import Simulator
3940

4041
# Create agent and object configuration helper dataclasses
4142

@@ -116,7 +117,7 @@ def __init__(
116117
agent = agent_type(**args)
117118
self._agents.append(agent)
118119

119-
self._env = HabitatSim(
120+
self._env: Simulator = HabitatSim(
120121
agents=self._agents,
121122
scene_id=scene_id,
122123
seed=seed,
@@ -139,7 +140,7 @@ def add_object(
139140
rotation: QuaternionWXYZ = (1.0, 0.0, 0.0, 0.0),
140141
scale: VectorXYZ = (1.0, 1.0, 1.0),
141142
semantic_id: Optional[str] = None,
142-
enable_physics: Optional[bool] = False,
143+
enable_physics=False,
143144
object_to_avoid=False,
144145
primary_target_object=None,
145146
):

src/tbp/monty/simulators/habitat/simulator.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from collections import defaultdict
1818
from pathlib import Path
19-
from typing import Dict, List, Optional, Tuple
19+
from typing import Dict, List, Optional
2020

2121
import habitat_sim
2222
import magnum as mn
@@ -52,6 +52,11 @@
5252
"PRIMITIVE_OBJECT_TYPES",
5353
]
5454

55+
from tbp.monty.frameworks.environments.embodied_environment import (
56+
QuaternionWXYZ,
57+
VectorXYZ,
58+
)
59+
5560
DEFAULT_SCENE = "NONE"
5661
DEFAULT_PHYSICS_CONFIG = str(files(resources) / "default.physics_config.json")
5762

@@ -66,10 +71,6 @@
6671
}
6772

6873

69-
Vector3 = Tuple[float, float, float]
70-
Quaternion = Tuple[float, float, float, float]
71-
72-
7374
class HabitatSim(HabitatActuator):
7475
"""Habitat-sim interface for tbp.monty.
7576
@@ -211,11 +212,11 @@ def remove_all_objects(self):
211212
def add_object(
212213
self,
213214
name: str,
214-
position: Vector3 = (0.0, 0.0, 0.0),
215-
rotation: Quaternion = (1.0, 0.0, 0.0, 0.0),
216-
scale: Vector3 = (1.0, 1.0, 1.0),
215+
position: VectorXYZ = (0.0, 0.0, 0.0),
216+
rotation: QuaternionWXYZ = (1.0, 0.0, 0.0, 0.0),
217+
scale: VectorXYZ = (1.0, 1.0, 1.0),
217218
semantic_id: Optional[str] = None,
218-
enable_physics: Optional[bool] = False,
219+
enable_physics=False,
219220
object_to_avoid=False,
220221
primary_target_bb=None,
221222
):

src/tbp/monty/simulators/simulator.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright 2025 Thousand Brains Project
2+
#
3+
# Copyright may exist in Contributors' modifications
4+
# and/or contributions to the work.
5+
#
6+
# Use of this source code is governed by the MIT
7+
# license that can be found in the LICENSE file or at
8+
# https://opensource.org/licenses/MIT.
9+
from typing import Dict, List, Optional, Protocol
10+
11+
from tbp.monty.frameworks.actions.actions import Action
12+
from tbp.monty.frameworks.environments.embodied_environment import (
13+
QuaternionWXYZ,
14+
VectorXYZ,
15+
)
16+
17+
18+
class Simulator(Protocol):
19+
"""A Protocol defining a simulator for use in simulated environments.
20+
21+
A Simulator is responsible for a simulated environment that contains objects to
22+
interact with, agents to do the interacting, and for collecting observations and
23+
proprioceptive state to send to Monty.
24+
"""
25+
26+
# TODO - do we need a way to abstract the concept of "agent"?
27+
def initialize_agent(self, agent_id, agent_state):
28+
"""Update agent runtime state."""
29+
...
30+
31+
def remove_all_objects(self):
32+
"""Remove all objects from the simulated environment."""
33+
...
34+
35+
def add_object(
36+
self,
37+
name: str,
38+
position: VectorXYZ = (0.0, 0.0, 0.0),
39+
rotation: QuaternionWXYZ = (1.0, 0.0, 0.0, 0.0),
40+
scale: VectorXYZ = (1.0, 1.0, 1.0),
41+
semantic_id: Optional[str] = None,
42+
enable_physics=False,
43+
object_to_avoid=False,
44+
primary_target_bb: Optional[List] = None,
45+
) -> None:
46+
"""Add new object to simulated environment.
47+
48+
Adds a new object based on the named object. This assumes that the set of
49+
available objects are preloaded and keyed by name.
50+
51+
Args:
52+
name (str): Registered object name
53+
position (VectorXYZ): Initial absolute position of the object
54+
rotation (QuaternionWXYZ): Initial orientation of the object
55+
scale (VectorXYZ): Initial object scale
56+
semantic_id (Optional[str]): Optional override object semantic ID
57+
enable_physics (bool): Whether to enable physics on the object
58+
object_to_avoid (bool): If True, ensure the object is not colliding with
59+
other objects
60+
primary_target_bb (List | None): If not None, this is a list of the min and
61+
max corners of a bounding box for the primary object, used to prevent
62+
obscuring the primary objet with the new object.
63+
"""
64+
...
65+
66+
# TODO - change getters to properties using @property
67+
def get_num_objects(self) -> int:
68+
"""Return the number of instantiated objects in the environment."""
69+
...
70+
71+
def get_action_space(self):
72+
"""Returns the set of all available actions."""
73+
...
74+
75+
def get_agent(self, agent_id):
76+
"""Return agent instance."""
77+
...
78+
79+
def get_observations(self):
80+
"""Get sensor observations."""
81+
...
82+
83+
def get_states(self):
84+
"""Get agent and sensor states."""
85+
...
86+
87+
def apply_action(self, action: Action) -> Dict[str, Dict]:
88+
"""Execute the given action in the environment.
89+
90+
Args:
91+
action (Action): the action to execute
92+
93+
Returns:
94+
(Dict[str, Dict]): A dictionary with the observations grouped by agent_id
95+
"""
96+
...
97+
98+
def reset(self):
99+
"""Reset the simulator."""
100+
...
101+
102+
def close(self):
103+
"""Close any resources used by the simulator."""
104+
...

0 commit comments

Comments
 (0)