Skip to content

Sensors

CollisionSensor ¤

__init__(self, parent_actor, hud) special ¤

Source code in carla_client/util/sensors.py
def __init__(self, parent_actor, hud):
    self.sensor = None
    self.history = []
    self._parent = parent_actor
    self.hud = hud
    world = self._parent.get_world()
    bp = world.get_blueprint_library().find("sensor.other.collision")
    self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=self._parent)
    # We need to pass the lambda a weak reference to self to avoid circular
    # reference.
    weak_self = weakref.ref(self)
    self.sensor.listen(
        lambda event: CollisionSensor._on_collision(weak_self, event)
    )

get_collision_history(self) ¤

Source code in carla_client/util/sensors.py
def get_collision_history(self):
    history = collections.defaultdict(int)
    for frame, intensity in self.history:
        history[frame] += intensity
    return history

GnssSensor ¤

__init__(self, parent_actor) special ¤

Source code in carla_client/util/sensors.py
def __init__(self, parent_actor):
    self.sensor = None
    self._parent = parent_actor
    self.lat = 0.0
    self.lon = 0.0
    world = self._parent.get_world()
    bp = world.get_blueprint_library().find("sensor.other.gnss")
    self.sensor = world.spawn_actor(
        bp, carla.Transform(carla.Location(x=1.0, z=2.8)), attach_to=self._parent
    )
    # We need to pass the lambda a weak reference to self to avoid circular
    # reference.
    weak_self = weakref.ref(self)
    self.sensor.listen(lambda event: GnssSensor._on_gnss_event(weak_self, event))

IMUSensor ¤

__init__(self, parent_actor) special ¤

Source code in carla_client/util/sensors.py
def __init__(self, parent_actor):
    self.sensor = None
    self._parent = parent_actor
    self.accelerometer = (0.0, 0.0, 0.0)
    self.gyroscope = (0.0, 0.0, 0.0)
    self.compass = 0.0
    world = self._parent.get_world()
    bp = world.get_blueprint_library().find("sensor.other.imu")
    self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=self._parent)
    # We need to pass the lambda a weak reference to self to avoid circular
    # reference.
    weak_self = weakref.ref(self)
    self.sensor.listen(
        lambda sensor_data: IMUSensor._IMU_callback(weak_self, sensor_data)
    )

LaneInvasionSensor ¤

__init__(self, parent_actor, hud) special ¤

Source code in carla_client/util/sensors.py
def __init__(self, parent_actor, hud):
    self.sensor = None
    self._parent = parent_actor
    self.hud = hud
    world = self._parent.get_world()
    bp = world.get_blueprint_library().find("sensor.other.lane_invasion")
    self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=self._parent)
    # We need to pass the lambda a weak reference to self to avoid circular
    # reference.
    weak_self = weakref.ref(self)
    self.sensor.listen(
        lambda event: LaneInvasionSensor._on_invasion(weak_self, event)
    )

RadarSensor ¤

__init__(self, parent_actor) special ¤

Source code in carla_client/util/sensors.py
def __init__(self, parent_actor):
    self.sensor = None
    self._parent = parent_actor
    self.velocity_range = 7.5  # m/s
    world = self._parent.get_world()
    self.debug = world.debug
    bp = world.get_blueprint_library().find("sensor.other.radar")
    bp.set_attribute("horizontal_fov", str(35))
    bp.set_attribute("vertical_fov", str(20))
    self.sensor = world.spawn_actor(
        bp,
        carla.Transform(carla.Location(x=2.8, z=1.0), carla.Rotation(pitch=5)),
        attach_to=self._parent,
    )
    # We need a weak reference to self to avoid circular reference.
    weak_self = weakref.ref(self)
    self.sensor.listen(
        lambda radar_data: RadarSensor._Radar_callback(weak_self, radar_data)
    )