-
Notifications
You must be signed in to change notification settings - Fork 74
/
urban_signal_intersection_3c.py
141 lines (127 loc) · 4.36 KB
/
urban_signal_intersection_3c.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
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
import time
from macad_gym.carla.multi_env import MultiCarlaEnv
# from env.carla.multi_env import get_next_actions
# config_file = open("urban_2_car_1_ped.json")
# configs = json.load(config_file)
USI3C_CONFIGS = {
"env": {
"server_map": "/Game/Carla/Maps/Town03",
"render": True,
"render_x_res": 800,
"render_y_res": 600,
"x_res": 168,
"y_res": 168,
"framestack": 1,
"discrete_actions": True,
"squash_action_logits": False,
"verbose": False,
"use_depth_camera": False,
"send_measurements": False,
"enable_planner": True,
"spectator_loc": [70, -125, 9],
"sync_server": True
},
"actors": {
"car1": {
"type": "vehicle_4W",
"enable_planner": True,
"convert_images_to_video": False,
"early_terminate_on_collision": True,
"reward_function": "corl2017",
"scenarios": "SUIC3_TOWN3_CAR1",
"manual_control": False,
"auto_control": True,
"camera_type": "rgb",
"collision_sensor": "on",
"lane_sensor": "on",
"log_images": False,
"log_measurements": False,
"render": False,
"render_x_res": 800,
"render_y_res": 600,
"x_res": 168,
"y_res": 168,
"use_depth_camera": False,
"send_measurements": False
},
"car2": {
"type": "vehicle_4W",
"enable_planner": True,
"convert_images_to_video": False,
"early_terminate_on_collision": True,
"reward_function": "corl2017",
"scenarios": "SUIC3_TOWN3_CAR2",
"manual_control": False,
"auto_control": True,
"camera_type": "rgb",
"collision_sensor": "on",
"lane_sensor": "on",
"log_images": False,
"log_measurements": False,
"render": False,
"render_x_res": 800,
"render_y_res": 600,
"x_res": 168,
"y_res": 168,
"use_depth_camera": False,
"send_measurements": False
},
"car3": {
"type": "vehicle_4W",
"enable_planner": True,
"convert_images_to_video": False,
"early_terminate_on_collision": True,
"reward_function": "corl2017",
"scenarios": "SUIC3_TOWN3_CAR3",
"manual_control": False,
"auto_control": True,
"camera_type": "rgb",
"collision_sensor": "on",
"lane_sensor": "on",
"log_images": False,
"log_measurements": False,
"render": False,
"render_x_res": 800,
"render_y_res": 600,
"x_res": 168,
"y_res": 168,
"use_depth_camera": False,
"send_measurements": False
}
}
}
class UrbanSignalIntersection3Car(MultiCarlaEnv):
"""A 4-way signalized intersection Multi-Agent Carla-Gym environment"""
def __init__(self):
self.configs = USI3C_CONFIGS
super(UrbanSignalIntersection3Car, self).__init__(self.configs)
if __name__ == "__main__":
env = UrbanSignalIntersection3Car()
configs = env.configs
for ep in range(2):
obs = env.reset()
total_reward_dict = {}
action_dict = {}
env_config = configs["env"]
actor_configs = configs["actors"]
for actor_id in actor_configs.keys():
total_reward_dict[actor_id] = 0
if env._discrete_actions:
action_dict[actor_id] = 3 # Forward
else:
action_dict[actor_id] = [1, 0] # test values
start = time.time()
i = 0
done = {"__all__": False}
while not done["__all__"]:
# while i < 20: # TEST
i += 1
obs, reward, done, info = env.step(action_dict)
# action_dict = get_next_actions(info, env.discrete_actions)
for actor_id in total_reward_dict.keys():
total_reward_dict[actor_id] += reward[actor_id]
print(":{}\n\t".join(["Step#", "rew", "ep_rew", "done{}"]).format(
i, reward, total_reward_dict, done))
time.sleep(0.1)
print("{} fps".format(i / (time.time() - start)))