-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-219.py
More file actions
129 lines (110 loc) · 3.75 KB
/
project-219.py
File metadata and controls
129 lines (110 loc) · 3.75 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
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
import glob
import os
import sys
import time
import random
import math
try:
sys.path.append(
glob.glob(
"../carla/dist/carla-*%d.%d-%s.egg"
% (
sys.version_info.major,
sys.version_info.minor,
"win-amd64" if os.name == "nt" else "linux-x86_64",
)
)[0]
)
except IndexError:
pass
import carla
actor_list = []
def generate_lidar_blueprint(blueprint_library):
lidar_blueprint = blueprint_library.find("sensor.lidar.ray_cast_semantic")
lidar_blueprint.set_attribute("channels", str(64))
lidar_blueprint.set_attribute("points_per_second", str(56000))
lidar_blueprint.set_attribute("rotation_frequency", str(80))
lidar_blueprint.set_attribute("range", str(100))
return lidar_blueprint
object_id = {
0: "None",
1: "Buildings",
2: "Fences",
3: "Other",
4: "Pedestrians",
5: "Poles",
6: "RoadLines",
7: "Roads",
8: "Sidewalks",
9: "Vegetation",
10: "Vehicles",
11: "Wall",
12: "TrafficsSigns",
13: "Sky",
14: "Ground",
15: "Bridge",
16: "RailTrack",
17: "GuardRail",
18: "TrafficLight",
19: "Static",
20: "Dynamic",
21: "Water",
22: "Terrain",
}
def semantic_lidar_data(point_cloud_data):
distance_name_data = {}
for detection in point_cloud_data:
distance_name_data["distance"] = math.sqrt(
(detection.point.x**2)
+ (detection.point.y**2)
+ (detection.point.z**2)
)
distance_name_data["name"] = object_id[detection.object_tag]
print("‘Name of all objects nearby car: ", distance_name_data["name"])
def car_control():
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.51))
time.sleep(20)
try:
client = carla.Client("127.0.0.1", 2000)
client.set_timeout(10.0)
world = client.get_world()
map = world.get_map()
get_blueprint_of_world = world.get_blueprint_library()
car_model = get_blueprint_of_world.filter("model3")[0]
spawn_point = world.get_map().get_spawn_points()[20]
dropped_vehicle = world.spawn_actor(car_model, spawn_point)
walkers_blueprint = random.choice(get_blueprint_of_world.filter("walker"))
walkers_spawn_point = world.get_map().get_spawn_points()[15]
dropped_walker = world.spawn_actor(walkers_blueprint, walkers_spawn_point)
control_walker = carla.WalkerControl()
control_walker.speed = 0.9
control_walker.direction.y = 0
control_walker.direction.x = 1
control_walker.direction.z = 0
dropped_walker.apply_control(control_walker)
simulator_camera_location_rotation = carla.Transform(
walkers_spawn_point.location, walkers_spawn_point.rotation
)
simulator_camera_location_rotation.location += spawn_point.get_forward_vector() * 30
simulator_camera_location_rotation.location += spawn_point.get_up_vector() * -5
simulator_camera_location_rotation.location += spawn_point.get_right_vector() * -8
simulator_camera_location_rotation.rotation.yaw += 180
simulator_camera_view = world.get_spectator()
simulator_camera_view.set_transform(simulator_camera_location_rotation)
actor_list.append(dropped_vehicle)
lidar_sensor = generate_lidar_blueprint(get_blueprint_of_world)
sensor_lidar_spawn_point = carla.Transform(
carla.Location(x=0, y=0, z=2.0),
carla.Rotation(pitch=0.000000, yaw=90.0, roll=0.000000),
)
sensor = world.spawn_actor(
lidar_sensor, sensor_lidar_spawn_point, attach_to=dropped_vehicle
)
sensor.listen(lambda point_cloud_data: semantic_lidar_data(point_cloud_data))
car_control()
time.sleep(1000)
finally:
print("destroying actors")
for actor in actor_list:
actor.destroy()
print("done.")