-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_topology.py
92 lines (57 loc) · 1.81 KB
/
main_topology.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
import carla
import time
import random
import matplotlib.pyplot as plt
import numpy as np
import time
import networkx as nx
import math
from get_topology import *
def main():
client = carla.Client('localhost',2000)
client.set_timeout(2.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
# vehicle
vehicle = blueprint_library.filter('vehicle.lin*')
vehicle = vehicle[0]
# get one of the possible spawning locations
# transform = random.choice(world.get_map().get_spawn_points())
# print transform
# plt.show()
# Get topology from the map
_map = world.get_map()
# Build waypoint graph
topology,waypoints = get_topology(_map)
# print topology[0].keys()#,type(topology[0])
xs = waypoints[:,0]
ys = waypoints[:,1]
graph,id_map = build_graph(topology)
e1 = graph.edges()[0]
e1_data = graph.get_edge_data(e1[0],e1[1])
source_location = e1_data['entry']
waypoint_next_to_source = e1_data['path'][0]
source_vector = e1_data['entry_vector']
source_yaw = np.degrees(np.arctan2(source_vector[1],source_vector[0]))
transform = carla.Transform(carla.Location(x=source_location[0], y=source_location[1], z=2), carla.Rotation(yaw=source_yaw))
vehicle = world.spawn_actor(vehicle,transform)
# print graph.get_edge_data()
axes = plt.gca()
axes.set_xlim(-500, 500)
axes.set_ylim(-500, +500)
line, = axes.plot(xs, ys, 'r*')
p = get_shortest_path(graph, 0, 14)
mapk = id_map.keys()
srcind = id_map.values().index(0)
print srcind
destind = id_map.values().index(14)
source = mapk[srcind]
dest = mapk[destind]
plt.plot(source[0],source[1],'go--', linewidth=2, markersize=12)
plt.plot(dest[0],dest[1],'ro--', linewidth=2, markersize=12)
# print len(final_path_x),len(final_path_y)
plt.plot(p[:,0],p[:,1])
plt.show()
# plt.show()
if __name__ == "__main__":
main()