-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-222.py
More file actions
89 lines (72 loc) · 3.45 KB
/
project-222.py
File metadata and controls
89 lines (72 loc) · 3.45 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
import glob
import os
import sys
import time
import threading
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 turn_to_right():
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.5, steer=0.21))
time.sleep(5)
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.18, steer=0.25))
time.sleep(1)
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.34))
time.sleep(4)
def check_traffic_lights():
threading.Timer(0.1, check_traffic_lights).start()
traffic_light = dropped_vehicle.get_traffic_light()
if dropped_vehicle.is_at_traffic_light():
print(traffic_light.get_state())
if traffic_light.get_state() == carla.TrafficLightState.Red:# write code for if condition
red_time = traffic_light.get_red_time()# write code for get red light time
print(red_time)# print(red_time)
dropped_vehicle.apply_control(carla.VehicleControl(hand_brake=True))
time.sleep(1)
traffic_light.set_state(carla.TrafficLightState.Yellow)# Change the traffic light color from red to yellow
dropped_vehicle.apply_control(carla.VehicleControl(hand_brake=True))
time.sleep(1)
if traffic_light.get_state() == carla.TrafficLightState.Yellow:# write code for if condition
dropped_vehicle.set_light_state(carla.VehicleLightState(carla.VehicleLightState.Brake |
carla.VehicleLightState.LeftBlinker | carla.VehicleLightState.LowBeam))
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.3,steer=0.15))# write code here to turn car to right
time.sleep(5)
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.15,steer=0.13))
time.sleep(5)
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.34))
dropped_vehicle.apply_control(carla.VehicleControl(hand_brake=True))
time.sleep(10)
print("Car stopped. Well Done!")
else:
dropped_vehicle.apply_control(carla.VehicleControl(hand_brake=True))
time.sleep(10)
else:
dropped_vehicle.apply_control(carla.VehicleControl(throttle=0.51))
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()[20])
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)
# car_control()
check_traffic_lights()
time.sleep(1000)
finally:
print('destroying actors')
for actor in actor_list:
actor.destroy()
print('done.')