Open hasibkyau opened 1 year ago
I have created the module for generating the Lidar data along with the location and driving log with following code!
`import glob import os import sys import time import numpy as np import open3d as o3d from csv import writer from PIL import Image as im from utlis import *
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 preProcess(image): image.save_to_disk('lidar_dataset/lidar/1%08d.ply' % image.frame_number) name = ('1%08d' % image.frame_number)
location = vehicle.get_location()
arr = [name,location.x,location.y,location.z]
with open('lidar_dataset/vehicle_location.csv', 'a') as f_object:
writer_object = writer(f_object)
writer_object.writerow(arr)
f_object.close()
c = vehicle.get_control()
arr2 = [name, c.throttle, c.steer, c.brake, c.gear]
with open('lidar_dataset/driving_log.csv', 'a') as f_object:
writer_object = writer(f_object)
writer_object.writerow(arr2)
f_object.close()
try: client = carla.Client("localhost", 2000) client.set_timeout(5.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
bp = blueprint_library.filter("model3")[0]
print(bp)
list = world.get_map().get_spawn_points()
print(list)
spawn_point = list[4]
# spawn_point = random.choice(world.get_map().get_spawn_points())
vehicle = world.spawn_actor(bp, spawn_point)
vehicle.set_autopilot(True)
# vehicle.apply_control(carla.VehicleControl(throttle = 0.0, steer = 0.0))
actor_list.append(vehicle)
lidar_bp = blueprint_library.find("sensor.lidar.ray_cast")
lidar_bp.set_attribute('range', '5000') #Maximum distance to measure/raycast in centimeter
lidar_bp.set_attribute('points_per_second', '56000')
lidar_bp.set_attribute('rotation_frequency', '12')
# lidar_bp.set_attribute('upper_fov', '60') #Angle in degrees of the highest laser.
lidar_bp.set_attribute('channels', '64') #Number of lasers.
spawn_point = carla.Transform(carla.Location(x=2.5, z=2))
lidar_sensor = world.spawn_actor(lidar_bp, spawn_point, attach_to=vehicle)
actor_list.append(lidar_sensor)
lidar_sensor.listen(lambda image: preProcess(image))
location = vehicle.get_location()
print(location)
time.sleep(3600)
finally: for actor in actor_list: actor.destroy() print("All cleaned up!")
`
You have to generate a dataset of LiDAR data from CARLA environment along with the vehicle location and driving log
[NOTE : Remember, the carla lidar sensor attribute for rotation_frequency should be equal or bigger than 12!] ` lidar_bp = blueprint_library.find("sensor.lidar.ray_cast") lidar_bp.set_attribute('range', '5000') #Maximum distance to measure/raycast in centimeter lidar_bp.set_attribute('points_per_second', '56000') lidar_bp.set_attribute('rotation_frequency', '12')
lidar_bp.set_attribute('upper_fov', '60') #Angle in degrees of the highest laser.
`