| 717 | |
| 718 | |
| 719 | class RssSensor(object): |
| 720 | def __init__(self, parent_actor): |
| 721 | self.sensor = None |
| 722 | self._parent = parent_actor |
| 723 | self.timestamp = None |
| 724 | self.response_valid = False |
| 725 | self.lon_response = None |
| 726 | self.lat_response_right = None |
| 727 | self.lat_response_left = None |
| 728 | self.acceleration_restriction = None |
| 729 | self.ego_velocity = None |
| 730 | world = self._parent.get_world() |
| 731 | bp = world.get_blueprint_library().find('sensor.other.rss') |
| 732 | self.sensor = world.spawn_actor(bp, carla.Transform(carla.Location(x=0.0, z=0.0)), attach_to=self._parent) |
| 733 | # We need to pass the lambda a weak reference to self to avoid circular |
| 734 | # reference. |
| 735 | |
| 736 | def check_rss_class(clazz): |
| 737 | return inspect.isclass(clazz) and "RssSensor" in clazz.__name__ |
| 738 | |
| 739 | if not inspect.getmembers(carla, check_rss_class): |
| 740 | raise RuntimeError('CARLA PythonAPI not compiled in RSS variant, please "make PythonAPI.rss"') |
| 741 | weak_self = weakref.ref(self) |
| 742 | self.sensor.visualize_results = True |
| 743 | self.sensor.listen(lambda event: RssSensor._on_rss_response(weak_self, event)) |
| 744 | |
| 745 | @staticmethod |
| 746 | def _on_rss_response(weak_self, response): |
| 747 | self = weak_self() |
| 748 | if not self or not response: |
| 749 | return |
| 750 | self.timestamp = response.timestamp |
| 751 | self.response_valid = response.response_valid |
| 752 | self.lon_response = response.longitudinal_response |
| 753 | self.lat_response_right = response.lateral_response_right |
| 754 | self.lat_response_left = response.lateral_response_left |
| 755 | self.acceleration_restriction = response.acceleration_restriction |
| 756 | self.ego_velocity = response.ego_velocity |
| 757 | |
| 758 | |
| 759 | # ============================================================================== |