Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,15 @@ CM*_proj/**/Release/*
**/.vs/*
tests/DelayedConnection/coordMerge.xml
CM11_proj/tmp.obj

# CARLA dependency bundle and local CMake build artifacts
CommonLib/libcarla/
VirCarlaEnv/build/
VirCarlaEnv/VirCarlaEnv/CMakeFiles/
VirCarlaEnv/VirCarlaEnv/CMakeCache.txt
VirCarlaEnv/VirCarlaEnv/cmake_install.cmake
VirCarlaEnv/VirCarlaEnv/*.ninja
VirCarlaEnv/VirCarlaEnv/.ninja*
VirCarlaEnv/VirCarlaEnv/Makefile
VirCarlaEnv/VirCarlaEnv/compile_commands.json
VirCarlaEnv/VirCarlaEnv/*.cmake
5,036 changes: 5,036 additions & 0 deletions Carla/Roosevelt.net.xml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Carla/carla_tl_locs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1375.4974524064373,-1067.6701523048437,182.3,0,0,-91,1356.73,-1077.3400000000001,181.88,-1868_0,373
1375.4974524064373,-1070.8701523048437,182.3,0,0,-91,1356.73,-1077.3400000000001,181.88,-1868_1,373
1375.4974524064373,-1074.0701523048438,182.3,0,0,-91,1356.73,-1077.3400000000001,181.88,-1868_2,373
1375.4974524064373,-1077.2701523048436,182.3,0,0,-91,1356.73,-1077.3400000000001,181.88,-1868_3,373
1348.71,-1057.2,181.84,0,0,0,1356.73,-1077.3400000000001,181.88,-1871_0,373
1351.91,-1057.2,181.84,0,0,0,1356.73,-1077.3400000000001,181.88,-1871_1,373
1355.11,-1057.2,181.84,0,0,0,1356.73,-1077.3400000000001,181.88,-1871_2,373
1338.0,-1086.48,181.46,0,0,-270,1356.73,-1077.3400000000001,181.88,-1880_0,373
1338.0,-1083.28,181.46,0,0,-270,1356.73,-1077.3400000000001,181.88,-1880_1,373
1338.0,-1080.08,181.46,0,0,-270,1356.73,-1077.3400000000001,181.88,-1880_2,373
1361.5598476951563,-1099.4874524064373,181.95,0,0,-181,1356.73,-1077.3400000000001,181.88,-2001_0,373
1358.3598476951563,-1099.4874524064373,181.95,0,0,-181,1356.73,-1077.3400000000001,181.88,-2001_1,373
58 changes: 58 additions & 0 deletions Carla/carla_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from re import T
import carla
import os
from CommonLib.ConfigHelper import ConfigHelper

config_path = os.path.join(os.getcwd(), 'defaultConfig.yaml')
config_helper = ConfigHelper()
config_helper.getConfig(config_path)
carla_server_ip = config_helper.Carla_setup["CarlaServerIP"]
carla_server_port = config_helper.Carla_setup["CarlaServerPort"]


carla_client = carla.Client(carla_server_ip, carla_server_port)

import carla

def draw_axes_at_location(world, location, length=5.0, thickness=0.1, life_time=0.0, persistent=True):
"""
Draw X (red), Y (green), Z (blue) axes at the world origin (0,0,0).
"""
debug = world.debug

# Red X-axis
debug.draw_line(location, carla.Location(x=length, y=0, z=100),
thickness=thickness, color=carla.Color(255, 0, 0), life_time=life_time, persistent_lines=persistent)

# Green Y-axis
debug.draw_line(location, carla.Location(x=0, y=length, z=100),
thickness=thickness, color=carla.Color(0, 255, 0), life_time=life_time, persistent_lines=persistent)

# Blue Z-axis
debug.draw_line(location, carla.Location(x=0, y=0, z=length),
thickness=thickness, color=carla.Color(0, 0, 255), life_time=life_time, persistent_lines=persistent)

def move_spectator_to_location(world, location, pitch=-90.0):
"""
Move the spectator directly above the origin, looking down.
"""
spectator = world.get_spectator()
rotation = carla.Rotation(pitch=pitch, yaw=0)
spectator.set_transform(carla.Transform(location, rotation))
def try_to_spawn_vehicle(world, location, rotation):
vehicle_bp = world.get_blueprint_library().find('vehicle.mini.cooper_s')
vehicle = world.try_spawn_actor(vehicle_bp, carla.Transform(location, rotation))
return vehicle

world = carla_client.get_world()
settings = world.get_settings()
settings.synchronous_mode = False
world.apply_settings(settings)


# draw_axes_at_location(world, carla.Location(334.887, 18.39, 0), length=100.0)
# move_spectator_to_location(world, carla.Location(334.887, 18.39, 100))
# try_to_spawn_vehicle(world, carla.Location(334.887, 18.39, 0.0), carla.Rotation(pitch=0, yaw=90.0346, roll=0))



88 changes: 88 additions & 0 deletions Carla/dash_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import carla
import os
from CommonLib.ConfigHelper import ConfigHelper
from dotenv import load_dotenv
import cv2
import numpy as np
import random
def process_image(image):
array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8"))
array = np.reshape(array, (image.height, image.width, 4)) # RGBA format
rgb_array = array[:, :, :3] # Drop the alpha channel
cv2.imshow("Front Camera", rgb_array)
cv2.waitKey(1)



if __name__ == "__main__":
load_dotenv()
config_path = os.environ["CONFIG_PATH"]
config_helper = ConfigHelper()
config_helper.getConfig(config_path)

carla_server_ip = config_helper.Carla_setup["CarlaServerIP"]
carla_server_port = config_helper.Carla_setup["CarlaServerPort"]
carla_client = carla.Client(carla_server_ip, carla_server_port)

carla_world = carla_client.get_world()
carla_settings = carla_world.get_settings()
if not carla_settings.synchronous_mode:
carla_settings.synchronous_mode = True # Enable synchronous mode
carla_world.apply_settings(carla_settings)
carla_blueprint_library = carla_world.get_blueprint_library()
camera_bp = carla_blueprint_library.find('sensor.camera.rgb')
camera_bp.set_attribute('image_size_x', '800')
camera_bp.set_attribute('image_size_y', '600')
camera_bp.set_attribute('fov', '90')
camera_transform = carla.Transform(carla.Location(x=1.5, z=2.4)) # x is forward, z is up
# Wait until the ego vehicle is spawned in the carla world
RANDOM_SPAWN = True
ego_vehicle_role_name = 'ego'
ego_vehicle_carla_actor: carla.Vehicle = None
ego_vehicle_carla_actor_id = ''
while ego_vehicle_carla_actor is None:
try:
carla_vehicle_actors_in_world = carla_world.get_actors().filter('vehicle.*')
carla_vehicle_actor: carla.Vehicle
# if the ego vehicle is not spawned in carla
if RANDOM_SPAWN:
spawn_points = carla_world.get_map().get_spawn_points()
spawn_point = random.choice(spawn_points)
vehicle_blueprint = carla_blueprint_library.find('vehicle.tesla.model3')
vehicle_blueprint.set_attribute('role_name', ego_vehicle_role_name)
ego_vehicle_carla_actor = carla_world.spawn_actor(vehicle_blueprint, spawn_point)
# set as auto pilot
ego_vehicle_carla_actor.set_autopilot(True)
if ego_vehicle_carla_actor is None:
for carla_vehicle_actor in carla_vehicle_actors_in_world:
if 'role_name' in carla_vehicle_actor.attributes.keys():
carla_actor_role_name = carla_vehicle_actor.attributes.get('role_name', None)
if carla_actor_role_name == ego_vehicle_role_name:
ego_vehicle_carla_actor = carla_vehicle_actor
ego_vehicle_carla_actor_id = carla_vehicle_actor.id
# if the ego vehicle is in carla
camera_actor: carla.Sensor
camera_actor = carla_world.spawn_actor(camera_bp, camera_transform, attach_to=ego_vehicle_carla_actor)

except Exception as e:
print(f"Error occurred: {str(e)}")


camera_actor.listen(lambda image: process_image(image))
latest_image = None

try:
while True:
carla_world.tick()
if latest_image is not None:
cv2.imshow("Front Camera", latest_image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except KeyboardInterrupt:
print("Stopping the simulation.")
finally:
camera_actor.stop()
ego_vehicle_carla_actor.destroy()
camera_actor.destroy()
cv2.destroyAllWindows()
print("Cleaning up...")
20 changes: 20 additions & 0 deletions Carla/disable_carla_synchronous_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import carla
import os
from CommonLib.ConfigHelper import ConfigHelper
from dotenv import load_dotenv
if __name__ == "__main__":
load_dotenv()
config_path = os.environ["CONFIG_PATH"]
config_helper = ConfigHelper()
config_helper.getConfig(config_path)

carla_server_ip = config_helper.Carla_setup["CarlaServerIP"]
carla_server_port = config_helper.Carla_setup["CarlaServerPort"]
carla_client = carla.Client(carla_server_ip, carla_server_port)

world = carla_client.get_world()
settings = world.get_settings()
settings.synchronous_mode = False
world.apply_settings(settings)


Loading