aemulus 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aemulus-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: aemulus
3
+ Version: 0.0.1
4
+ Summary: A digital twin for lab automation (early work in progress)
5
+ Author: Artur Galstyan
6
+ Author-email: Artur Galstyan <63471891+Artur-Galstyan@users.noreply.github.com>
7
+ License-Expression: Apache-2.0
8
+ Requires-Dist: connectrpc>=0.13.0
9
+ Requires-Dist: hypercorn>=0.18.0
10
+ Requires-Dist: loguru>=0.8.0
11
+ Requires-Dist: protobuf-py>=0.7.0
12
+ Requires-Dist: typed-mujoco
13
+ Requires-Python: >=3.15
14
+ Description-Content-Type: text/markdown
15
+
16
+ # aemulus
17
+
18
+ A digital twin for lab automation. Write a lab protocol in Python, run it against a
19
+ simulated lab in MuJoCo, then run the same protocol against the real devices.
20
+
21
+ **Status:** early work in progress. Version 0.0.1 holds the package names and is not usable yet.
22
+
23
+ ## Layout
24
+
25
+ - `python/aemulus/`: the Python package (user API, MuJoCo simulation, device models)
26
+ - `crates/`: the Rust device servers
27
+ - `proto/`: the Protobuf contracts, shared by Python and Rust
28
+
29
+ ## Development
30
+
31
+ ```bash
32
+ task setup # install the code generator plugins
33
+ task gen # generate Python and Rust code from proto/
34
+ ```
35
+
36
+ ## License
37
+
38
+ Apache-2.0
@@ -0,0 +1,23 @@
1
+ # aemulus
2
+
3
+ A digital twin for lab automation. Write a lab protocol in Python, run it against a
4
+ simulated lab in MuJoCo, then run the same protocol against the real devices.
5
+
6
+ **Status:** early work in progress. Version 0.0.1 holds the package names and is not usable yet.
7
+
8
+ ## Layout
9
+
10
+ - `python/aemulus/`: the Python package (user API, MuJoCo simulation, device models)
11
+ - `crates/`: the Rust device servers
12
+ - `proto/`: the Protobuf contracts, shared by Python and Rust
13
+
14
+ ## Development
15
+
16
+ ```bash
17
+ task setup # install the code generator plugins
18
+ task gen # generate Python and Rust code from proto/
19
+ ```
20
+
21
+ ## License
22
+
23
+ Apache-2.0
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "aemulus"
3
+ version = "0.0.1"
4
+ description = "A digital twin for lab automation (early work in progress)"
5
+ license = "Apache-2.0"
6
+ readme = "README.md"
7
+ requires-python = ">=3.15"
8
+ dependencies = [
9
+ "connectrpc>=0.13.0",
10
+ "hypercorn>=0.18.0",
11
+ "loguru>=0.8.0",
12
+ "protobuf-py>=0.7.0",
13
+ "typed-mujoco",
14
+ ]
15
+
16
+ [[project.authors]]
17
+ name = "Artur Galstyan"
18
+ email = "63471891+Artur-Galstyan@users.noreply.github.com"
19
+
20
+ [build-system]
21
+ requires = ["uv_build>=0.13.0,<0.14.0"]
22
+ build-backend = "uv_build"
23
+
24
+ [tool.uv.build-backend]
25
+ module-root = "python"
26
+
27
+ [dependency-groups]
28
+ dev = [
29
+ "buf-bin>=1.75.0",
30
+ "protoc-gen-connectrpc>=0.13.0",
31
+ "protoc-gen-py>=0.7.0",
32
+ ]
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = "aemulus"
3
+ version = "0.0.1"
4
+ description = "A digital twin for lab automation (early work in progress)"
5
+ license = "Apache-2.0"
6
+ readme = "README.md"
7
+ authors = [
8
+ { name = "Artur Galstyan", email = "63471891+Artur-Galstyan@users.noreply.github.com" }
9
+ ]
10
+ requires-python = ">=3.15"
11
+ dependencies = [
12
+ "connectrpc>=0.13.0",
13
+ "hypercorn>=0.18.0",
14
+ "loguru>=0.8.0",
15
+ "protobuf-py>=0.7.0",
16
+ "typed-mujoco",
17
+ ]
18
+
19
+ [build-system]
20
+ requires = ["uv_build>=0.13.0,<0.14.0"]
21
+ build-backend = "uv_build"
22
+
23
+ [tool.uv.build-backend]
24
+ module-root = "python"
25
+
26
+ [dependency-groups]
27
+ dev = [
28
+ "buf-bin>=1.75.0",
29
+ "protoc-gen-connectrpc>=0.13.0",
30
+ "protoc-gen-py>=0.7.0",
31
+ ]
@@ -0,0 +1,2 @@
1
+ def hello() -> str:
2
+ return "Hello from aemulus!"
@@ -0,0 +1,95 @@
1
+ <!-- PF400, standard reach, 400 mm Z, no rail.
2
+ Dimensions and joint ranges are from the Brooks datasheet 661423 Rev A:
3
+ base 235 x 201 mm, robot height 679 mm, inner link 225 mm, gripper 134 mm wide,
4
+ finger gap 80 to 140 mm, gripper bottom 39 mm above the base at the low end of Z.
5
+ The outer link (210 mm) is calculated from the 500.8 mm reach.
6
+ Origin: center of the base footprint, on the mount surface. +x is FRONT.
7
+ Meshes: scripts/pf400_meshes.py makes them. Each mesh is convex, so it is also the collision shape.
8
+ Masses and link cross-sections are estimates, not vendor CAD values. -->
9
+ <mujoco model="pf400">
10
+ <compiler angle="degree" autolimits="true" meshdir="meshes"/>
11
+
12
+ <default>
13
+ <joint damping="1" armature="0.1"/>
14
+ <geom type="mesh" material="pf400_white"/>
15
+ <mesh scale="0.001 0.001 0.001"/>
16
+ <position inheritrange="1"/>
17
+ <default class="pf400_decor">
18
+ <geom contype="0" conaffinity="0" mass="0"/>
19
+ </default>
20
+ </default>
21
+
22
+ <asset>
23
+ <material name="pf400_white" rgba="0.93 0.93 0.94 1" specular="0.3" shininess="0.4"/>
24
+ <material name="pf400_dark" rgba="0.12 0.12 0.13 1" specular="0.2"/>
25
+ <material name="pf400_grey" rgba="0.62 0.63 0.65 1" specular="0.3"/>
26
+ <material name="pf400_blue" rgba="0.2 0.55 1 1" emission="0.6"/>
27
+ <mesh file="base_plate.stl"/>
28
+ <mesh file="column.stl"/>
29
+ <mesh file="carriage.stl"/>
30
+ <mesh file="inner_link.stl"/>
31
+ <mesh file="outer_link.stl"/>
32
+ <mesh file="gripper.stl"/>
33
+ <mesh file="finger.stl"/>
34
+ </asset>
35
+
36
+ <worldbody>
37
+ <body name="pf400_base">
38
+ <geom name="base_plate" mesh="base_plate" material="pf400_grey" mass="2"/>
39
+ <geom name="column" mesh="column" mass="12"/>
40
+ <geom name="slot_left" class="pf400_decor" type="box" size="0.0005 0.005 0.27" pos="-0.0055 0.03 0.38" material="pf400_dark"/>
41
+ <geom name="slot_right" class="pf400_decor" type="box" size="0.0005 0.005 0.27" pos="-0.0055 -0.03 0.38" material="pf400_dark"/>
42
+
43
+ <!-- The J2 axis is 146 mm from the rear edge of the base. -->
44
+ <body name="carriage" pos="0.0455 0 0.179" gravcomp="1">
45
+ <joint name="j1_z" type="slide" axis="0 0 1" range="0 0.4"/>
46
+ <geom name="carriage" mesh="carriage" contype="0" conaffinity="0" mass="2"/>
47
+
48
+ <body name="inner_link" gravcomp="1">
49
+ <joint name="j2_shoulder" axis="0 0 1" range="-93 93"/>
50
+ <geom name="inner_link" mesh="inner_link" mass="2"/>
51
+ <geom name="status_ring" class="pf400_decor" type="cylinder" size="0.0505 0.004" pos="0 0 0.04" material="pf400_blue"/>
52
+
53
+ <!-- J3 = 0 is a straight arm, as on the real robot. The body is drawn at J3 = 180 (folded). -->
54
+ <body name="outer_link" pos="0.225 0 -0.035" euler="0 0 180" gravcomp="1">
55
+ <joint name="j3_elbow" axis="0 0 1" range="12 348" ref="180"/>
56
+ <geom name="outer_link" mesh="outer_link" mass="1.5"/>
57
+
58
+ <body name="gripper" pos="0.210 0 -0.045" gravcomp="1">
59
+ <joint name="j4_wrist" axis="0 0 1" range="-960 960"/>
60
+ <geom name="palm" mesh="gripper" material="pf400_grey" mass="0.5"/>
61
+ <site name="tcp" pos="0.0682 0 -0.045" size="0.004" rgba="1 0 0 1"/>
62
+
63
+ <body name="finger_left" pos="0.0682 0.043 -0.045" gravcomp="1">
64
+ <joint name="finger_left" type="slide" axis="0 1 0" range="0 0.03"/>
65
+ <geom name="finger_left" mesh="finger" material="pf400_dark" mass="0.05" friction="1.5"/>
66
+ </body>
67
+ <body name="finger_right" pos="0.0682 -0.043 -0.045" gravcomp="1">
68
+ <joint name="finger_right" type="slide" axis="0 -1 0" range="0 0.03"/>
69
+ <geom name="finger_right" mesh="finger" material="pf400_dark" mass="0.05" friction="1.5"/>
70
+ </body>
71
+ </body>
72
+ </body>
73
+ </body>
74
+ </body>
75
+ </body>
76
+ </worldbody>
77
+
78
+ <equality>
79
+ <joint joint1="finger_right" joint2="finger_left"/>
80
+ </equality>
81
+
82
+ <!-- Position control. Units of ctrl: m for j1 and gripper, rad for j2-j4. -->
83
+ <actuator>
84
+ <position name="j1_z" joint="j1_z" kp="2000" kv="200"/>
85
+ <position name="j2_shoulder" joint="j2_shoulder" kp="200" kv="20"/>
86
+ <position name="j3_elbow" joint="j3_elbow" kp="200" kv="20"/>
87
+ <position name="j4_wrist" joint="j4_wrist" kp="50" kv="5"/>
88
+ <position name="gripper" joint="finger_left" kp="500" kv="20"/>
89
+ </actuator>
90
+
91
+ <!-- Folded arm, gripper to the front. With J4 = 0 the folded gripper hits the column. -->
92
+ <keyframe>
93
+ <key name="home" qpos="0 0 3.14159 3.14159 0 0" ctrl="0 0 3.14159 3.14159 0"/>
94
+ </keyframe>
95
+ </mujoco>
@@ -0,0 +1,23 @@
1
+ <!-- PF400 on a floor with lights, for the viewer. -->
2
+ <mujoco model="pf400_scene">
3
+ <include file="pf400.xml"/>
4
+
5
+ <statistic center="0.1 0 0.35" extent="0.9"/>
6
+ <visual>
7
+ <headlight diffuse="0.5 0.5 0.5" ambient="0.35 0.35 0.35" specular="0 0 0"/>
8
+ <rgba haze="0.82 0.86 0.9 1"/>
9
+ <global azimuth="130" elevation="-20" offwidth="1280" offheight="960"/>
10
+ <quality shadowsize="4096"/>
11
+ </visual>
12
+
13
+ <asset>
14
+ <texture type="skybox" builtin="gradient" rgb1="0.82 0.86 0.9" rgb2="0.45 0.55 0.68" width="512" height="3072"/>
15
+ <texture name="floor" type="2d" builtin="checker" mark="edge" rgb1="0.78 0.8 0.82" rgb2="0.72 0.74 0.76" markrgb="0.9 0.9 0.9" width="300" height="300"/>
16
+ <material name="floor" texture="floor" texuniform="true" texrepeat="4 4" reflectance="0.15"/>
17
+ </asset>
18
+
19
+ <worldbody>
20
+ <light pos="0.6 -0.6 1.6" dir="-0.4 0.4 -1" directional="true" diffuse="0.6 0.6 0.6"/>
21
+ <geom name="floor" type="plane" size="0 0 0.05" material="floor"/>
22
+ </worldbody>
23
+ </mujoco>
@@ -0,0 +1,233 @@
1
+ # Generated from aemulus/pf400/v1/pf400.proto. DO NOT EDIT.
2
+ # Generated by protoc-gen-connectrpc-py v0.13.0 with parameter "".
3
+ # ruff: noqa: PGH004
4
+ # ruff: noqa
5
+ # pyright: reportDeprecated=false
6
+ # ty: ignore[unused-ignore-comment]
7
+ # ty: ignore[deprecated, unused-ignore-comment]
8
+ # fmt: off
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Protocol, TYPE_CHECKING
13
+
14
+ from connectrpc.client import ConnectClient, ConnectClientSync
15
+ from connectrpc.code import Code
16
+ from connectrpc.errors import ConnectError
17
+ from connectrpc.method import IdempotencyLevel, MethodInfo, StreamType
18
+ from connectrpc.server import ConnectASGIApplication, ConnectWSGIApplication, DEFAULT_READ_MAX_BYTES, Endpoint, EndpointSync
19
+ from protobuf import DescService
20
+
21
+ from . import pf400_pb
22
+ from .pf400_pb import MoveZRequest, MoveZResponse, ReadZRequest, ReadZResponse
23
+
24
+ if TYPE_CHECKING:
25
+ from collections.abc import AsyncGenerator, Iterable, Mapping
26
+
27
+ from connectrpc.codec import Codec
28
+ from connectrpc.compression import Compression
29
+ from connectrpc.interceptor import Interceptor, InterceptorSync
30
+ from connectrpc.request import Headers, RequestContext
31
+
32
+
33
+ class Pf400Service(Protocol):
34
+ async def move_z(self, request: MoveZRequest, ctx: RequestContext[MoveZRequest, MoveZResponse], /) -> MoveZResponse:
35
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
36
+
37
+ async def read_z(self, request: ReadZRequest, ctx: RequestContext[ReadZRequest, ReadZResponse], /) -> ReadZResponse:
38
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
39
+
40
+ @classmethod
41
+ def desc(cls) -> DescService:
42
+ """Returns the descriptor for this service."""
43
+ return next(s for s in pf400_pb.desc().services if s.type_name == 'aemulus.pf400.v1.Pf400Service')
44
+
45
+ class Pf400ServiceASGIApplication(ConnectASGIApplication[Pf400Service]):
46
+ def __init__(
47
+ self,
48
+ service: Pf400Service | AsyncGenerator[Pf400Service],
49
+ *,
50
+ interceptors: Iterable[Interceptor] = (),
51
+ read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
52
+ compressions: Iterable[Compression] | None = None,
53
+ codecs: Iterable[Codec] | None = None,
54
+ ) -> None:
55
+ super().__init__(
56
+ service=service,
57
+ endpoints=lambda svc: {
58
+ "/aemulus.pf400.v1.Pf400Service/MoveZ": Endpoint.unary(
59
+ method=MethodInfo(
60
+ name="MoveZ",
61
+ service_name="aemulus.pf400.v1.Pf400Service",
62
+ input=MoveZRequest,
63
+ output=MoveZResponse,
64
+ idempotency_level=IdempotencyLevel.UNKNOWN,
65
+ stream_type=StreamType.UNARY,
66
+ ),
67
+ function=svc.move_z,
68
+ ),
69
+ "/aemulus.pf400.v1.Pf400Service/ReadZ": Endpoint.unary(
70
+ method=MethodInfo(
71
+ name="ReadZ",
72
+ service_name="aemulus.pf400.v1.Pf400Service",
73
+ input=ReadZRequest,
74
+ output=ReadZResponse,
75
+ idempotency_level=IdempotencyLevel.UNKNOWN,
76
+ stream_type=StreamType.UNARY,
77
+ ),
78
+ function=svc.read_z,
79
+ ),
80
+ },
81
+ interceptors=interceptors,
82
+ read_max_bytes=read_max_bytes,
83
+ compressions=compressions,
84
+ codecs=codecs,
85
+ )
86
+
87
+ @property
88
+ def path(self) -> str:
89
+ """Returns the URL path to mount the application to when serving multiple applications."""
90
+ return "/aemulus.pf400.v1.Pf400Service"
91
+
92
+
93
+ class Pf400ServiceClient(ConnectClient):
94
+ async def move_z(
95
+ self,
96
+ request: MoveZRequest,
97
+ *,
98
+ headers: Headers | Mapping[str, str] | None = None,
99
+ timeout_ms: int | None = None,
100
+ ) -> MoveZResponse:
101
+ return await self.execute_unary(
102
+ request=request,
103
+ method=MethodInfo(
104
+ name="MoveZ",
105
+ service_name="aemulus.pf400.v1.Pf400Service",
106
+ input=MoveZRequest,
107
+ output=MoveZResponse,
108
+ idempotency_level=IdempotencyLevel.UNKNOWN,
109
+ stream_type=StreamType.UNARY,
110
+ ),
111
+ headers=headers,
112
+ timeout_ms=timeout_ms,
113
+ )
114
+ async def read_z(
115
+ self,
116
+ request: ReadZRequest,
117
+ *,
118
+ headers: Headers | Mapping[str, str] | None = None,
119
+ timeout_ms: int | None = None,
120
+ ) -> ReadZResponse:
121
+ return await self.execute_unary(
122
+ request=request,
123
+ method=MethodInfo(
124
+ name="ReadZ",
125
+ service_name="aemulus.pf400.v1.Pf400Service",
126
+ input=ReadZRequest,
127
+ output=ReadZResponse,
128
+ idempotency_level=IdempotencyLevel.UNKNOWN,
129
+ stream_type=StreamType.UNARY,
130
+ ),
131
+ headers=headers,
132
+ timeout_ms=timeout_ms,
133
+ )
134
+
135
+ class Pf400ServiceSync(Protocol):
136
+ def move_z(self, request: MoveZRequest, ctx: RequestContext[MoveZRequest, MoveZResponse], /) -> MoveZResponse:
137
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
138
+
139
+ def read_z(self, request: ReadZRequest, ctx: RequestContext[ReadZRequest, ReadZResponse], /) -> ReadZResponse:
140
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
141
+
142
+ @classmethod
143
+ def desc(cls) -> DescService:
144
+ """Returns the descriptor for this service."""
145
+ return next(s for s in pf400_pb.desc().services if s.type_name == 'aemulus.pf400.v1.Pf400Service')
146
+
147
+ class Pf400ServiceWSGIApplication(ConnectWSGIApplication):
148
+ def __init__(
149
+ self,
150
+ service: Pf400ServiceSync,
151
+ interceptors: Iterable[InterceptorSync] = (),
152
+ read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
153
+ compressions: Iterable[Compression] | None = None,
154
+ codecs: Iterable[Codec] | None = None,
155
+ ) -> None:
156
+ super().__init__(
157
+ endpoints={
158
+ "/aemulus.pf400.v1.Pf400Service/MoveZ": EndpointSync.unary(
159
+ method=MethodInfo(
160
+ name="MoveZ",
161
+ service_name="aemulus.pf400.v1.Pf400Service",
162
+ input=MoveZRequest,
163
+ output=MoveZResponse,
164
+ idempotency_level=IdempotencyLevel.UNKNOWN,
165
+ stream_type=StreamType.UNARY,
166
+ ),
167
+ function=service.move_z,
168
+ ),
169
+ "/aemulus.pf400.v1.Pf400Service/ReadZ": EndpointSync.unary(
170
+ method=MethodInfo(
171
+ name="ReadZ",
172
+ service_name="aemulus.pf400.v1.Pf400Service",
173
+ input=ReadZRequest,
174
+ output=ReadZResponse,
175
+ idempotency_level=IdempotencyLevel.UNKNOWN,
176
+ stream_type=StreamType.UNARY,
177
+ ),
178
+ function=service.read_z,
179
+ ),
180
+ },
181
+ interceptors=interceptors,
182
+ read_max_bytes=read_max_bytes,
183
+ compressions=compressions,
184
+ codecs=codecs,
185
+ )
186
+
187
+ @property
188
+ def path(self) -> str:
189
+ """Returns the URL path to mount the application to when serving multiple applications."""
190
+ return "/aemulus.pf400.v1.Pf400Service"
191
+
192
+
193
+ class Pf400ServiceClientSync(ConnectClientSync):
194
+ def move_z(
195
+ self,
196
+ request: MoveZRequest,
197
+ *,
198
+ headers: Headers | Mapping[str, str] | None = None,
199
+ timeout_ms: int | None = None,
200
+ ) -> MoveZResponse:
201
+ return self.execute_unary(
202
+ request=request,
203
+ method=MethodInfo(
204
+ name="MoveZ",
205
+ service_name="aemulus.pf400.v1.Pf400Service",
206
+ input=MoveZRequest,
207
+ output=MoveZResponse,
208
+ idempotency_level=IdempotencyLevel.UNKNOWN,
209
+ stream_type=StreamType.UNARY,
210
+ ),
211
+ headers=headers,
212
+ timeout_ms=timeout_ms,
213
+ )
214
+ def read_z(
215
+ self,
216
+ request: ReadZRequest,
217
+ *,
218
+ headers: Headers | Mapping[str, str] | None = None,
219
+ timeout_ms: int | None = None,
220
+ ) -> ReadZResponse:
221
+ return self.execute_unary(
222
+ request=request,
223
+ method=MethodInfo(
224
+ name="ReadZ",
225
+ service_name="aemulus.pf400.v1.Pf400Service",
226
+ input=ReadZRequest,
227
+ output=ReadZResponse,
228
+ idempotency_level=IdempotencyLevel.UNKNOWN,
229
+ stream_type=StreamType.UNARY,
230
+ ),
231
+ headers=headers,
232
+ timeout_ms=timeout_ms,
233
+ )
@@ -0,0 +1,138 @@
1
+ # Generated from aemulus/pf400/v1/pf400.proto. DO NOT EDIT.
2
+ # Generated by protoc-gen-py v0.7.0 with parameter "init_files=false".
3
+ # ruff: noqa: PGH004
4
+ # ruff: noqa
5
+ # pyright: reportDeprecated=false
6
+ # ty: ignore[unused-ignore-comment]
7
+ # ty: ignore[deprecated, unused-ignore-comment]
8
+ # fmt: off
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Literal, NoReturn, TYPE_CHECKING, TypeAlias
13
+
14
+ from protobuf import Message
15
+ from protobuf._codegen import file_desc
16
+
17
+ if TYPE_CHECKING:
18
+ from protobuf import DescFile
19
+
20
+
21
+ _MoveZRequestFields: TypeAlias = Literal["height"]
22
+
23
+ class MoveZRequest(Message[_MoveZRequestFields]):
24
+ """
25
+ ```proto
26
+ message aemulus.pf400.v1.MoveZRequest
27
+ ```
28
+
29
+ Attributes:
30
+ height:
31
+ ```proto
32
+ double height = 1;
33
+ ```
34
+ """
35
+
36
+ __slots__ = ("height",)
37
+
38
+ if TYPE_CHECKING:
39
+
40
+ def __init__(
41
+ self,
42
+ *,
43
+ height: float = 0,
44
+ ) -> None:
45
+ pass
46
+
47
+ height: float
48
+
49
+ _MoveZResponseFields: TypeAlias = Literal["position"]
50
+
51
+ class MoveZResponse(Message[_MoveZResponseFields]):
52
+ """
53
+ ```proto
54
+ message aemulus.pf400.v1.MoveZResponse
55
+ ```
56
+
57
+ Attributes:
58
+ position:
59
+ ```proto
60
+ double position = 1;
61
+ ```
62
+ """
63
+
64
+ __slots__ = ("position",)
65
+
66
+ if TYPE_CHECKING:
67
+
68
+ def __init__(
69
+ self,
70
+ *,
71
+ position: float = 0,
72
+ ) -> None:
73
+ pass
74
+
75
+ position: float
76
+
77
+ _ReadZRequestFields: TypeAlias = NoReturn
78
+
79
+ class ReadZRequest(Message[_ReadZRequestFields]):
80
+ """
81
+ ```proto
82
+ message aemulus.pf400.v1.ReadZRequest
83
+ ```
84
+ """
85
+
86
+ __slots__ = ()
87
+
88
+ if TYPE_CHECKING:
89
+
90
+ def __init__(
91
+ self,
92
+ ) -> None:
93
+ pass
94
+
95
+ _ReadZResponseFields: TypeAlias = Literal["position"]
96
+
97
+ class ReadZResponse(Message[_ReadZResponseFields]):
98
+ """
99
+ ```proto
100
+ message aemulus.pf400.v1.ReadZResponse
101
+ ```
102
+
103
+ Attributes:
104
+ position:
105
+ ```proto
106
+ double position = 1;
107
+ ```
108
+ """
109
+
110
+ __slots__ = ("position",)
111
+
112
+ if TYPE_CHECKING:
113
+
114
+ def __init__(
115
+ self,
116
+ *,
117
+ position: float = 0,
118
+ ) -> None:
119
+ pass
120
+
121
+ position: float
122
+
123
+
124
+ _DESC = file_desc(
125
+ b'\n\x1caemulus/pf400/v1/pf400.proto\x12\x10aemulus.pf400.v1"&\n\x0cMoveZRequest\x12\x16\n\x06height\x18\x01 \x01(\x01R\x06height"+\n\rMoveZResponse\x12\x1a\n\x08position\x18\x01 \x01(\x01R\x08position"\x0e\n\x0cReadZRequest"+\n\rReadZResponse\x12\x1a\n\x08position\x18\x01 \x01(\x01R\x08position2\xa2\x01\n\x0cPf400Service\x12H\n\x05MoveZ\x12\x1e.aemulus.pf400.v1.MoveZRequest\x1a\x1f.aemulus.pf400.v1.MoveZResponse\x12H\n\x05ReadZ\x12\x1e.aemulus.pf400.v1.ReadZRequest\x1a\x1f.aemulus.pf400.v1.ReadZResponseb\x06proto3',
126
+ [],
127
+ {
128
+ "MoveZRequest": MoveZRequest,
129
+ "MoveZResponse": MoveZResponse,
130
+ "ReadZRequest": ReadZRequest,
131
+ "ReadZResponse": ReadZResponse,
132
+ },
133
+ )
134
+
135
+
136
+ def desc() -> DescFile:
137
+ """Returns the descriptor for the file `aemulus/pf400/v1/pf400.proto`."""
138
+ return _DESC
File without changes
@@ -0,0 +1,233 @@
1
+ # Generated from aemulus/sim/v1/sim.proto. DO NOT EDIT.
2
+ # Generated by protoc-gen-connectrpc-py v0.13.0 with parameter "".
3
+ # ruff: noqa: PGH004
4
+ # ruff: noqa
5
+ # pyright: reportDeprecated=false
6
+ # ty: ignore[unused-ignore-comment]
7
+ # ty: ignore[deprecated, unused-ignore-comment]
8
+ # fmt: off
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Protocol, TYPE_CHECKING
13
+
14
+ from connectrpc.client import ConnectClient, ConnectClientSync
15
+ from connectrpc.code import Code
16
+ from connectrpc.errors import ConnectError
17
+ from connectrpc.method import IdempotencyLevel, MethodInfo, StreamType
18
+ from connectrpc.server import ConnectASGIApplication, ConnectWSGIApplication, DEFAULT_READ_MAX_BYTES, Endpoint, EndpointSync
19
+ from protobuf import DescService
20
+
21
+ from . import sim_pb
22
+ from .sim_pb import GetJointRequest, GetJointResponse, SetActuatorRequest, SetActuatorResponse
23
+
24
+ if TYPE_CHECKING:
25
+ from collections.abc import AsyncGenerator, Iterable, Mapping
26
+
27
+ from connectrpc.codec import Codec
28
+ from connectrpc.compression import Compression
29
+ from connectrpc.interceptor import Interceptor, InterceptorSync
30
+ from connectrpc.request import Headers, RequestContext
31
+
32
+
33
+ class SimService(Protocol):
34
+ async def get_joint(self, request: GetJointRequest, ctx: RequestContext[GetJointRequest, GetJointResponse], /) -> GetJointResponse:
35
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
36
+
37
+ async def set_actuator(self, request: SetActuatorRequest, ctx: RequestContext[SetActuatorRequest, SetActuatorResponse], /) -> SetActuatorResponse:
38
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
39
+
40
+ @classmethod
41
+ def desc(cls) -> DescService:
42
+ """Returns the descriptor for this service."""
43
+ return next(s for s in sim_pb.desc().services if s.type_name == 'aemulus.sim.v1.SimService')
44
+
45
+ class SimServiceASGIApplication(ConnectASGIApplication[SimService]):
46
+ def __init__(
47
+ self,
48
+ service: SimService | AsyncGenerator[SimService],
49
+ *,
50
+ interceptors: Iterable[Interceptor] = (),
51
+ read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
52
+ compressions: Iterable[Compression] | None = None,
53
+ codecs: Iterable[Codec] | None = None,
54
+ ) -> None:
55
+ super().__init__(
56
+ service=service,
57
+ endpoints=lambda svc: {
58
+ "/aemulus.sim.v1.SimService/GetJoint": Endpoint.unary(
59
+ method=MethodInfo(
60
+ name="GetJoint",
61
+ service_name="aemulus.sim.v1.SimService",
62
+ input=GetJointRequest,
63
+ output=GetJointResponse,
64
+ idempotency_level=IdempotencyLevel.UNKNOWN,
65
+ stream_type=StreamType.UNARY,
66
+ ),
67
+ function=svc.get_joint,
68
+ ),
69
+ "/aemulus.sim.v1.SimService/SetActuator": Endpoint.unary(
70
+ method=MethodInfo(
71
+ name="SetActuator",
72
+ service_name="aemulus.sim.v1.SimService",
73
+ input=SetActuatorRequest,
74
+ output=SetActuatorResponse,
75
+ idempotency_level=IdempotencyLevel.UNKNOWN,
76
+ stream_type=StreamType.UNARY,
77
+ ),
78
+ function=svc.set_actuator,
79
+ ),
80
+ },
81
+ interceptors=interceptors,
82
+ read_max_bytes=read_max_bytes,
83
+ compressions=compressions,
84
+ codecs=codecs,
85
+ )
86
+
87
+ @property
88
+ def path(self) -> str:
89
+ """Returns the URL path to mount the application to when serving multiple applications."""
90
+ return "/aemulus.sim.v1.SimService"
91
+
92
+
93
+ class SimServiceClient(ConnectClient):
94
+ async def get_joint(
95
+ self,
96
+ request: GetJointRequest,
97
+ *,
98
+ headers: Headers | Mapping[str, str] | None = None,
99
+ timeout_ms: int | None = None,
100
+ ) -> GetJointResponse:
101
+ return await self.execute_unary(
102
+ request=request,
103
+ method=MethodInfo(
104
+ name="GetJoint",
105
+ service_name="aemulus.sim.v1.SimService",
106
+ input=GetJointRequest,
107
+ output=GetJointResponse,
108
+ idempotency_level=IdempotencyLevel.UNKNOWN,
109
+ stream_type=StreamType.UNARY,
110
+ ),
111
+ headers=headers,
112
+ timeout_ms=timeout_ms,
113
+ )
114
+ async def set_actuator(
115
+ self,
116
+ request: SetActuatorRequest,
117
+ *,
118
+ headers: Headers | Mapping[str, str] | None = None,
119
+ timeout_ms: int | None = None,
120
+ ) -> SetActuatorResponse:
121
+ return await self.execute_unary(
122
+ request=request,
123
+ method=MethodInfo(
124
+ name="SetActuator",
125
+ service_name="aemulus.sim.v1.SimService",
126
+ input=SetActuatorRequest,
127
+ output=SetActuatorResponse,
128
+ idempotency_level=IdempotencyLevel.UNKNOWN,
129
+ stream_type=StreamType.UNARY,
130
+ ),
131
+ headers=headers,
132
+ timeout_ms=timeout_ms,
133
+ )
134
+
135
+ class SimServiceSync(Protocol):
136
+ def get_joint(self, request: GetJointRequest, ctx: RequestContext[GetJointRequest, GetJointResponse], /) -> GetJointResponse:
137
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
138
+
139
+ def set_actuator(self, request: SetActuatorRequest, ctx: RequestContext[SetActuatorRequest, SetActuatorResponse], /) -> SetActuatorResponse:
140
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
141
+
142
+ @classmethod
143
+ def desc(cls) -> DescService:
144
+ """Returns the descriptor for this service."""
145
+ return next(s for s in sim_pb.desc().services if s.type_name == 'aemulus.sim.v1.SimService')
146
+
147
+ class SimServiceWSGIApplication(ConnectWSGIApplication):
148
+ def __init__(
149
+ self,
150
+ service: SimServiceSync,
151
+ interceptors: Iterable[InterceptorSync] = (),
152
+ read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
153
+ compressions: Iterable[Compression] | None = None,
154
+ codecs: Iterable[Codec] | None = None,
155
+ ) -> None:
156
+ super().__init__(
157
+ endpoints={
158
+ "/aemulus.sim.v1.SimService/GetJoint": EndpointSync.unary(
159
+ method=MethodInfo(
160
+ name="GetJoint",
161
+ service_name="aemulus.sim.v1.SimService",
162
+ input=GetJointRequest,
163
+ output=GetJointResponse,
164
+ idempotency_level=IdempotencyLevel.UNKNOWN,
165
+ stream_type=StreamType.UNARY,
166
+ ),
167
+ function=service.get_joint,
168
+ ),
169
+ "/aemulus.sim.v1.SimService/SetActuator": EndpointSync.unary(
170
+ method=MethodInfo(
171
+ name="SetActuator",
172
+ service_name="aemulus.sim.v1.SimService",
173
+ input=SetActuatorRequest,
174
+ output=SetActuatorResponse,
175
+ idempotency_level=IdempotencyLevel.UNKNOWN,
176
+ stream_type=StreamType.UNARY,
177
+ ),
178
+ function=service.set_actuator,
179
+ ),
180
+ },
181
+ interceptors=interceptors,
182
+ read_max_bytes=read_max_bytes,
183
+ compressions=compressions,
184
+ codecs=codecs,
185
+ )
186
+
187
+ @property
188
+ def path(self) -> str:
189
+ """Returns the URL path to mount the application to when serving multiple applications."""
190
+ return "/aemulus.sim.v1.SimService"
191
+
192
+
193
+ class SimServiceClientSync(ConnectClientSync):
194
+ def get_joint(
195
+ self,
196
+ request: GetJointRequest,
197
+ *,
198
+ headers: Headers | Mapping[str, str] | None = None,
199
+ timeout_ms: int | None = None,
200
+ ) -> GetJointResponse:
201
+ return self.execute_unary(
202
+ request=request,
203
+ method=MethodInfo(
204
+ name="GetJoint",
205
+ service_name="aemulus.sim.v1.SimService",
206
+ input=GetJointRequest,
207
+ output=GetJointResponse,
208
+ idempotency_level=IdempotencyLevel.UNKNOWN,
209
+ stream_type=StreamType.UNARY,
210
+ ),
211
+ headers=headers,
212
+ timeout_ms=timeout_ms,
213
+ )
214
+ def set_actuator(
215
+ self,
216
+ request: SetActuatorRequest,
217
+ *,
218
+ headers: Headers | Mapping[str, str] | None = None,
219
+ timeout_ms: int | None = None,
220
+ ) -> SetActuatorResponse:
221
+ return self.execute_unary(
222
+ request=request,
223
+ method=MethodInfo(
224
+ name="SetActuator",
225
+ service_name="aemulus.sim.v1.SimService",
226
+ input=SetActuatorRequest,
227
+ output=SetActuatorResponse,
228
+ idempotency_level=IdempotencyLevel.UNKNOWN,
229
+ stream_type=StreamType.UNARY,
230
+ ),
231
+ headers=headers,
232
+ timeout_ms=timeout_ms,
233
+ )
@@ -0,0 +1,144 @@
1
+ # Generated from aemulus/sim/v1/sim.proto. DO NOT EDIT.
2
+ # Generated by protoc-gen-py v0.7.0 with parameter "init_files=false".
3
+ # ruff: noqa: PGH004
4
+ # ruff: noqa
5
+ # pyright: reportDeprecated=false
6
+ # ty: ignore[unused-ignore-comment]
7
+ # ty: ignore[deprecated, unused-ignore-comment]
8
+ # fmt: off
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Literal, NoReturn, TYPE_CHECKING, TypeAlias
13
+
14
+ from protobuf import Message
15
+ from protobuf._codegen import file_desc
16
+
17
+ if TYPE_CHECKING:
18
+ from protobuf import DescFile
19
+
20
+
21
+ _GetJointRequestFields: TypeAlias = Literal["joint"]
22
+
23
+ class GetJointRequest(Message[_GetJointRequestFields]):
24
+ """
25
+ ```proto
26
+ message aemulus.sim.v1.GetJointRequest
27
+ ```
28
+
29
+ Attributes:
30
+ joint:
31
+ ```proto
32
+ string joint = 1;
33
+ ```
34
+ """
35
+
36
+ __slots__ = ("joint",)
37
+
38
+ if TYPE_CHECKING:
39
+
40
+ def __init__(
41
+ self,
42
+ *,
43
+ joint: str = "",
44
+ ) -> None:
45
+ pass
46
+
47
+ joint: str
48
+
49
+ _GetJointResponseFields: TypeAlias = Literal["position"]
50
+
51
+ class GetJointResponse(Message[_GetJointResponseFields]):
52
+ """
53
+ ```proto
54
+ message aemulus.sim.v1.GetJointResponse
55
+ ```
56
+
57
+ Attributes:
58
+ position:
59
+ ```proto
60
+ double position = 1;
61
+ ```
62
+ """
63
+
64
+ __slots__ = ("position",)
65
+
66
+ if TYPE_CHECKING:
67
+
68
+ def __init__(
69
+ self,
70
+ *,
71
+ position: float = 0,
72
+ ) -> None:
73
+ pass
74
+
75
+ position: float
76
+
77
+ _SetActuatorRequestFields: TypeAlias = Literal["actuator", "value"]
78
+
79
+ class SetActuatorRequest(Message[_SetActuatorRequestFields]):
80
+ """
81
+ ```proto
82
+ message aemulus.sim.v1.SetActuatorRequest
83
+ ```
84
+
85
+ Attributes:
86
+ actuator:
87
+ ```proto
88
+ string actuator = 1;
89
+ ```
90
+ value:
91
+ ```proto
92
+ double value = 2;
93
+ ```
94
+ """
95
+
96
+ __slots__ = ("actuator", "value")
97
+
98
+ if TYPE_CHECKING:
99
+
100
+ def __init__(
101
+ self,
102
+ *,
103
+ actuator: str = "",
104
+ value: float = 0,
105
+ ) -> None:
106
+ pass
107
+
108
+ actuator: str
109
+ value: float
110
+
111
+ _SetActuatorResponseFields: TypeAlias = NoReturn
112
+
113
+ class SetActuatorResponse(Message[_SetActuatorResponseFields]):
114
+ """
115
+ ```proto
116
+ message aemulus.sim.v1.SetActuatorResponse
117
+ ```
118
+ """
119
+
120
+ __slots__ = ()
121
+
122
+ if TYPE_CHECKING:
123
+
124
+ def __init__(
125
+ self,
126
+ ) -> None:
127
+ pass
128
+
129
+
130
+ _DESC = file_desc(
131
+ b'\n\x18aemulus/sim/v1/sim.proto\x12\x0eaemulus.sim.v1"\'\n\x0fGetJointRequest\x12\x14\n\x05joint\x18\x01 \x01(\tR\x05joint".\n\x10GetJointResponse\x12\x1a\n\x08position\x18\x01 \x01(\x01R\x08position"F\n\x12SetActuatorRequest\x12\x1a\n\x08actuator\x18\x01 \x01(\tR\x08actuator\x12\x14\n\x05value\x18\x02 \x01(\x01R\x05value"\x15\n\x13SetActuatorResponse2\xb3\x01\n\nSimService\x12M\n\x08GetJoint\x12\x1f.aemulus.sim.v1.GetJointRequest\x1a .aemulus.sim.v1.GetJointResponse\x12V\n\x0bSetActuator\x12".aemulus.sim.v1.SetActuatorRequest\x1a#.aemulus.sim.v1.SetActuatorResponseb\x06proto3',
132
+ [],
133
+ {
134
+ "GetJointRequest": GetJointRequest,
135
+ "GetJointResponse": GetJointResponse,
136
+ "SetActuatorRequest": SetActuatorRequest,
137
+ "SetActuatorResponse": SetActuatorResponse,
138
+ },
139
+ )
140
+
141
+
142
+ def desc() -> DescFile:
143
+ """Returns the descriptor for the file `aemulus/sim/v1/sim.proto`."""
144
+ return _DESC
@@ -0,0 +1,80 @@
1
+ import asyncio
2
+ import threading
3
+ import time
4
+ from importlib.resources import files
5
+
6
+ import mujoco
7
+ import mujoco.viewer
8
+ from connectrpc.request import RequestContext
9
+ from hypercorn import Config
10
+ from hypercorn.asyncio import serve
11
+ from loguru import logger
12
+
13
+ from aemulus.sim.v1.sim_connect import SimService, SimServiceASGIApplication
14
+ from aemulus.sim.v1.sim_pb import (
15
+ GetJointRequest,
16
+ GetJointResponse,
17
+ SetActuatorRequest,
18
+ SetActuatorResponse,
19
+ )
20
+
21
+
22
+ def run_server(service: PF400):
23
+ config = Config()
24
+ config.bind = ["127.0.0.1:50051"]
25
+
26
+ async def main():
27
+ app = SimServiceASGIApplication(service)
28
+ await serve(app, config, shutdown_trigger=asyncio.Event().wait)
29
+
30
+ asyncio.run(main())
31
+
32
+
33
+ def run_simulation():
34
+ path = files("aemulus") / "assets/pf400/scene.xml"
35
+ model = mujoco.MjModel.from_xml_path(str(path))
36
+
37
+ data = mujoco.MjData(model)
38
+ mujoco.mj_resetDataKeyframe(model, data, 0)
39
+ lock = threading.Lock()
40
+ service = PF400(model, data, lock)
41
+
42
+ thread = threading.Thread(target=run_server, args=(service,), daemon=True)
43
+ thread.start()
44
+ logger.info("sim server started")
45
+
46
+ while True:
47
+ step_start = time.time()
48
+ with lock:
49
+ mujoco.mj_step(model, data)
50
+ remaining = model.opt.timestep - (time.time() - step_start)
51
+ if remaining > 0:
52
+ time.sleep(remaining)
53
+
54
+
55
+ class PF400(SimService):
56
+ def __init__(
57
+ self, model: mujoco.MjModel, data: mujoco.MjData, lock: threading.Lock
58
+ ):
59
+ self.model = model
60
+ self.data = data
61
+ self.lock = lock
62
+
63
+ async def get_joint(
64
+ self,
65
+ request: GetJointRequest,
66
+ ctx: RequestContext[GetJointRequest, GetJointResponse],
67
+ /,
68
+ ) -> GetJointResponse:
69
+ with self.lock:
70
+ return GetJointResponse(position=self.data.joint(request.joint).qpos[0])
71
+
72
+ async def set_actuator(
73
+ self,
74
+ request: SetActuatorRequest,
75
+ ctx: RequestContext[SetActuatorRequest, SetActuatorResponse],
76
+ /,
77
+ ) -> SetActuatorResponse:
78
+ with self.lock:
79
+ self.data.actuator(request.actuator).ctrl = request.value
80
+ return SetActuatorResponse()