def validate_sensor_configuration(sensors, agent_track, selected_track): """ Ensure that the sensor configuration is valid, in case the challenge mode is used Returns true on valid configuration, false otherwise """ if Track(selected_track) != agent_track: raise SensorConfigurationInvalid( "You are submitting to the wrong track [{}]!".format( Track(selected_track))) sensor_count = {} sensor_ids = [] for sensor in sensors: # Check if the is has been already used sensor_id = sensor['id'] if sensor_id in sensor_ids: raise SensorConfigurationInvalid( "Duplicated sensor tag [{}]".format(sensor_id)) else: sensor_ids.append(sensor_id) # Check if the sensor is valid if agent_track == Track.SENSORS: if sensor['type'].startswith('sensor.opendrive_map'): raise SensorConfigurationInvalid( "Illegal sensor used for Track [{}]!".format( agent_track)) # Check the sensors validity if sensor['type'] not in AgentWrapper.allowed_sensors: raise SensorConfigurationInvalid( "Illegal sensor used. {} are not allowed!".format( sensor['type'])) # Check the extrinsics of the sensor if 'x' in sensor and 'y' in sensor and 'z' in sensor: if math.sqrt(sensor['x']**2 + sensor['y']**2 + sensor['z']**2) > MAX_ALLOWED_RADIUS_SENSOR: raise SensorConfigurationInvalid( "Illegal sensor extrinsics used for Track [{}]!". format(agent_track)) # Check the amount of sensors if sensor['type'] in sensor_count: sensor_count[sensor['type']] += 1 else: sensor_count[sensor['type']] = 1 for sensor_type, max_instances_allowed in SENSORS_LIMITS.items(): if sensor_type in sensor_count and sensor_count[ sensor_type] > max_instances_allowed: raise SensorConfigurationInvalid( "Too many {} used! " "Maximum number allowed is {}, but {} were requested.". format(sensor_type, max_instances_allowed, sensor_count[sensor_type]))
def _validate_sensor_configuration(self, selected_track): """ Ensure that the sensor configuration is valid, in case the challenge mode is used Returns true on valid configuration, false otherwise """ if Track(selected_track) != self._agent.track: raise SensorConfigurationInvalid("You are submitting to the wrong track [{}]!".format(Track(selected_track))) sensor_count = {} for sensor in self._agent.sensors(): if self._agent.track == Track.SENSORS: if sensor['type'].startswith('sensor.opendrive_map'): raise SensorConfigurationInvalid("Illegal sensor used for Track [{}]!".format(self._agent.track)) # let's check the extrinsics of the sensor if 'x' in sensor and 'y' in sensor and 'z' in sensor: if math.sqrt(sensor['x']**2 + sensor['y']**2 + sensor['z']**2) > MAX_ALLOWED_RADIUS_SENSOR: raise SensorConfigurationInvalid( "Illegal sensor extrinsics used for Track [{}]!".format(self._agent.track)) if sensor['type'] in sensor_count: sensor_count[sensor['type']] += 1 else: sensor_count[sensor['type']] = 0 for sensor_type, max_instances_allowed in SENSORS_LIMITS.items(): if sensor_type in sensor_count and sensor_count[sensor_type] > max_instances_allowed: raise SensorConfigurationInvalid( "Too many {} used! " "Maximum number allowed is {}, but {} were requested.".format(sensor_type, max_instances_allowed, sensor_count[sensor_type]))