forked from tonegas/PyDrivingSim
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulator.py
More file actions
50 lines (37 loc) · 1.11 KB
/
Copy pathsimulator.py
File metadata and controls
50 lines (37 loc) · 1.11 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
# Authors : Gastone Pietro Rosati Papini
# Date : 09/08/2022
# License : MIT
import signal
from pydrivingsim import World, Vehicle, TrafficLight, Agent, Obstacle
class GracefulKiller:
kill_now = False
def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self, *args):
self.kill_now = True
def main():
mode = 0 # mode settings: 0 = basic agent, 1 = obstacles
vehicle = Vehicle()
vehicle.set_screen_here()
agent = Agent(vehicle)
trafficlight = TrafficLight()
trafficlight.set_pos((162,-2))
if mode == 1:
# Obstacles position setting
obs = Obstacle()
obs.set_pos((50,0.5))
obs = Obstacle()
obs.set_pos((90,2.5))
obs = Obstacle()
obs.set_pos((130,0.5))
killer = GracefulKiller()
while not killer.kill_now and World().loop:
agent.compute()
action = agent.get_action()
vehicle.set_screen_here()
vehicle.control([action[0], action[1]])
World().update()
agent.terminate()
World().exit()
main()