Carla学习笔记-基础传感器设置

本笔记翻译于Carla官方文档

设置基础传感器

生成任何传感器的过程都非常相似1. 使用库查找传感器蓝图。2. 设置传感器的具体属性。这是至关重要的。属性将决定检索的数据。3.将传感器安装到ego车辆上。位置是相对位置。Carla.AttachmentType将决定如何更新传感器的位置。4. 添加一个listen()方法。这是关键因素。每次传感器侦听数据时都会调用的lambda方法。参数是所检索的传感器数据有了这个基本的指导方针,让我们为ego车辆设置一些基本的传感器RGB相机RGB相机生成场景的真实图片。它是具有更多可设置属性的传感器,但也是一个基本的。它应该被理解为一个真实的相机,具有focal_distance, shutter_speed或gamma等属性,以决定它内部如何工作。还有一组特定的属性来定义镜头失真,以及许多高级属性。例如,lens_circle_multiplier可以用来达到类似于眼鱼镜头的效果。具体在文档中了解关于它们的更多信息。为了简单起见,该脚本只设置该传感器最常用的属性。Image_size_x和image_size_y将改变输出图像的分辨率。Fov是相机的水平视场设置属性后,就可以生成传感器了。脚本将摄像机放在汽车引擎盖上,并指向前方。它会捕捉到汽车的正面。每个数据都是carla每一步检索到的图像。listen方法将这些文件保存到磁盘上。这条路可以随意改变。每个图像的名称都是基于拍摄的模拟帧编码的。# --------------# Spawn attached RGB camera# --------------cam_bp = Nonecam_bp = world.get_blueprint_library().find(‘sensor.camera.rgb’)cam_bp.set_attribute(“image_size_x”,str(1920))cam_bp.set_attribute(“image_size_y”,str(1080))cam_bp.set_attribute(“fov”,str(105))cam_location = carla.Location(2,0,1)cam_rotation = carla.Rotation(0,180,0)cam_transform = carla.Transform(cam_location,cam_rotation)ego_cam = world.spawn_actor(cam_bp,cam_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)ego_cam.listen(lambda image: image.save_to_disk(‘tutorial/output/%.6d.jpg’ % image.frame))

探测器

当附加到这些传感器的对象探测到特定事件时,这些传感器就会检索数据。有三种类型的探测器传感器,每一种都描述一种类型的事件碰撞探测器,当本车与其他actor发生碰撞时触发道路越线探测器,当本车越过道路边界线的时候触发障碍物探测器,探测前面可能阻碍本车的障碍物它们检索到的数据将有助于稍后决定模拟的哪个部分将被重新执行。事实上,可以使用记录器明确地查询碰撞情况。只有障碍物检测器的蓝图有属性需要设置:Sensor_tick 设置传感器仅在x秒后检索数据。对于每一步都要检索数据的传感器来说,这是一个常见的属性Distance和hit-radius构成探测前方障碍的调试线。Only_dynamics 确定是否应该考虑静态对象。默认情况下,考虑任何对象。以下脚本将障碍物检测器设置为只考虑动态对象。如果车辆与任何静态物体发生碰撞,碰撞传感器就会检测到。# --------------# Add collision sensor to ego vehicle. # --------------col_bp = world.get_blueprint_library().find(‘sensor.other.collision’)col_location = carla.Location(0,0,0)col_rotation = carla.Rotation(0,0,0)col_transform = carla.Transform(col_location,col_rotation)ego_col = world.spawn_actor(col_bp,col_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)def col_callback(colli): print(“Collision detected:\n”+str(colli)+’\n’)ego_col.listen(lambda colli: col_callback(colli))# --------------# Add Lane invasion sensor to ego vehicle. # --------------lane_bp = world.get_blueprint_library().find(‘sensor.other.lane_invasion’)lane_location = carla.Location(0,0,0)lane_rotation = carla.Rotation(0,0,0)lane_transform = carla.Transform(lane_location,lane_rotation)ego_lane = world.spawn_actor(lane_bp,lane_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)def lane_callback(lane): print(“Lane invasion detected:\n”+str(lane)+’\n’)ego_lane.listen(lambda lane: lane_callback(lane))# --------------# Add Obstacle sensor to ego vehicle. # --------------obs_bp = world.get_blueprint_library().find(‘sensor.other.obstacle’)obs_bp.set_attribute(“only_dynamics”,str(True))obs_location = carla.Location(0,0,0)obs_rotation = carla.Rotation(0,0,0)obs_transform = carla.Transform(obs_location,obs_rotation)ego_obs = world.spawn_actor(obs_bp,obs_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)def obs_callback(obs): print(“Obstacle detected:\n”+str(obs)+’\n’)ego_obs.listen(lambda obs: obs_callback(obs))

其他探测器

GNSS sensor 返回该传感器的地理信息IMU sensor 包括加速度计、陀螺仪、罗盘这些传感器可用的属性大多设置了测量噪声模型中的均值或标准差参数。这对于获得更现实的措施是有用的。但是,在tutorial_ego.py中只设置了一个属性:Sensor_tick由于该度量在各个步骤之间不应该有显著差异,所以可以经常检索数据。在本例中,它被设置为每三秒打印一次。# --------------# Add GNSS sensor to ego vehicle. # --------------gnss_bp = world.get_blueprint_library().find(‘sensor.other.gnss’)gnss_location = carla.Location(0,0,0)gnss_rotation = carla.Rotation(0,0,0)gnss_transform = carla.Transform(gnss_location,gnss_rotation)gnss_bp.set_attribute(“sensor_tick”,str(3.0))ego_gnss = world.spawn_actor(gnss_bp,gnss_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)def gnss_callback(gnss): print(“GNSS measure:\n”+str(gnss)+’\n’)ego_gnss.listen(lambda gnss: gnss_callback(gnss))# --------------# Add IMU sensor to ego vehicle. # --------------imu_bp = world.get_blueprint_library().find(‘sensor.other.imu’)imu_location = carla.Location(0,0,0)imu_rotation = carla.Rotation(0,0,0)imu_transform = carla.Transform(imu_location,imu_rotation)imu_bp.set_attribute(“sensor_tick”,str(3.0))ego_imu = world.spawn_actor(imu_bp,imu_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)def imu_callback(imu): print(“IMU measure:\n”+str(imu)+’\n’)ego_imu.listen(lambda imu: imu_callback(imu))

你可能感兴趣的:(笔记)