File size: 1,533 Bytes
f9cf739
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
class ObjectGroup:
    """
    An abstraction that encompasses a group of objects that interact together in a meaningful way
    name (str): Name of this object group. This will be prepended to all objects generated by this group.
    """

    def __init__(self, name):
        # Store internal variables
        self.name = name
        self.sim = None  # Reference to shared mjsim object
        self._objects = {}  # maps object names to object class instances

        # Generate objects
        self._generate_objects()

    def get_states(self):
        """
        Function to grab group-relevant states. This should be implemented by the subclass.
        Returns:
            dict: Keyword-mapped states for this group
        """
        raise NotImplementedError

    def update_sim(self, sim):
        """
        Updates internal reference to sim and all other relevant references
        Args:
            sim (MjSim): Active mujoco sim reference
        """
        self.sim = sim

    def _generate_objects(self):
        """
        Internal helper function that generates the objects for this group. Should populate self._objects mapping
        names of objects to their actual object class instances.
        """
        raise NotImplementedError

    @property
    def objects(self):
        """
        Contains references to all objects owned by this group. Mapped from names to object instances
        Returns:
            dict: keyword-mapped object class instances
        """
        return self._objects