MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / LaneInvasionSensor

Class LaneInvasionSensor

PythonAPI/examples/automatic_control.py:424–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422
423
424class LaneInvasionSensor(object):
425 def __init__(self, parent_actor, hud):
426 self.sensor = None
427 self._parent = parent_actor
428 self.hud = hud
429 world = self._parent.get_world()
430 bp = world.get_blueprint_library().find('sensor.other.lane_invasion')
431 self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=self._parent)
432 # We need to pass the lambda a weak reference to self to avoid circular
433 # reference.
434 weak_self = weakref.ref(self)
435 self.sensor.listen(lambda event: LaneInvasionSensor._on_invasion(weak_self, event))
436
437 @staticmethod
438 def _on_invasion(weak_self, event):
439 self = weak_self()
440 if not self:
441 return
442 lane_types = set(x.type for x in event.crossed_lane_markings)
443 text = ['%r' % str(x).split()[-1] for x in lane_types]
444 self.hud.notification('Crossed line %s' % ' and '.join(text))
445
446# ==============================================================================
447# -- GnssSensor --------------------------------------------------------

Callers 1

restartMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected