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

Class LaneInvasionSensor

PythonAPI/examples/manual_control_rss.py:665–685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663
664
665class LaneInvasionSensor(object):
666 def __init__(self, parent_actor, hud):
667 self.sensor = None
668 self._parent = parent_actor
669 self.hud = hud
670 world = self._parent.get_world()
671 bp = world.get_blueprint_library().find('sensor.other.lane_invasion')
672 self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=self._parent)
673 # We need to pass the lambda a weak reference to self to avoid circular
674 # reference.
675 weak_self = weakref.ref(self)
676 self.sensor.listen(lambda event: LaneInvasionSensor._on_invasion(weak_self, event))
677
678 @staticmethod
679 def _on_invasion(weak_self, event):
680 self = weak_self()
681 if not self:
682 return
683 lane_types = set(x.type for x in event.crossed_lane_markings)
684 text = ['%r' % str(x).split()[-1] for x in lane_types]
685 self.hud.notification('Crossed line %s' % ' and '.join(text))
686
687# ==============================================================================
688# -- GnssSensor --------------------------------------------------------

Callers 1

restartMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected