robosim.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 HasTypeAndArgs(Component):
 15    _type: np.ndarray = field(metadata={
 16        "shape": (1, ), "dtype": "object", "serializable": True,
 17        "default": None,
 18        "comment": "Part of HasTypeAndArgs. Used to construct the entity"})
 19    _args: np.ndarray = field(metadata={
 20        "shape": (1, ), "dtype": "object", "serializable": True,
 21        "default": None,
 22        "comment": "Part of HasTypeAndArgs. Used to construct the entity"})
 23
 24class HasModel(Component):
 25    model: np.ndarray = field(metadata={
 26        "shape": (1, ), "dtype": "object", "serializable": False,
 27        "default": None,
 28        "comment": "The model object (not serializable)"})
 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_bbox: np.ndarray = field(metadata={
 34        "shape": (2, 3), "dtype": "float32", "serializable": False,
 35        "default": np.zeros((2, 3), "float32"),
 36        "comment": "The bbox of the object dertived from the model itself"})
 37    model_radius: np.ndarray = field(metadata={
 38        "shape": (1, ), "dtype": "float32", "serializable": False,
 39        "default": np.zeros((1, ), "float32"),
 40        "comment": "The radius of the model, derived from the model itself"})
 41
 42# State/Motion-related components
 43
 44class HasPose(Component):
 45    pose: np.ndarray = field(metadata={
 46        "shape": (4, 4), "dtype": "float32", "serializable": True,
 47        "default": np.eye(4, dtype="float32"),
 48        "comment": "The pose of the entity (rotation & translation) as 4x4 homogeneous matrix"})
 49    candidate_pose: np.ndarray = field(metadata={
 50        "shape": (4, 4), "dtype": "float32", "serializable": True,
 51        "default": np.eye(4, dtype="float32"),
 52        "comment": "The future (t+1) 4x4 pose. Used for post-collision"})
 53
 54class HasVelocity6DoF(Component):
 55    velocity: np.ndarray = field(metadata={
 56        "shape": (6, ), "dtype": "float32", "serializable": True,
 57        "default": np.zeros((6, ), "float32"),
 58        "comment": "The velocity of an entity"})
 59    candidate_velocity: np.ndarray = field(metadata={
 60        "shape": (6, ), "dtype": "float32", "serializable": True,
 61        "default": np.zeros((6, ), "float32"),
 62        "comment": "The future (t+1) velocity. Used for post-collision"})
 63
 64class HasAcceleration6DoF(Component):
 65    acceleration: np.ndarray = field(metadata={
 66        "shape": (6, ), "dtype": "float32", "serializable": True,
 67        "default": np.zeros((6, ), "float32"),
 68        "comment": "The acceleration of an entity"})
 69    candidate_acceleration: np.ndarray = field(metadata={
 70        "shape": (6, ), "dtype": "float32", "serializable": True,
 71        "default": np.zeros((6, ), "float32"),
 72        "comment": "The future (t+1) acceleration. Used for post-collision"})
 73
 74# network or dynamic objects
 75
 76class HasFPV(Component):
 77    fpv_camera: np.ndarray = field(metadata={
 78        "shape": (1, ), "dtype": "object", "serializable": False,
 79        "default": None,
 80        "comment": "The FPV camera object, instantiated in the server."})
 81    fpv_data: np.ndarray = field(metadata={
 82        "shape": (1, ), "dtype": "object", "serializable": False,
 83        "default": None,
 84        "comment": "The frame currently displayed in the world in this FPV camera."})
 85    fpv_texture: np.ndarray = field(metadata={
 86        "shape": (1, ), "dtype": "object", "serializable": False,
 87        "default": None,
 88        "comment": "The texture where the fpv_data of this camera is rendered"})
 89
 90class HasChannel(Component):
 91    channel: np.ndarray = field(metadata={
 92        "shape": (1, ), "dtype": "object", "serializable": False,
 93        "default": None,
 94        "comment": ("The channel object (1 socket + 2 queues) through which external "
 95                    "servies commnunicate with an entity")})
 96
 97# physics
 98
 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)")})
105
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"})
111
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"})
121
122class ColliderKinds(IntEnum):
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": False,
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
144ROBOSIM_COMPONENTS = [HasModel, HasPose, HasFPV, HasChannel, HasTypeAndArgs,                          # model/object
145                      HasVelocity6DoF, HasAcceleration6DoF, HasPhysicsLevel1,                          # physics
146                        HasPhysicsLevel2, HasMotionInput,
147                      HasCollision]                                                                    # collision
class HasTypeAndArgs(microecs.component.Component):
15class HasTypeAndArgs(Component):
16    _type: np.ndarray = field(metadata={
17        "shape": (1, ), "dtype": "object", "serializable": True,
18        "default": None,
19        "comment": "Part of HasTypeAndArgs. Used to construct the entity"})
20    _args: np.ndarray = field(metadata={
21        "shape": (1, ), "dtype": "object", "serializable": True,
22        "default": None,
23        "comment": "Part of HasTypeAndArgs. Used to construct the entity"})
HasTypeAndArgs(*, _type: numpy.ndarray, _args: numpy.ndarray)
class HasModel(microecs.component.Component):
25class HasModel(Component):
26    model: np.ndarray = field(metadata={
27        "shape": (1, ), "dtype": "object", "serializable": False,
28        "default": None,
29        "comment": "The model object (not serializable)"})
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_bbox: np.ndarray = field(metadata={
35        "shape": (2, 3), "dtype": "float32", "serializable": False,
36        "default": np.zeros((2, 3), "float32"),
37        "comment": "The bbox of the object dertived from the model itself"})
38    model_radius: np.ndarray = field(metadata={
39        "shape": (1, ), "dtype": "float32", "serializable": False,
40        "default": np.zeros((1, ), "float32"),
41        "comment": "The radius of the model, derived from the model itself"})
HasModel( *, model: numpy.ndarray, scale: numpy.ndarray, model_bbox: numpy.ndarray, model_radius: numpy.ndarray)
model: numpy.ndarray
scale: numpy.ndarray
model_bbox: numpy.ndarray
model_radius: numpy.ndarray
class HasPose(microecs.component.Component):
45class HasPose(Component):
46    pose: np.ndarray = field(metadata={
47        "shape": (4, 4), "dtype": "float32", "serializable": True,
48        "default": np.eye(4, dtype="float32"),
49        "comment": "The pose of the entity (rotation & translation) as 4x4 homogeneous matrix"})
50    candidate_pose: np.ndarray = field(metadata={
51        "shape": (4, 4), "dtype": "float32", "serializable": True,
52        "default": np.eye(4, dtype="float32"),
53        "comment": "The future (t+1) 4x4 pose. Used for post-collision"})
HasPose(*, pose: numpy.ndarray, candidate_pose: numpy.ndarray)
pose: numpy.ndarray
candidate_pose: numpy.ndarray
class HasVelocity6DoF(microecs.component.Component):
55class HasVelocity6DoF(Component):
56    velocity: np.ndarray = field(metadata={
57        "shape": (6, ), "dtype": "float32", "serializable": True,
58        "default": np.zeros((6, ), "float32"),
59        "comment": "The velocity of an entity"})
60    candidate_velocity: np.ndarray = field(metadata={
61        "shape": (6, ), "dtype": "float32", "serializable": True,
62        "default": np.zeros((6, ), "float32"),
63        "comment": "The future (t+1) velocity. Used for post-collision"})
HasVelocity6DoF(*, velocity: numpy.ndarray, candidate_velocity: numpy.ndarray)
velocity: numpy.ndarray
candidate_velocity: numpy.ndarray
class HasAcceleration6DoF(microecs.component.Component):
65class HasAcceleration6DoF(Component):
66    acceleration: np.ndarray = field(metadata={
67        "shape": (6, ), "dtype": "float32", "serializable": True,
68        "default": np.zeros((6, ), "float32"),
69        "comment": "The acceleration of an entity"})
70    candidate_acceleration: np.ndarray = field(metadata={
71        "shape": (6, ), "dtype": "float32", "serializable": True,
72        "default": np.zeros((6, ), "float32"),
73        "comment": "The future (t+1) acceleration. Used for post-collision"})
HasAcceleration6DoF( *, acceleration: numpy.ndarray, candidate_acceleration: numpy.ndarray)
acceleration: numpy.ndarray
candidate_acceleration: numpy.ndarray
class HasFPV(microecs.component.Component):
77class HasFPV(Component):
78    fpv_camera: np.ndarray = field(metadata={
79        "shape": (1, ), "dtype": "object", "serializable": False,
80        "default": None,
81        "comment": "The FPV camera object, instantiated in the server."})
82    fpv_data: np.ndarray = field(metadata={
83        "shape": (1, ), "dtype": "object", "serializable": False,
84        "default": None,
85        "comment": "The frame currently displayed in the world in this FPV camera."})
86    fpv_texture: np.ndarray = field(metadata={
87        "shape": (1, ), "dtype": "object", "serializable": False,
88        "default": None,
89        "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 HasChannel(microecs.component.Component):
91class HasChannel(Component):
92    channel: np.ndarray = field(metadata={
93        "shape": (1, ), "dtype": "object", "serializable": False,
94        "default": None,
95        "comment": ("The channel object (1 socket + 2 queues) through which external "
96                    "servies commnunicate with an entity")})
HasChannel(*, channel: numpy.ndarray)
channel: numpy.ndarray
class HasMotionInput(microecs.component.Component):
100class HasMotionInput(Component):
101    motion_input: np.ndarray = field(metadata={
102        "shape": (6, ), "dtype": "float32", "serializable": False,
103        "default": np.zeros((6, ), "float32"),
104        "comment": ("The motion input (to change vel/acc) of this entity. "
105                    "Usually sent from keyboard or the entity's channel (tcp)")})
HasMotionInput(*, motion_input: numpy.ndarray)
motion_input: numpy.ndarray
class HasPhysicsLevel1(microecs.component.Component):
107class HasPhysicsLevel1(Component):
108    max_velocities: np.ndarray = field(metadata={
109        "shape": (6, ), "dtype": "float32", "serializable": True,
110        "default": None,
111        "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):
113class HasPhysicsLevel2(Component):
114    max_accelerations: np.ndarray = field(metadata={
115        "shape": (6, ), "dtype": "float32", "serializable": True,
116        "default": None,
117        "comment": "The maximum acc. in the monion_input for lvl 2"})
118    drag_coefficient: np.ndarray = field(metadata={
119        "shape": (1, ), "dtype": "float32", "serializable": True,
120        "default": None,
121        "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):
123class ColliderKinds(IntEnum):
124    SPHERE = 1
125    AABB = 2
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": False,
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
ROBOSIM_COMPONENTS = [<class 'HasModel'>, <class 'HasPose'>, <class 'HasFPV'>, <class 'HasChannel'>, <class 'HasTypeAndArgs'>, <class 'HasVelocity6DoF'>, <class 'HasAcceleration6DoF'>, <class 'HasPhysicsLevel1'>, <class 'HasPhysicsLevel2'>, <class 'HasMotionInput'>, <class 'HasCollision'>]