forked from MasoudJTehrani/PCLA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.py
More file actions
95 lines (76 loc) · 2.9 KB
/
Copy pathsample.py
File metadata and controls
95 lines (76 loc) · 2.9 KB
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
import carla
import time
from PCLA import PCLA
def main():
HOST_IP = "localhost"
client = carla.Client(HOST_IP, 2000)
client.set_timeout(10.0)
client.load_world("Town02")
synchronous_master = False
pcla = None
settings = None
try:
world = client.get_world()
traffic_manager = client.get_trafficmanager(8000)
settings = world.get_settings()
asynch = False
if not asynch:
traffic_manager.set_synchronous_mode(True)
if not settings.synchronous_mode:
synchronous_master = True
settings.synchronous_mode = True
settings.fixed_delta_seconds = 0.05
else:
synchronous_master = False
else:
print("You are currently in asynchronous mode. If this is a traffic simulation, \
you could experience some issues. If it's not working correctly, switch to \
synchronous mode by using traffic_manager.set_synchronous_mode(True)")
#settings.no_rendering_mode = True
world.apply_settings(settings)
# Finding actors
bpLibrary = world.get_blueprint_library()
## Finding vehicle
vehicleBP = bpLibrary.filter('model3')[0]
vehicle_spawn_points = world.get_map().get_spawn_points()
### Spawn vehicle
vehicle = world.spawn_actor(vehicleBP, vehicle_spawn_points[31])
# Retrieve the spectator object
spectator = world.get_spectator()
# Set the spectator with our transform
spectator.set_transform(carla.Transform(carla.Location(x=-8, y=108, z=7), carla.Rotation(pitch=-19, yaw=0, roll=0)))
world.tick()
agent = "simlingo_simlingo"
route = "./sample_route.xml"
pcla = PCLA(agent, vehicle, route, client)
print('\nSpawned the vehicle with model =', agent,', press Ctrl+C to exit.\n')
step = 0
while True:
try:
ego_action = pcla.get_action()
vehicle.apply_control(ego_action)
world.tick()
step += 1
except Exception as e:
print(f'\nError at step {step}:')
print(f'{type(e).__name__}: {e}\n')
import traceback
traceback.print_exc()
break
finally:
#settings.no_rendering_mode = False
if settings is not None:
settings.synchronous_mode = False
world.apply_settings(settings)
# Destroy vehicle
print('\nCleaning up the vehicle')
if pcla is not None:
pcla.cleanup()
time.sleep(0.5)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
finally:
print('Done.')