-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-216.py
More file actions
80 lines (67 loc) · 2.54 KB
/
project-216.py
File metadata and controls
80 lines (67 loc) · 2.54 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
import glob
import os
import sys
import time
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_radar_blueprint(blueprint_library):
radar_blueprint = blueprint_library.find("sensor.other.radar")
radar_blueprint.set_attribute("horizontal_fov", str(45))
radar_blueprint.set_attribute("vertical_fov", str(35))
radar_blueprint.set_attribute("points_per_second", str(3500))
radar_blueprint.set_attribute("range", str(35))
return radar_blueprint
try:
client = carla.Client("127.0.0.1", 2000)
client.set_timeout(10.0)
world = client.get_world()
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()[1]
dropped_vehicle = world.spawn_actor(car_model, spawn_point)
simulator_camera_location_rotation = carla.Transform(
spawn_point.location, spawn_point.rotation
)
simulator_camera_location_rotation.location += spawn_point.get_forward_vector() * 30
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)
radar_sensor = generate_radar_blueprint(get_blueprint_of_world)
sensor_radar_spawn_point = carla.Transform(carla.Location(x=-0.5, z=1.8))
sensor = world.spawn_actor(
radar_sensor, sensor_radar_spawn_point, attach_to=dropped_vehicle
)
dropped_vehicle.set_autopilot(True)
sensor.listen(lambda radar_data: radar_callback(radar_data))
def radar_callback(data):
for detection in data:
print("Depth: ", str(detection.depth))
print("Altitude: ", str(detection.altitude))
final_velocity = detection.velocity
initial_velocity = 0.5
time = 1
acceleration = (-(final_velocity - initial_velocity)) / time
print("Acceleration: ", str(acceleration))
print("Velocity: ", str(final_velocity))
print("Azimuth: ", str(detection.azimuth))
actor_list.append(sensor)
time.sleep(1000)
finally:
print("destroying actors")
for actor in actor_list:
actor.destroy()
print("done.")