-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (27 loc) · 1002 Bytes
/
main.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
from metadrive.metadrive.envs import MetaDriveEnv
from scipy.interpolate import CubicHermiteSpline
import numpy as np
import mpc
render = False
env = MetaDriveEnv(dict(
traffic_mode="respawn", map="O", use_render=render))
obs, info = env.reset()
drawer = env.engine.make_point_drawer(scale=1) # create a point drawer
full_spline = mpc.ClassMPC.get_splines_to_destination(env.vehicle, drawer)
mpc = mpc.ClassMPC(full_spline)
for i in range(10000):
action = mpc.find_action(env.vehicle, drawer) # calls mpc solver
obs, reward, terminated, truncated, info = env.step(action)
# env.render(mode="render",
# scaling=None,
# film_size=(500, 500),
# screen_size=(1500, 500),
# # target_vehicle_heading_up=True,
# camera_position=(0,0),
# screen_record=False,
# window=True,
# text={"episode_step": env.engine.episode_step,
# "mode": "Trigger"})
if terminated or truncated:
obs, info = env.reset()
env.close()