Skip to content

entity

Entity

Docstring for Entity Entity class for dynamically spawning world objects via /world/{competition}/create service

Source code in controls/sae_2025_ws/src/sim/sim/world_gen/entity.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Entity:
    """
    Docstring for Entity
    Entity class for dynamically spawning world objects via /world/{competition}/create service
    """

    def __init__(
        self,
        name: str,
        path_to_sdf: str,
        position: tuple[float, float, float],
        rpy: tuple[float, float, float],
        world: str,
    ):
        self.name = name
        self.path_to_sdf = os.path.expanduser(path_to_sdf)
        self.position = position
        self.rpy = rpy
        self.world = world

    def to_entity_factory_msg(self):
        pose = Pose()
        pose.position.x = float(self.position[0])
        pose.position.y = float(self.position[1])
        pose.position.z = float(self.position[2])
        q = quaternion_from_euler(self.rpy[0], self.rpy[1], self.rpy[2])
        pose.orientation.x = float(q[0])
        pose.orientation.y = float(q[1])
        pose.orientation.z = float(q[2])
        pose.orientation.w = float(q[3])

        ent_fact = EntityFactory()
        ent_fact.name = self.name
        ent_fact.sdf_filename = self.path_to_sdf
        ent_fact.pose = pose
        ent_fact.relative_to = self.world
        return ent_fact

    def to_pose(self):
        return self.position + self.rpy  # (x, y, z, r, p, y)