Carla内容简介

article/2025/9/30 8:16:49

最近学长安排了新的任务,开始学习Carla仿真软件。这个软件之前在自己电脑安装一次,各种坑,坑到我怀疑人生,大概装了两三天才装上,之后因为毕设就没动过了,时隔小一年又重新开始学。。。(后续有时间打算重新装一边最新版本的Carla,感觉之前装的有很多问题,虽然可以运行)
毕竟自己英语不好,本科也不是计算机专业的,学起来还是比较困难的,在这里记录一下学习过程,避免忘了hhh

核心概念

基础

1 world和client

客户端:请求信息或者更改仿真的模块,一个客户端在一个IP和特定的端口下运行。通过终端和服务器进行通信,可以有多个客户端同时运行。

世界:仿真的对象表示。它充当一个抽象层,其中包含生成角色,更改天气,获取当前状态等主要方法。每个仿真中只有一个世界。 更改地图后,它将被销毁并替换为新的地图。

2 actors和blueprints

actor:仿真中的角色,车辆、行人、传感器、交通标志、信号灯、旁观者。

blueprints:是生成角色所需的已经完成的角色布局。模型包含一定的动画和属性,一些属性是可以由用户定义的。

3 maps和navigation

maps:通俗意义的地图。道路车道和路口由Python API管理,可从客户端访问。 它们与waypoint一起使用,为车辆提供导航路径。

交通标志作为作为carla.Landmark对象使用,其中包含有关其OpenDRIVE定义的信息。 此外,在运行时,模拟器会使用OpenDRIVE文件上的信息自动生成停车和交通信号灯对象。 这些在道路上放置了边界框, 一旦进入边界框,车辆就会意识到它们。

4 sensors和data

传感器等待事件发生并且从仿真中收集信息。他们需要一个定义如何管理数据的函数。 取决于种类,传感器检索不同类型的传感器数据。

传感器是连接到车辆上的actor。他跟随车辆收集周围的信息,由蓝图库中可用的蓝图定义。

相机(RGB、深度和语义分割)

碰撞检测器

Gnss(全球卫星导航系统)传感器

IMU(惯性测量单元)传感器

雷达

车道进入检测器

障碍物探测器

激光雷达

RSS传感器

高级

  • OpenDRIVE standalone mode:制作道路网格
  • PTV-Vissim:交通仿真器协同仿真
  • recorder:记录仿真过程,重现仿真
  • rendering options:可选off-screen渲染和无渲染
  • RSS:集成了C ++责任敏感安全性库,可以通过安全检查来修改车辆的轨迹。
  • SUMO:协同仿真
  • Traffic manager:创建自动驾驶的车辆模拟真实世界

World和Client

创建客户端

需要IP地址和两个TCP端口:

client = carla.Client('localhost', 2000)

然后设置连接超时时间:

client.set_timeout(10.0) # seconds

客户端连接当前世界:

world = client.get_world()

或者连接指定世界:

world = client.load_world('Town01')

Commands可以使用批命令,对同时间操作很多元素很有用,例如销毁车辆:

client.apply_batch([carla.command.DestroyActor(x) for x in vehicles_list])

客户端还有其他的特性:Traffic manager和Recorder

World

很多信息和通用设置可以通过这个类访问。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uiX0yjKG-1600950774382)(/home/wj/Documents/MdImage/image-20200923193155302.png)]

world可以寻找actor,寻找创建actor的合适位置、访问蓝图等。

天气是一组参数,可以这样设定:

weather = carla.WeatherParameters(cloudiness=80.0,precipitation=30.0,sun_altitude_angle=70.0)world.set_weather(weather)print(world.get_weather())

还有预设的环境可以直接使用:

world.set_weather(carla.WeatherParameters.WetCloudySunset)

还可以使用两个py脚本设置天气:environment.pydynamic_weather.py

灯(路灯、建筑物灯也可以设置)

# Get the light manager and lights
lmanager = world.get_light_manager()
mylights = lmanager.get_all_lights()# Custom a specific light
light01 = mylights[0]
light01.turn_on()
light01.set_intensity(100.0)
state01 = carla.LightState(200.0,red,carla.LightGroup.Building,True)
light01.set_light_state(state01)# Custom a group of lights
my_lights = lmanager.get_light_group(carla.LightGroup.Building)
lmanager.turn_on(my_lights)
lmanager.set_color(my_lights,carla.Color(255,0,0))
lmanager.set_intensities(my_lights,list_of_intensities)

车辆的灯光需要用户控制

# Turn on position lights
current_lights = carla.VehicleLightState.NONE
current_lights |= carla.VehicleLightState.Position
vehicle.set_light_state(current_lights)

灯光也可以通过environment.py实时设置。

World snapshots

在单个帧中包含模拟中每个参与者的状态。 一种带有时间参考的静止图像。 即使在异步模式下,信息也来自相同的仿真步骤。

# Retrieve a snapshot of the world at current frame.
world_snapshot = world.get_snapshot()

可以得到timesnapshot和actorsnapshot:

timestamp = world_snapshot.timestamp # Get the time reference for actor_snapshot in world_snapshot: # Get the actor and the snapshot informationactual_actor = world.get_actor(actor_snapshot.id)actor_snapshot.get_transform()actor_snapshot.get_velocity()actor_snapshot.get_angular_velocity()actor_snapshot.get_acceleration()  actor_snapshot = world_snapshot.find(actual_actor.id) # Get an actor's snapshot

Actor和Blueprints

Blueprints

蓝图已经建模了actor的动画和其他的一些特性,一些特性可以修改,另一些不可以修改。

world对象可以访问蓝图:

blueprint_library = world.get_blueprint_library()

利用得到的blueprint_library可以得到某个actor的蓝图:

# Find a specific blueprint.
collision_sensor_bp = blueprint_library.find('sensor.other.collision')
# Choose a vehicle blueprint at random.
vehicle_bp = random.choice(blueprint_library.filter('vehicle.*.*'))

此外, 可以得到或设定actor蓝图的特性:

is_bike = [vehicle.get_attribute('number_of_wheels') == 2]
if(is_bike)vehicle.set_attribute('color', '255,0,0')

对于可以修改的属性,有推荐属性可以选择:

for attr in blueprint:if attr.is_modifiable:blueprint.set_attribute(attr.id, random.choice(attr.recommended_values))

Actor的生命周期

世界对象负责产生actor并跟踪这些actor。

world有两种不同的方法生成actorspawn_actor()try_spawn_actor(),生成actor需要提供blueprint和transform,后者指定位置和旋转(rotation):

transform = Transform(Location(x=230, y=195, z=40), Rotation(yaw=180))
actor = world.spawn_actor(blueprint, transform)

不合适的生成点会导致生成失败,可以利用map.get_spawn_points()获取合适的车辆生成点:

spawn_points = world.get_map().get_spawn_points()

随即设置行人的位置:

spawn_point = carla.Transform()
spawn_point.location = world.get_random_location_from_navigation()

actor可以和其他actor连接起来,这对于snesor很有用,例如车载相机:(rigid表示是否可以移动)

transform是相对位置!

camera = world.spawn_actor(camera_bp, relative_transform, attach_to=my_vehicle, carla.AttachmentType.Rigid)

actor生成后,加入list,而后可以检索:

actor_list = world.get_actors()
# Find an actor by id.
actor = actor_list.find(id)
# Print the location of all the speed limit signs in the world.
for speed_sign in actor_list.filter('traffic.speed_limit.*'):print(speed_sign.get_location())

actor大多包含set和get方法:

print(actor.get_acceleration())
print(actor.get_velocity())location = actor.get_location()
location.z += 10.0
actor.set_location(location)

可以禁用actor的物理性质,固定在某个位置:

actor.set_simulate_physics(False)

在脚本运行结束后actor不会销毁,必须手动销毁:

destroyed_sucessfully = actor.destroy() # Returns True if successful

actor的种类

这个例子表示相机附着在车辆上,并且将收集的图像保存到磁盘中:(传感器监听数据,受到数据后调用Lambda函数)

camera_bp = blueprint_library.find('sensor.camera.rgb')
camera = world.spawn_actor(camera_bp, relative_transform, attach_to=my_vehicle)
camera.listen(lambda image: image.save_to_disk('output/%06d.png' % image.frame))

观众(spectator):有UE放置,可以移动仿真视角窗口,如:

spectator = world.get_spectator()
transform = vehicle.get_transform()
spectator.set_transform(carla.Transform(transform.location + carla.Location(z=50),
carla.Rotation(pitch=-90)))

交通标志和交通灯

交通标志有BBox来影响其中的车辆:

#Get the traffic light affecting a vehicle
if vehicle_actor.is_at_traffic_light():traffic_light = vehicle_actor.get_traffic_light()

交通等有单独ID,也有group ID:pole。设置红绿灯:

#Change a red traffic light to green
if traffic_light.get_state() == carla.TrafficLightState.Red:traffic_light.set_state(carla.TrafficLightState.Green)traffic_light.set_set_green_time(4.0)

车辆

四种方式控制车辆:

carla.VehicleControl

vehicle.apply_control(carla.VehicleControl(throttle=1.0, steer=-1.0))

carla.VehiclePhysicsControl

vehicle.apply_physics_control(carla.VehiclePhysicsControl(max_rpm = 5000.0, center_of_mass = carla.Vector3D(0.0, 0.0, 0.0), torque_curve=[[0,400],[5000,400]]))

为了检测碰撞,引入车辆BBox:

box = vehicle.bounding_box
print(box.location)         # Location relative to the vehicle.
print(box.extent)           # XYZ half-box extents in meters.

其他特性:

自动驾驶

vehicle.set_autopilot(True)

车灯

# Turn on position lights
current_lights = carla.VehicleLightState.NONE
current_lights |= carla.VehicleLightState.Position
vehicle.set_light_state(current_lights)

行人

类似于车辆,carla.WalkerControlcarla.WalkerBoneControl

行人可以被AI控制,在其连接的actor周围移动:

walker_controller_bp = world.get_blueprint_library().find('controller.ai.walker')
world.SpawnActor(walker_controller_bp, carla.Transform(), parent_walker)

每个AI controller需要初始化:

ai_controller.start()
ai_controller.go_to_location(world.get_random_location_from_navigation())
ai_controller.set_max_speed(1 + random.random())  # Between 1 and 2 m/s (default is 1.4 m/s).
...
ai_controller.stop()

可以使用batches产生大量行人并行走,可见This recipe。


Maps和navigation

map

每一个map都是基于OpenDRIVE文件。

改变map:reload_world()和load_world()

world = client.load_world('Town01')

可用地图:

print(client.get_available_maps())

landmarks

OpenDRIVE文件中定义的交通标志将转换为CARLA作为可从API查询的地标对象。 为了促进它们的操纵,已经对其进行了一些补充。(此处没列)

Lanes

OpenDRIVE标准定义的通道类型将转换为carla.LaneType中的API,作为一系列枚举值。

# Get the lane type where the waypoint is. 
lane_type = waypoint.lane_type# Get the type of lane marking on the left. 
left_lanemarking_type = waypoint.left_lane_marking.type()# Get available lane changes for this waypoint.
lane_change = waypoint.lane_change

Junctions

此类中最出色的方法是在交叉路口内的每个车道返回一对waypoints。 每对位于交界处的起点和终点。

waypoints_junc = my_junction.get_waypoints()

Waypoints

包含了一些lane的信息

# Examples of a waypoint accessing to lane information
inside_junction = waypoint.is_junction()
width = waypoint.lane_width
right_lm_color = waypoint.right_lane_marking.color

Navigation in CARLA

Navigating through waypoints

有一套与其他人建立联系并建立道路的方法。 所有这些方法都遵循交通规则,仅确定车辆可以行驶的地方。

# Disable physics, in this example the vehicle is teleported.
vehicle.set_simulate_physics(False)
while True:# Find next waypoint 2 meters ahead.waypoint = random.choice(waypoint.next(2.0))# Teleport the vehicle.vehicle.set_transform(waypoint.transform)

Generating a map navigation

Get recommended spawn points for vehiclespointed by developers. There is no ensurance that these spots will be free.

spawn_points = world.get_map().get_spawn_points()

Get the closest waypoint to a specific location or to a certain road_id, lane_id and s in OpenDRIVE.

# Nearest waypoint on the center of a Driving or Sidewalk lane.
waypoint01 = map.get_waypoint(vehicle.get_location(),project_to_road=True, lane_type=(carla.LaneType.Driving | carla.LaneType.Sidewalk))#Nearest waypoint but specifying OpenDRIVE parameters. 
waypoint02 = map.get_waypoint_xodr(road_id,lane_id,s)

Generate a collection of waypoints to visualize the city lanes. Creates waypoints all over the map, for every road and lane. All of them will be an approximate distance apart.

waypoint_list = map.generate_waypoints(2.0)

Generate road topology. Returns a list of pairs (tuples) of waypoints. For each pair, the first element connects with the second one and both define the starting and ending point of each lane in the map.

waypoint_tuple_list = map.get_topology()

Convert simulation point to geographical coordinates. Transforms a certain location to a carla.GeoLocation with latitude and longitude values.

my_geolocation = map.transform_to_geolocation(vehicle.transform)

Save road information. Converts the road information to OpenDRIVE format, and saves it to disk.

info_map = map.to_opendrive()

CARLA maps

内置了8个不同的map,每种都有不同的特性,例如高速公路或者城镇道路。


Sensors和data

每个sensor都有listen()方法检索数据。

Setting

找到蓝图并设置属性,如仪表盘高清摄像头:

# Find the blueprint of the sensor.
blueprint = world.get_blueprint_library().find('sensor.camera.rgb')
# Modify the attributes of the blueprint to set image resolution and field of view.
blueprint.set_attribute('image_size_x', '1920')
blueprint.set_attribute('image_size_y', '1080')
blueprint.set_attribute('fov', '110')
# Set the time in seconds between sensor captures
blueprint.set_attribute('sensor_tick', '1.0')

Spawning

依附其他actor,有两种依附形式Rigid attachment和**SpringArm attachment.**位置相对于依附对象。

transform = carla.Transform(carla.Location(x=0.8, z=1.7))
sensor = world.spawn_actor(blueprint, transform, attach_to=my_vehicle)

Listening

listen()函数的回调参数为lanbda函数,它决定了如何处理检索到的数据。

# do_something() will be called each time a new image is generated by the camera.
sensor.listen(lambda data: do_something(data))...# This collision sensor would print everytime a collision is detected. 
def callback(event):for actor_id in event:vehicle = world_ref().get_actor(actor_id)print('Vehicle too close: %s' % vehicle.type_id)sensor02.listen(callback)

Data

大多数传感器数据对象都具有将信息保存到磁盘的功能。 这将使其可以在其他环境中使用。

传感器数据的属性:frame、timestamp、transform。

传感器种类

相机:深度、RGB、语义分割

Detectors:Collision、Lane invasion、Obstacle事件触发时检测

其他:雷达、激光雷达等。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vVyQeELY-1600950774386)(/home/wj/Documents/MdImage/image-20200923225036189.png)]


http://chatgpt.dhexx.cn/article/mBq8oYXc.shtml

相关文章

Carla学习2:carla安装与使用

文章目录 0. 建议1. carla学习相关链接1.1 官方资料1.1 学习教程 2. Carla安装2.1 服务器端2.1.1 下载预编译版本(也可以使用下载源码并编译) 2.1.2 启动服务器端及服务器端显示导航2.3 客户端2.3.1 创建python环境2.3.2 安装carla 的pythonAPI所需要的依…

【仿真】Carla介绍与使用 [1] (附代码手把手讲解)

0. 参考与前言 主要介绍无人驾驶的仿真环境CARLA,开源社区维护,以下为相关参考链接: Carla官方文档 建议后续找的时候 先按好版本号,有些功能/api 是新版本里有的,Carla官方github Youtube PythonWindow 0.9.5 主要是…

自动驾驶仿真平台Carla从入门到放弃

一、Carla的基本概念 人工智能、5G和V2X技术的不断发展使得自动驾驶成为可能。近几年,自动驾驶发展迅速,在科技新闻上经常可以看到自动驾驶的身影,而从事自动驾驶相关软、硬件研究的高效研究所和公司也越来越多,既有传统的汽车巨头…

介绍一款开源的自动驾驶仿真模拟器-Carla

大家好,我是李慢慢。 不管你是一个自动驾驶的算法工程师,还是仿真工程师,不管你是业界大佬还是小白,我都建议你了解甚至使用一下这个软件。 目录: 0、前言 1、Carla简介 2、Carla的官方资源 3、Carla的安装 4、Ca…

Carla 使用神经网络训练自动驾驶车辆---模型搭建及训练

Carla 使用神经网络训练自动驾驶车辆—模型搭建及训练 上一节已经搭建好了一个carla仿真环境,并且进行了数据采集 现在需要使用采集到的摄像头图片和转角数据进行模型训练 创建dataset类 import numpy as np import config from torch.utils.data import Dataset…

Carla自动驾驶仿真一:快速安装与运行Carla

文章目录 前言一、Carla运行效果二、Carla运行资源1、官方推荐2、环境配置1)Carla 0.9.14下载2)Python依赖安装 3)运行Demo 三、运行前注意事项 前言 网上有不少的Windows版本的Carla的安装教程,这里简单记录下自己安装过程 一、…

Carla 安装详细教程 —— Ubuntu 20.04 安装 Carla

Carla 安装详细教程 —— Ubuntu 20.04 安装 Carla 简介 自动驾驶算法的调试和效果评测首先要在仿真环境中去做,因此,一个强大、灵活的仿真环境是开发、测试过程中必不可少的要素。我们在查找可用的仿真工具时主要关注以下几个特性: 开源&…

[carla入门教程]-1 安装carla环境

本专栏教程将记录我从安装carla到调用carla的pythonAPI进行车辆操控的全流程,带领大家从安装carla开始,到最终能够熟练使用carla仿真环境进行传感器数据采集和车辆控制. 第一节 carla 仿真环境的安装 准备工作: 在本节教程之前,需要大家安装ubuntu18.04以上的系统,并且安装对…

自动驾驶——Carla 模拟器简介

CARLA基本介绍 CARLA是一个开源的自动驾驶模拟器。它是从头开始构建的,用作模块化和灵活的API,以解决自动驾驶问题中涉及的一系列任务。 CARLA的主要目标之一是帮助自动驾驶研发民主化,它是一种易于用户使用和定制的工具。为此,模…

高通8953调试I2S小记

在调通i2s后,发现设备做蓝牙免提时没有声音。后来发现QUIN通路高通竟然没调试过蓝牙免提,这部分代码都没有!经过一番折腾。总算把驱动搞好了。但在实际过程中老是报如下错误: [ 2018.164783] msm_pcm_routing_prepare: setting i…

高通8953启动流程

本文来自于:[添加链接描述 嵌入式工程师有必要了解芯片启动过程,在分析、调试各种问题时都有可能涉及这方面知识。同时,这部分知识复杂,涉及到芯片内部架构,启动各个阶段软件代码执行顺序,启动模式等等。以常用的MSM89…

高通8953平台串口配置入门

目录 一、 串口概述二、 平台串口介绍三、 Device tree如何配置串口四、 bootloader如何配置串口五、bootloader中串口相关代码六、 kernel中串口驱动文件:七、 调试中遇到的问题八、 串口回环测试九、参考文档 一、 串口概述 RS232、RS422、RS485都是串行数据接口…

windows 10安装sqlyog详细步骤

sqlyog下载链接: 链接: https://pan.baidu.com/s/1D_iRna8V90omfHsKHyeBtg 提取码: bqht 复制这段内容后打开百度网盘手机App,操作更方便哦 1. 下载完以后解压,双击SQLyog-12.0.9-0.x64 2. 如下图,选择Ok 3 . 如图,点…

SQLyog下载与安装

SQLyog卸载与安装 声明SQLyog卸载SQLyog安装一、SQLyog下载二、正式安装SQLyog 课后习题即答案 声明 SQLyog卸载 用360直接卸载 SQLyog安装 一、SQLyog下载 1.百度搜索SQLyog官网并进入。 2.下载,稍等片刻,即在浏览器下载列表中看到下载成功。 …

MySQL下载与安装、mysql服务启动与停止、mysql使用cmd命令行登录、SQLyog下载与安装,sqlyog登录与操作mysql

文章目录 1.MySQL下载与安装1.1 下载地址1.2 打开官网,点击DOWNLOADS1.3 点击 MySQL Community Server1.4 在General Availability(GA) Releases中选择适合的版本 2.配置MySQL8.03.配置MySQL8.0 环境变量4.服务的启动与停止4.1 使用图形界面工具4.1.1 打开windows服…

MySQL连接工具(SQLyog、Navicat)下载安装

目录 ❤ SQLyog 下载 安装 双击下载的文件 选择Chinese后点击OK ​编辑 点击“下一步” 选择“我接受”后点击“下一步” 点击“下一步” 修改安装位置(尽量不要安装在C盘),点击“安装” ​编辑 安装后点击“下一步” 点击“完…

【小白】SQLyog下载安装配置篇全攻略

我是第一次使用 SQLyog 这款对于MySQL数据库的可视化图形管理工具,本篇是我对于SQLyog安装配置的过程和总结,仅供大家参考。 如下: 了解SQLyog: SQLyog 是一个快速而简洁的图形化管理MYSQL数据库的工具,它能够在任何地点有效地管理…

python+pycharm+mysql+sqlyog下载安装

目录 工具包详情 Python pycharm mysql sqlyog 工具包详情 工具包包括python安装包,pycharm安装包,mysql安装包,sqlyog安装包及注册码 Python 首先是python安装,较为简单,只需要打开然后选择Add to PATH即可&…

SQLyog——下载2058问题

前言:本文记录了我今天下载和安装SQLyog的过程,主要问题就出在了SQLyog链接这部分——2058号问题。写下来一方面希望我的文章能有所帮助,另一方面记录一下自己的生活。感谢文中链接的作者。 1.先下载安装SQLyog 下载安装SQLyog我看的是这个…

SQLyog(旗舰版)下载

安装导航(以及常见问题的解决方案): https://docs.qq.com/doc/DS0VSV2toQXd0dWtN (如图所示:)