MCPcopy Create free account
hub / github.com/OpenDriveLab/TCP / AgentWrapper

Class AgentWrapper

scenario_runner/srunner/autoagents/agent_wrapper.py:20–98  ·  view source on GitHub ↗

Wrapper for autonomous agents required for tracking and checking of used sensors

Source from the content-addressed store, hash-verified

18
19
20class AgentWrapper(object):
21
22 """
23 Wrapper for autonomous agents required for tracking and checking of used sensors
24 """
25
26 _agent = None
27 _sensors_list = []
28
29 def __init__(self, agent):
30 """
31 Set the autonomous agent
32 """
33 self._agent = agent
34
35 def __call__(self):
36 """
37 Pass the call directly to the agent
38 """
39 return self._agent()
40
41 def setup_sensors(self, vehicle, debug_mode=False):
42 """
43 Create the sensors defined by the user and attach them to the ego-vehicle
44 :param vehicle: ego vehicle
45 :return:
46 """
47 bp_library = CarlaDataProvider.get_world().get_blueprint_library()
48 for sensor_spec in self._agent.sensors():
49 # These are the sensors spawned on the carla world
50 bp = bp_library.find(str(sensor_spec['type']))
51 if sensor_spec['type'].startswith('sensor.camera'):
52 bp.set_attribute('image_size_x', str(sensor_spec['width']))
53 bp.set_attribute('image_size_y', str(sensor_spec['height']))
54 bp.set_attribute('fov', str(sensor_spec['fov']))
55 sensor_location = carla.Location(x=sensor_spec['x'], y=sensor_spec['y'],
56 z=sensor_spec['z'])
57 sensor_rotation = carla.Rotation(pitch=sensor_spec['pitch'],
58 roll=sensor_spec['roll'],
59 yaw=sensor_spec['yaw'])
60 elif sensor_spec['type'].startswith('sensor.lidar'):
61 bp.set_attribute('range', str(sensor_spec['range']))
62 bp.set_attribute('rotation_frequency', str(sensor_spec['rotation_frequency']))
63 bp.set_attribute('channels', str(sensor_spec['channels']))
64 bp.set_attribute('upper_fov', str(sensor_spec['upper_fov']))
65 bp.set_attribute('lower_fov', str(sensor_spec['lower_fov']))
66 bp.set_attribute('points_per_second', str(sensor_spec['points_per_second']))
67 sensor_location = carla.Location(x=sensor_spec['x'], y=sensor_spec['y'],
68 z=sensor_spec['z'])
69 sensor_rotation = carla.Rotation(pitch=sensor_spec['pitch'],
70 roll=sensor_spec['roll'],
71 yaw=sensor_spec['yaw'])
72 elif sensor_spec['type'].startswith('sensor.other.gnss'):
73 sensor_location = carla.Location(x=sensor_spec['x'], y=sensor_spec['y'],
74 z=sensor_spec['z'])
75 sensor_rotation = carla.Rotation()
76
77 # create sensor

Callers 1

load_scenarioMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected