forked from mizuki-p/EyePersimmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommunication.py
128 lines (109 loc) · 3.02 KB
/
communication.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'''
Entity: Client, Model Server
Client compose of:
- Client ID
- View Server (functions):
- Query Available Models (with Environment ID)
- Register Model
- Send Image
- Receive Action
- Execute Action
- Environment:
- Environment ID
- Environment Name
- Environment Scene
- Environment UI
- Environment Captor
- Environment Action Executor
Model Server compose of:
- Model:
- Model ID
- Request Looper
- Request Executor
- Server (functions):
- Launch Model
- Find suitable model for environment
- Register Client
- Receive Observation
- Compute Action
- Send Action
'''
'''
如何确认环境和模型匹配与否?
对比发过来的环境名称就行,后台维护一个环境名称和模型名称的对应表
为什么Client要先注册才能请求Action?
其实来一个请求就返回一个Action也是可行的,只是<我觉得>之后很有可能需要限制同时访问的用户数量,需要事先留个接口
可能需要处理的,简单但是繁琐的问题:
1. 未注册的用户请求Action
2. 已注册的用户重复注册
3. 注册后的用户掉线
'''
'''
相关接口(websocket接口):
/register_client
request:
- client_id
- env_id
- env_name
success response:
- text: 'register success'
fail response:
- text: 'register fail'
- text: fail_reason
/get_action
request:
- client_id
- observation (image)
- instruction (text)
success response:
- action
fail response:
- text: 'get action fail'
- text: fail_reason
'''
'''
该方案并不要求Client事先安装对应库,使用时按需引入
考虑到用户用户自定义场景的需求,Client端需要提供最基本的接口
Client的预期使用方式:
```python
# 使用预先定义的示例
python -m EP.example.omnigibson_example
```
```python
# 使用自定义场景
from EP import omnigibson_proxy
# init environment
env = omnigibson.OmniGibsonEnv()
### init client
env, client = omnigibson_proxy.Client(
client_id = 'client_1',
)
# render loop
while True:
# action = get_action()
# obs = env.step(action)
obs = env.get_observation()
action = client.get_action(obs)
_ = env.step(action)
```
```python
# 使用自定义模拟器
from EP import EPClient
# init environment
env = Unreal.Env()
client = EPClient(
client_id = 'client_1',
env_id = 'env_1',
env_name = 'Unreal',
env_action_executor = lambda action : env.step(action), # if env supports executing action in non-main thread
# env_action_executor = lambda action : actions_queue.add(action), # if env only supports executing action in main thread
view_mode = 'image_to_live',
view_dataflow = 'active', # 'active' or 'passive'
env_captor = lambda : env.get_observation(),
)
# render loop
while True:
obs = env.get_observation()
client.render(obs)
```
'''