carla传感器及其数据

作者: wangafu | 来源:发表于2020-05-14 11:44 被阅读0次

CARLA传感器及其数据

carla中的传感器可以帮助我们从环境中获取数据,因此传感器对于将carla作为学习训练自动驾驶的平台也十分重要。

本内容总结了处理传感器的所有必要内容,包括不同类型可用传感器的基本信息,以及其整个生命周期涉及的每个步骤的方法,关于不同传感器的具体信息可以参考reference。


传感器步骤

carla.Sensor类定义了特殊的可以测量和传输数据的actor。

  • 数据是什么样的? 这取决于传感器的类型而差异巨大,但是不同的数据都被定义为 [carla.SensorData]
  • 什么时候获取数据? 在每个模拟时间步或者收到了特定的事件的情况下会开始,这取决于传感器的类型。
  • 怎么获取数据? 每个传感器都有一个listen()方法,该方法可以获取和处理这些数据。

尽管不同的传感器本身存在差异,但是使用和管理每个传感器的方法都是类似的。

设置

如其它actor的方式一样,第一步就是在library中找到blueprint,并设定特定的属性以获得想要的结果。这对于处理传感器来说至关重要,因为传感器的能力取决于其设置内容。他们的属性在sensors' reference中有详细的介绍。

下面的例子设定了一个将要连接到车辆上的仪表盘高清摄像头。

# 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')

生成

传感器与其它actor的生产方式也是类似的,只有attachment_toattachment_type 两个可选参数是需要格外注意的。传感器应该连接到另一个actor上去,这个actor通常就是车辆,传感器会跟随该车辆,并采集其周围的数据。有两种可用的连接类型:

  • Rigid: 传感器的位置会根据其父项的位置严格更新。采用这种方式的话,摄像头传感器可能会有雪花出现,如果运动没有放宽的话。
  • SpringArm:运动的加速和减速都会有轻微的放宽
transform = carla.Transform(carla.Location(x=0.8, z=1.7))
sensor = world.spawn_actor(blueprint, transform, attach_to=my_vehicle)

!!! 注意
当使用连接方式产生actor时,其位置为其父项的相对位置,而不是全局位置。

监听

每个传感器都有一个 listen() 方法,在传感器接收到数据后,该方法都会被调用。该方法有一个参数: callback,它是一个函数的lambda expression 表达,其定义了当数据被接收到之后传感器应该做什么。lambda函数必须有至少一个参数,该参数就是获取的数据。

# 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)

!!! 注意
is_listening 是一个根据使用者意愿来开启/关闭数据监听的。
类似的,sensor_tick是一个blueprint attribute蓝本属性,可以被用来设定数据获取的时间间隔,所以其不是在每个时间步都被召回的。

大多数的传感器对象都有一个可以保存测量数据到硬盘的函数,这样的话这些数据就可以在别的地方使用。
传感器属于由于其类型的不同而相差很大,但是通常都被贴了以下标记:

Sensor data attribute Type Description
frame int 测量时的帧数号
timestamp double 情节开始之后模拟器运行时间的时间戳
transform carla.Transform 获取到数据时传感器的位置坐标信息

传感器类型

摄像头

这种摄像头会对模拟器中的world从其位置点进行拍照,然后使用helper类将其获取到的图像进行转换,并提供不同类型的信息。

Retrieve data: 每一个模拟时间步。

Sensor Output Overview
Depth carla.Image Renders the depth of the elements in the field of view in a gray-scale depth map.
RGB carla.Image Provides clear vision of the surroundings. Looks like a normal photo of the scene.
Semantic segmentation carla.Image Renders elements in the field of view with a specific color according to their tags.

Detectors

一种当其连接的父项在模拟器中注册了特定的事件就开始获取数据的传感器。

Retrieve data: 当被激活时.

Sensor Output Overview
Collision carla.CollisionEvent Retrieves collisions between its parent and other actors.
Lane invasion carla.LaneInvasionEvent Registers when its parent crosses a lane marking.
Obstacle carla.ObstacleDetectionEvent Detects possible obstacles ahead of its parent.

Other

这组包含了不同功能的传感器:导航,测量物体物理属性以及提供场景的2D和3D模型。

Retrieve data:每一个模拟时间步.

Sensor Output Overview
GNSS carla.GNSSMeasurement Retrieves the geolocation location of the sensor.
IMU carla.IMUMeasurement Comprises an accelerometer, a gyroscope and a compass.
Lidar raycast carla.LidarMeasurement A rotating lidar retrieving a cloud of points to generate a 3D model the surroundings.
Radar carla.RadarMeasurement 2D point map that models elements in sight and their movement regarding the sensor.

这是关于传感器如何获取模拟数据的总结,因此,关于carla的介绍到这里就结束了,然而还有很多东西需要学习。以下是推荐的集中不同的学习路线:

  • 搞一些练习: 如果只在carla中进行驾驶任务还是有挑战的话,试一试本文档中提供的代码示例会是一个不错的idea,可以尝试将其与示例脚本进行组合或者加入自己的想法。

<div class="build-buttons">

<p>
<a href="ref_code_recipes.md" target="_blank" class="btn btn-neutral" title="Code recipes">
Code recipes</a>
</p>
</div>

  • 继续学习: 在carla中还有一些其他高级的特点,就像渲染选项、交通管理、录像机、以及其它。既然已经学完了基础的知识,搞点这些所谓的高级玩意儿也是极好的。

<div class="build-buttons">

<p>
<a href="adv_synchrony_timestep.md" target="_blank" class="btn btn-neutral" title="Synchrony and time-step">
Synchrony and time-step</a>
</p>
</div>

  • 自由的去试验: 但是不要忘记去看看文档的 References部分,它包含了Pyhon API的各种类的具体信息、传感器及其输出以及其它东东。

<div class="build-buttons">

<p>
<a href="python_api.md" target="_blank" class="btn btn-neutral" title="Python API reference">
Python API reference</a>
</p>
</div>

  • 掏出你的两分钱: 分享你的想法,如果有任何关于carla的疑惑、建议和想法,carla 论坛都欢迎你来搞。

<div class="build-buttons">

<p>
<a href="https://forum.carla.org/" target="_blank" class="btn btn-neutral" title="Go to the CARLA forum">
CARLA forum</a>
</p>
</div>

相关文章

网友评论

    本文标题:carla传感器及其数据

    本文链接:https://www.haomeiwen.com/subject/nxftohtx.html