-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent_activity-c206.py
More file actions
83 lines (69 loc) · 2.67 KB
/
student_activity-c206.py
File metadata and controls
83 lines (69 loc) · 2.67 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
import glob
import os
import sys
import random
import time
import numpy as np
import cv2
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
IM_WIDTH = 640
IM_HEIGHT = 480
def image(image):
matrix_representational_data = np.array(image.raw_data)
reshape_of_image = matrix_representational_data.reshape((IM_HEIGHT, IM_WIDTH, 4))
live_feed_from_camera = reshape_of_image[:, :, :3]
cv2.imshow("", live_feed_from_camera)
cv2.waitKey(1)
return
def camera(get_blueprint_of_world):
camera_sensor = get_blueprint_of_world.find('sensor.camera.rgb')
camera_sensor.set_attribute('image_size_x', f'{IM_WIDTH}')
camera_sensor.set_attribute('image_size_y', f'{IM_HEIGHT}')
camera_sensor.set_attribute('fov', '70')
return camera_sensor
data = []
actor_list = []
try:
client = carla.Client('127.0.0.1', 2000)
client.set_timeout(2.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)
camera_sensor = camera(get_blueprint_of_world)
sensor_camera_spawn_point = carla.Transform(carla.Location(x=2.5, z=0.7))
sensor = world.spawn_actor(camera_sensor, sensor_camera_spawn_point, attach_to=dropped_vehicle)
actor_list.append(sensor)
sensor.listen(lambda camera_data: image(camera_data))
#write a lambda function to control speed of car
speed = lambda speed: carla.VehicleControl(throttle=speed)
#define dropped_vehicle with speed of car
dropped_vehicle.apply_control(speed(0.5))
#define time.sleep
time.sleep(11)
#write a lambda function to control steering of car
steer = lambda steer: carla.VehicleControl(steer=steer)
#define dropped_vehicle with steering movement of car
dropped_vehicle.apply_control(steer(0.5))
#define time.sleep
time.sleep(0.5)
#append car in actor_list()
actor_list.append(dropped_vehicle)
finally:
print('destroying actors')
for actor in actor_list:
actor.destroy()
print('done.')