-
Notifications
You must be signed in to change notification settings - Fork 23
/
demo_sim_static.py
61 lines (50 loc) · 1.65 KB
/
demo_sim_static.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
# -*- coding: utf-8 -*-
"""
路径搜索示例 (单观测)
Created on Wed Mar 13 2024 18:18:07
Modified on 2024-3-13 18:18:07
@auther: HJ https://github.com/zhaohaojie1998
"""
#
# 1.环境实例化
from path_plan_env import StaticPathPlanning, NormalizedActionsWrapper
env = NormalizedActionsWrapper(StaticPathPlanning())
# 2.策略加载
import onnxruntime as ort
policy = ort.InferenceSession("./path_plan_env/policy_static.onnx")
# 3.仿真LOOP
from copy import deepcopy
MAX_EPISODE = 20
for episode in range(MAX_EPISODE):
## 获取初始观测
obs = env.reset()
## 进行一回合仿真
for steps in range(env.max_episode_steps):
# 可视化
env.render()
# 决策
obs = obs.reshape(1, *obs.shape) # (*shape, ) -> (1, *shape, )
act = policy.run(['action'], {'observation': obs})[0] # return [action, ...]
act = act.flatten() # (1, dim, ) -> (dim, )
# 仿真
next_obs, _, _, info = env.step(act)
# 回合结束
if info["terminal"]:
print('回合: ', episode,'| 状态: ', info,'| 步数: ', steps)
break
else:
obs = deepcopy(next_obs)
#end for
#end for
# ⠰⢷⢿⠄
# ⠀⠀⠀⠀⠀⣼⣷⣄
# ⠀⠀⣤⣿⣇⣿⣿⣧⣿⡄
# ⢴⠾⠋⠀⠀⠻⣿⣷⣿⣿⡀
# 🏀 ⢀⣿⣿⡿⢿⠈⣿
# ⠀⠀⢠⣿⡿⠁⢠⣿⡊⠀⠙
# ⠀⠀⢿⣿⠀⠀⠹⣿
# ⠀⠀⠹⣷⡀⠀⣿⡄
# ⠀⣀⣼⣿⠀⢈⣧
#
# 你。。。干。。。嘛。。。
# 哈哈。。唉哟。。。