Wrapper for autonomous agents required for tracking and checking of used sensors
| 47 | |
| 48 | |
| 49 | class AgentWrapper(object): |
| 50 | |
| 51 | """ |
| 52 | Wrapper for autonomous agents required for tracking and checking of used sensors |
| 53 | """ |
| 54 | |
| 55 | allowed_sensors = [ |
| 56 | 'sensor.opendrive_map', |
| 57 | 'sensor.speedometer', |
| 58 | 'sensor.camera.rgb', |
| 59 | 'sensor.camera.semantic_segmentation', |
| 60 | 'sensor.camera.depth', |
| 61 | 'sensor.camera', |
| 62 | 'sensor.lidar.ray_cast', |
| 63 | 'sensor.lidar.ray_cast_semantic', |
| 64 | 'sensor.other.radar', |
| 65 | 'sensor.other.gnss', |
| 66 | 'sensor.other.imu' |
| 67 | ] |
| 68 | |
| 69 | _agent = None |
| 70 | _sensors_list = [] |
| 71 | |
| 72 | def __init__(self, agent): |
| 73 | """ |
| 74 | Set the autonomous agent |
| 75 | """ |
| 76 | self._agent = agent |
| 77 | |
| 78 | def __call__(self): |
| 79 | """ |
| 80 | Pass the call directly to the agent |
| 81 | """ |
| 82 | return self._agent() |
| 83 | |
| 84 | def setup_sensors(self, vehicle, debug_mode=False): |
| 85 | """ |
| 86 | Create the sensors defined by the user and attach them to the ego-vehicle |
| 87 | :param vehicle: ego vehicle |
| 88 | :return: |
| 89 | """ |
| 90 | bp_library = CarlaDataProvider.get_world().get_blueprint_library() |
| 91 | for sensor_spec in self._agent.sensors(): |
| 92 | # These are the pseudosensors (not spawned) |
| 93 | if sensor_spec['type'].startswith('sensor.opendrive_map'): |
| 94 | # The HDMap pseudo sensor is created directly here |
| 95 | sensor = OpenDriveMapReader(vehicle, sensor_spec['reading_frequency']) |
| 96 | elif sensor_spec['type'].startswith('sensor.speedometer'): |
| 97 | delta_time = CarlaDataProvider.get_world().get_settings().fixed_delta_seconds |
| 98 | frame_rate = 1 / delta_time |
| 99 | sensor = SpeedometerReader(vehicle, frame_rate) |
| 100 | # These are the sensors spawned on the carla world |
| 101 | else: |
| 102 | bp = bp_library.find(str(sensor_spec['type'])) |
| 103 | if sensor_spec['type'].startswith('sensor.camera.semantic_segmentation'): |
| 104 | bp.set_attribute('image_size_x', str(sensor_spec['width'])) |
| 105 | bp.set_attribute('image_size_y', str(sensor_spec['height'])) |
| 106 | bp.set_attribute('fov', str(sensor_spec['fov'])) |