robolib.components

components.py - The basic componens that the simulator supports. New custom ones can be added in server or plugins. Import level: 1

  1"""
  2components.py - The basic componens that the simulator supports. New custom ones can be added in server or plugins.
  3Import level: 1
  4"""
  5# pylint: disable=missing-class-docstring
  6
  7from enum import IntEnum
  8from dataclasses import field
  9from microecs import Component
 10import numpy as np
 11
 12# components (data only)
 13
 14class HasTag(Component):
 15    tag: np.ndarray = field(metadata={
 16        "shape": (1, ), "dtype": "object", "serializable": True,
 17        "default": None,
 18        "comment": "The tag of this entity (e.g. robot, ground floor etc.)"})
 19
 20class HasModel(Component):
 21    model_path: np.ndarray = field(metadata={
 22        "shape": (1, ), "dtype": "object", "serializable": True,
 23        "default": None,
 24        "comment": "The model path on the disk"})
 25    texture_path: np.ndarray = field(metadata={
 26        "shape": (1, ), "dtype": "object", "serializable": True,
 27        "default": None,
 28        "comment": "The texture path on the disk (optional)"})
 29    scale: np.ndarray = field(metadata={
 30        "shape": (1, ), "dtype": "float32", "serializable": True,
 31        "default": None,
 32        "comment": "The scale of the model to project in world space"})
 33    model: np.ndarray = field(metadata={
 34        "shape": (1, ), "dtype": "object", "serializable": False,
 35        "default": None,
 36        "comment": "The model object (not serializable)"})
 37    model_bbox: np.ndarray = field(metadata={
 38        "shape": (2, 3), "dtype": "float32", "serializable": False,
 39        "default": np.zeros((2, 3), "float32"),
 40        "comment": "The bbox of the object dertived from the model itself"})
 41    model_radius: np.ndarray = field(metadata={
 42        "shape": (1, ), "dtype": "float32", "serializable": False,
 43        "default": np.zeros((1, ), "float32"),
 44        "comment": "The radius of the model, derived from the model itself"})
 45
 46# State/Motion-related components
 47
 48class HasPose(Component):
 49    pose: np.ndarray = field(metadata={
 50        "shape": (4, 4), "dtype": "float32", "serializable": True,
 51        "default": np.eye(4, dtype="float32"),
 52        "comment": "The pose of the entity (rotation & translation) as 4x4 homogeneous matrix"})
 53    candidate_pose: np.ndarray = field(metadata={
 54        "shape": (4, 4), "dtype": "float32", "serializable": False,
 55        "default": None,
 56        "comment": "The future (t+1) 4x4 pose. Used for post-collision. Needs to be updated at each frame (system)."})
 57
 58class HasVelocity(Component):
 59    velocity: np.ndarray = field(metadata={
 60        "shape": (6, ), "dtype": "float32", "serializable": True,
 61        "default": np.zeros((6, ), "float32"),
 62        "comment": ("The velocity of an entity. We use 6 degrees of freedom (6DoF): (vx, vy, vz, wx, wy, wz). "
 63                    "The first three numbers are the linear velocities and the last three are angular velocities.")})
 64    candidate_velocity: np.ndarray = field(metadata={
 65        "shape": (6, ), "dtype": "float32", "serializable": True,
 66        "default": np.zeros((6, ), "float32"),
 67        "comment": "The future (t+1) velocity. Used for collision checking in the phsyics system before updating pose"})
 68
 69class HasAcceleration(Component):
 70    acceleration: np.ndarray = field(metadata={
 71        "shape": (6, ), "dtype": "float32", "serializable": True,
 72        "default": np.zeros((6, ), "float32"),
 73        "comment": ("The acceleration of an entity. We use 6 degrees of freedom (6DoF): (ax, ay, az, wax, way, waz). "
 74                    "The first three numbers are the linear accelerations and the last three are angular accels.")})
 75    candidate_acceleration: np.ndarray = field(metadata={
 76        "shape": (6, ), "dtype": "float32", "serializable": True,
 77        "default": np.zeros((6, ), "float32"),
 78        "comment": "The future (t+1) accel. Used for collision checking in the phsyics system before updating pose"})
 79
 80# network or dynamic objects
 81
 82class HasFPV(Component):
 83    fpv_camera: np.ndarray = field(metadata={
 84        "shape": (1, ), "dtype": "object", "serializable": False,
 85        "default": None,
 86        "comment": "The FPV camera object, instantiated in the server."})
 87    fpv_data: np.ndarray = field(metadata={
 88        "shape": (1, ), "dtype": "object", "serializable": False,
 89        "default": None,
 90        "comment": "The frame currently displayed in the world in this FPV camera."})
 91    fpv_texture: np.ndarray = field(metadata={
 92        "shape": (1, ), "dtype": "object", "serializable": False,
 93        "default": None,
 94        "comment": "The texture where the fpv_data of this camera is rendered"})
 95
 96# physics
 97
 98class HasMotionInput(Component):
 99    motion_input: np.ndarray = field(metadata={
100        "shape": (6, ), "dtype": "float32", "serializable": False,
101        "default": np.zeros((6, ), "float32"),
102        "comment": ("The motion input (to change vel/acc) of this entity. "
103                    "Usually sent from keyboard or the entity's channel (tcp)")})
104
105class HasPhysicsLevel1(Component):
106    max_velocities: np.ndarray = field(metadata={
107        "shape": (6, ), "dtype": "float32", "serializable": True,
108        "default": None,
109        "comment": "The maximum velocities in the monion_input for lvl 2"})
110
111class HasPhysicsLevel2(Component):
112    max_accelerations: np.ndarray = field(metadata={
113        "shape": (6, ), "dtype": "float32", "serializable": True,
114        "default": None,
115        "comment": "The maximum acc. in the monion_input for lvl 2"})
116    drag_coefficient: np.ndarray = field(metadata={
117        "shape": (1, ), "dtype": "float32", "serializable": True,
118        "default": None,
119        "comment": "The drag coefficient for level 2"})
120
121class ColliderKinds(IntEnum):
122    """The types of colliders. Used by HasCollision components. Keep as IntEnum for faster narrowphase"""
123    SPHERE = 1
124    AABB = 2
125
126class HasCollision(Component):
127    is_colliding: np.ndarray = field(metadata={
128        "shape": (1, ), "dtype": "bool", "serializable": False,
129        "default": np.zeros((1, ), "bool"),
130        "comment": "Whether this entity is colliding now with something"})
131    collider_kind: np.ndarray = field(metadata={
132        "shape": (1, ), "dtype": "int32", "serializable": True,
133        "default": None,
134        "comment": "The collider kind. see ColliderKinds enum for options."})
135    collider_bbox: np.ndarray = field(metadata={
136        "shape": (2, 3), "dtype": "float32", "serializable": False,
137        "default": np.zeros((2, 3), "float32"),
138        "comment": "Note: already in world space (scaled) by physics system"})
139    collider_radii: np.ndarray = field(metadata={
140        "shape": (1, ), "dtype": "float32", "serializable": False,
141        "default": np.zeros((1, ), "float32"),
142        "comment": "Note: already in world space (scaled) by physics system"})
143
144ROBOLIB_COMPONENTS = [HasTag, HasModel, HasPose, HasFPV,                   # model/object
145                      HasVelocity, HasAcceleration, HasPhysicsLevel1,      # physics
146                        HasPhysicsLevel2, HasMotionInput,
147                      HasCollision]                                        # collision
class HasTag(microecs.component.Component):
15class HasTag(Component):
16    tag: np.ndarray = field(metadata={
17        "shape": (1, ), "dtype": "object", "serializable": True,
18        "default": None,
19        "comment": "The tag of this entity (e.g. robot, ground floor etc.)"})
HasTag(*, tag: numpy.ndarray)
tag: numpy.ndarray
class HasModel(microecs.component.Component):
21class HasModel(Component):
22    model_path: np.ndarray = field(metadata={
23        "shape": (1, ), "dtype": "object", "serializable": True,
24        "default": None,
25        "comment": "The model path on the disk"})
26    texture_path: np.ndarray = field(metadata={
27        "shape": (1, ), "dtype": "object", "serializable": True,
28        "default": None,
29        "comment": "The texture path on the disk (optional)"})
30    scale: np.ndarray = field(metadata={
31        "shape": (1, ), "dtype": "float32", "serializable": True,
32        "default": None,
33        "comment": "The scale of the model to project in world space"})
34    model: np.ndarray = field(metadata={
35        "shape": (1, ), "dtype": "object", "serializable": False,
36        "default": None,
37        "comment": "The model object (not serializable)"})
38    model_bbox: np.ndarray = field(metadata={
39        "shape": (2, 3), "dtype": "float32", "serializable": False,
40        "default": np.zeros((2, 3), "float32"),
41        "comment": "The bbox of the object dertived from the model itself"})
42    model_radius: np.ndarray = field(metadata={
43        "shape": (1, ), "dtype": "float32", "serializable": False,
44        "default": np.zeros((1, ), "float32"),
45        "comment": "The radius of the model, derived from the model itself"})
HasModel( *, model_path: numpy.ndarray, texture_path: numpy.ndarray, scale: numpy.ndarray, model: numpy.ndarray, model_bbox: numpy.ndarray, model_radius: numpy.ndarray)
model_path: numpy.ndarray
texture_path: numpy.ndarray
scale: numpy.ndarray
model: numpy.ndarray
model_bbox: numpy.ndarray
model_radius: numpy.ndarray
class HasPose(microecs.component.Component):
49class HasPose(Component):
50    pose: np.ndarray = field(metadata={
51        "shape": (4, 4), "dtype": "float32", "serializable": True,
52        "default": np.eye(4, dtype="float32"),
53        "comment": "The pose of the entity (rotation & translation) as 4x4 homogeneous matrix"})
54    candidate_pose: np.ndarray = field(metadata={
55        "shape": (4, 4), "dtype": "float32", "serializable": False,
56        "default": None,
57        "comment": "The future (t+1) 4x4 pose. Used for post-collision. Needs to be updated at each frame (system)."})
HasPose(*, pose: numpy.ndarray, candidate_pose: numpy.ndarray)
pose: numpy.ndarray
candidate_pose: numpy.ndarray
class HasVelocity(microecs.component.Component):
59class HasVelocity(Component):
60    velocity: np.ndarray = field(metadata={
61        "shape": (6, ), "dtype": "float32", "serializable": True,
62        "default": np.zeros((6, ), "float32"),
63        "comment": ("The velocity of an entity. We use 6 degrees of freedom (6DoF): (vx, vy, vz, wx, wy, wz). "
64                    "The first three numbers are the linear velocities and the last three are angular velocities.")})
65    candidate_velocity: np.ndarray = field(metadata={
66        "shape": (6, ), "dtype": "float32", "serializable": True,
67        "default": np.zeros((6, ), "float32"),
68        "comment": "The future (t+1) velocity. Used for collision checking in the phsyics system before updating pose"})
HasVelocity(*, velocity: numpy.ndarray, candidate_velocity: numpy.ndarray)
velocity: numpy.ndarray
candidate_velocity: numpy.ndarray
class HasAcceleration(microecs.component.Component):
70class HasAcceleration(Component):
71    acceleration: np.ndarray = field(metadata={
72        "shape": (6, ), "dtype": "float32", "serializable": True,
73        "default": np.zeros((6, ), "float32"),
74        "comment": ("The acceleration of an entity. We use 6 degrees of freedom (6DoF): (ax, ay, az, wax, way, waz). "
75                    "The first three numbers are the linear accelerations and the last three are angular accels.")})
76    candidate_acceleration: np.ndarray = field(metadata={
77        "shape": (6, ), "dtype": "float32", "serializable": True,
78        "default": np.zeros((6, ), "float32"),
79        "comment": "The future (t+1) accel. Used for collision checking in the phsyics system before updating pose"})
HasAcceleration( *, acceleration: numpy.ndarray, candidate_acceleration: numpy.ndarray)
acceleration: numpy.ndarray
candidate_acceleration: numpy.ndarray
class HasFPV(microecs.component.Component):
83class HasFPV(Component):
84    fpv_camera: np.ndarray = field(metadata={
85        "shape": (1, ), "dtype": "object", "serializable": False,
86        "default": None,
87        "comment": "The FPV camera object, instantiated in the server."})
88    fpv_data: np.ndarray = field(metadata={
89        "shape": (1, ), "dtype": "object", "serializable": False,
90        "default": None,
91        "comment": "The frame currently displayed in the world in this FPV camera."})
92    fpv_texture: np.ndarray = field(metadata={
93        "shape": (1, ), "dtype": "object", "serializable": False,
94        "default": None,
95        "comment": "The texture where the fpv_data of this camera is rendered"})
HasFPV( *, fpv_camera: numpy.ndarray, fpv_data: numpy.ndarray, fpv_texture: numpy.ndarray)
fpv_camera: numpy.ndarray
fpv_data: numpy.ndarray
fpv_texture: numpy.ndarray
class HasMotionInput(microecs.component.Component):
 99class HasMotionInput(Component):
100    motion_input: np.ndarray = field(metadata={
101        "shape": (6, ), "dtype": "float32", "serializable": False,
102        "default": np.zeros((6, ), "float32"),
103        "comment": ("The motion input (to change vel/acc) of this entity. "
104                    "Usually sent from keyboard or the entity's channel (tcp)")})
HasMotionInput(*, motion_input: numpy.ndarray)
motion_input: numpy.ndarray
class HasPhysicsLevel1(microecs.component.Component):
106class HasPhysicsLevel1(Component):
107    max_velocities: np.ndarray = field(metadata={
108        "shape": (6, ), "dtype": "float32", "serializable": True,
109        "default": None,
110        "comment": "The maximum velocities in the monion_input for lvl 2"})
HasPhysicsLevel1(*, max_velocities: numpy.ndarray)
max_velocities: numpy.ndarray
class HasPhysicsLevel2(microecs.component.Component):
112class HasPhysicsLevel2(Component):
113    max_accelerations: np.ndarray = field(metadata={
114        "shape": (6, ), "dtype": "float32", "serializable": True,
115        "default": None,
116        "comment": "The maximum acc. in the monion_input for lvl 2"})
117    drag_coefficient: np.ndarray = field(metadata={
118        "shape": (1, ), "dtype": "float32", "serializable": True,
119        "default": None,
120        "comment": "The drag coefficient for level 2"})
HasPhysicsLevel2(*, max_accelerations: numpy.ndarray, drag_coefficient: numpy.ndarray)
max_accelerations: numpy.ndarray
drag_coefficient: numpy.ndarray
class ColliderKinds(enum.IntEnum):
122class ColliderKinds(IntEnum):
123    """The types of colliders. Used by HasCollision components. Keep as IntEnum for faster narrowphase"""
124    SPHERE = 1
125    AABB = 2

The types of colliders. Used by HasCollision components. Keep as IntEnum for faster narrowphase

SPHERE = <ColliderKinds.SPHERE: 1>
AABB = <ColliderKinds.AABB: 2>
class HasCollision(microecs.component.Component):
127class HasCollision(Component):
128    is_colliding: np.ndarray = field(metadata={
129        "shape": (1, ), "dtype": "bool", "serializable": False,
130        "default": np.zeros((1, ), "bool"),
131        "comment": "Whether this entity is colliding now with something"})
132    collider_kind: np.ndarray = field(metadata={
133        "shape": (1, ), "dtype": "int32", "serializable": True,
134        "default": None,
135        "comment": "The collider kind. see ColliderKinds enum for options."})
136    collider_bbox: np.ndarray = field(metadata={
137        "shape": (2, 3), "dtype": "float32", "serializable": False,
138        "default": np.zeros((2, 3), "float32"),
139        "comment": "Note: already in world space (scaled) by physics system"})
140    collider_radii: np.ndarray = field(metadata={
141        "shape": (1, ), "dtype": "float32", "serializable": False,
142        "default": np.zeros((1, ), "float32"),
143        "comment": "Note: already in world space (scaled) by physics system"})
HasCollision( *, is_colliding: numpy.ndarray, collider_kind: numpy.ndarray, collider_bbox: numpy.ndarray, collider_radii: numpy.ndarray)
is_colliding: numpy.ndarray
collider_kind: numpy.ndarray
collider_bbox: numpy.ndarray
collider_radii: numpy.ndarray
ROBOLIB_COMPONENTS = [<class 'HasTag'>, <class 'HasModel'>, <class 'HasPose'>, <class 'HasFPV'>, <class 'HasVelocity'>, <class 'HasAcceleration'>, <class 'HasPhysicsLevel1'>, <class 'HasPhysicsLevel2'>, <class 'HasMotionInput'>, <class 'HasCollision'>]