|
| 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