diff --git a/srunner/scenarioconfigs/openscenario_configuration.py b/srunner/scenarioconfigs/openscenario_configuration.py index ce4d99b09..202975dff 100644 --- a/srunner/scenarioconfigs/openscenario_configuration.py +++ b/srunner/scenarioconfigs/openscenario_configuration.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright (c) 2019 Intel Corporation +# Copyright (c) 2019-2021 Intel Corporation # # This work is licensed under the terms of the MIT license. # For a copy, see . @@ -124,7 +124,8 @@ def _load_catalogs(self): if catalog is None: continue - catalog_path = catalog.find("Directory").attrib.get('path') + "/" + catalog_type + "Catalog.xosc" + catalog_path = str(ParameterRef(catalog.find("Directory").attrib.get('path'))) + \ + "/" + catalog_type + "Catalog.xosc" if not os.path.isabs(catalog_path) and "xosc" in self.filename: catalog_path = os.path.dirname(os.path.abspath(self.filename)) + "/" + catalog_path @@ -134,10 +135,10 @@ def _load_catalogs(self): xml_tree = ET.parse(catalog_path) self._validate_openscenario_catalog_configuration(xml_tree) catalog = xml_tree.find("Catalog") - catalog_name = catalog.attrib.get("name") + catalog_name = str(ParameterRef(catalog.attrib.get("name"))) self.catalogs[catalog_name] = {} for entry in catalog: - self.catalogs[catalog_name][entry.attrib.get("name")] = entry + self.catalogs[catalog_name][str(ParameterRef(entry.attrib.get("name")))] = entry def _set_scenario_name(self): """ @@ -158,7 +159,7 @@ def _set_carla_town(self): Hence, there can be multiple towns specified. We just use the _last_ one. """ for logic in self.xml_tree.find("RoadNetwork").findall("LogicFile"): - self.town = logic.attrib.get('filepath', None) + self.town = str(ParameterRef(logic.attrib.get('filepath', None))) if self.town is not None and ".xodr" in self.town: if not os.path.isabs(self.town): @@ -235,7 +236,7 @@ def _set_actor_information(self): """ for entity in self.xml_tree.iter("Entities"): for obj in entity.iter("ScenarioObject"): - rolename = obj.attrib.get('name', 'simulation') + rolename = str(ParameterRef(obj.attrib.get('name', 'simulation'))) args = {} for prop in obj.iter("Property"): key = prop.get('name') @@ -290,8 +291,8 @@ def _extract_vehicle_information(self, obj, rolename, vehicle, args): Helper function to _set_actor_information for getting vehicle information from XML tree """ color = None - model = vehicle.attrib.get('name', "vehicle.*") - category = vehicle.attrib.get('vehicleCategory', "car") + model = str(ParameterRef(vehicle.attrib.get('name', "vehicle.*"))) + category = str(ParameterRef(vehicle.attrib.get('vehicleCategory', "car"))) ego_vehicle = False for prop in obj.iter("Property"): if prop.get('name', '') == 'type': @@ -312,7 +313,7 @@ def _extract_pedestrian_information(self, obj, rolename, pedestrian, args): """ Helper function to _set_actor_information for getting pedestrian information from XML tree """ - model = pedestrian.attrib.get('model', "walker.*") + model = str(ParameterRef(pedestrian.attrib.get('model', "walker.*"))) speed = self._get_actor_speed(rolename) new_actor = ActorConfigurationData(model, None, rolename, speed, category="pedestrian", args=args) @@ -323,13 +324,13 @@ def _extract_misc_information(self, obj, rolename, misc, args): """ Helper function to _set_actor_information for getting vehicle information from XML tree """ - category = misc.attrib.get('miscObjectCategory') + category = str(ParameterRef(misc.attrib.get('miscObjectCategory'))) if category == "barrier": model = "static.prop.streetbarrier" elif category == "guardRail": model = "static.prop.chainbarrier" else: - model = misc.attrib.get('name') + model = str(ParameterRef(misc.attrib.get('name'))) new_actor = ActorConfigurationData(model, None, rolename, category="misc", args=args) self.other_actors.append(new_actor) @@ -351,7 +352,7 @@ def _get_actor_transform(self, actor_name): actor_found = False for private_action in self.init.iter("Private"): - if private_action.attrib.get('entityRef', None) == actor_name: + if str(ParameterRef(private_action.attrib.get('entityRef', None))) == actor_name: if actor_found: # pylint: disable=line-too-long self.logger.warning( @@ -380,7 +381,7 @@ def _get_actor_speed(self, actor_name): actor_found = False for private_action in self.init.iter("Private"): - if private_action.attrib.get('entityRef', None) == actor_name: + if str(ParameterRef(private_action.attrib.get('entityRef', None))) == actor_name: if actor_found: # pylint: disable=line-too-long self.logger.warning( diff --git a/srunner/tools/openscenario_parser.py b/srunner/tools/openscenario_parser.py index 5dc0f8536..10eff5c7b 100644 --- a/srunner/tools/openscenario_parser.py +++ b/srunner/tools/openscenario_parser.py @@ -361,7 +361,10 @@ def get_catalog_entry(catalogs, catalog_reference): returns: Catalog entry (XML ElementTree) """ - entry = catalogs[catalog_reference.attrib.get("catalogName")][ParameterRef(catalog_reference.attrib.get("entryName"))] + catalog_name = str(ParameterRef(catalog_reference.attrib.get("catalogName"))) + catalog_entry = str(ParameterRef(catalog_reference.attrib.get("entryName"))) + + entry = catalogs[catalog_name][catalog_entry] entry_copy = copy.deepcopy(entry) catalog_copy = copy.deepcopy(catalog_reference) entry = OpenScenarioParser.assign_catalog_parameters(entry_copy, catalog_copy) @@ -439,7 +442,7 @@ def get_friction_from_env_action(xml_tree, catalogs): road_condition = environment.iter("RoadCondition") for condition in road_condition: - friction = condition.attrib.get('frictionScaleFactor') + friction = float(ParameterRef(condition.attrib.get('frictionScaleFactor'))) return friction @@ -473,11 +476,11 @@ def get_weather_from_env_action(xml_tree, catalogs): sun = weather.find("Sun") carla_weather = carla.WeatherParameters() - carla_weather.sun_azimuth_angle = math.degrees(float(sun.attrib.get('azimuth', 0))) - carla_weather.sun_altitude_angle = math.degrees(float(sun.attrib.get('elevation', 0))) - carla_weather.cloudiness = 100 - float(sun.attrib.get('intensity', 0)) * 100 + carla_weather.sun_azimuth_angle = math.degrees(float(ParameterRef(sun.attrib.get('azimuth', 0)))) + carla_weather.sun_altitude_angle = math.degrees(float(ParameterRef(sun.attrib.get('elevation', 0)))) + carla_weather.cloudiness = 100 - float(ParameterRef(sun.attrib.get('intensity', 0))) * 100 fog = weather.find("Fog") - carla_weather.fog_distance = float(fog.attrib.get('visualRange', 'inf')) + carla_weather.fog_distance = float(ParameterRef(fog.attrib.get('visualRange', 'inf'))) if carla_weather.fog_distance < 1000: carla_weather.fog_density = 100 carla_weather.precipitation = 0 @@ -485,16 +488,16 @@ def get_weather_from_env_action(xml_tree, catalogs): carla_weather.wetness = 0 carla_weather.wind_intensity = 30.0 precepitation = weather.find("Precipitation") - if precepitation.attrib.get('precipitationType') == "rain": - carla_weather.precipitation = float(precepitation.attrib.get('intensity')) * 100 + if str(ParameterRef(precepitation.attrib.get('precipitationType'))) == "rain": + carla_weather.precipitation = float(ParameterRef(precepitation.attrib.get('intensity'))) * 100 carla_weather.precipitation_deposits = 100 # if it rains, make the road wet carla_weather.wetness = carla_weather.precipitation - elif precepitation.attrib.get('type') == "snow": + elif str(ParameterRef(precepitation.attrib.get('type'))) == "snow": raise AttributeError("CARLA does not support snow precipitation") time_of_day = environment.find("TimeOfDay") - weather_animation = strtobool(time_of_day.attrib.get("animation")) - time = time_of_day.attrib.get("dateTime") + weather_animation = strtobool(str(ParameterRef(time_of_day.attrib.get("animation")))) + time = str(ParameterRef(time_of_day.attrib.get("dateTime"))) dtime = datetime.datetime.strptime(time, "%Y-%m-%dT%H:%M:%S") return Weather(carla_weather, dtime, weather_animation) @@ -526,14 +529,14 @@ def get_controller(xml_tree, catalogs): module = None args = {} for prop in properties: - if prop.attrib.get('name') == "module": - module = prop.attrib.get('value') + if str(ParameterRef(prop.attrib.get('name'))) == "module": + module = str(ParameterRef(prop.attrib.get('value'))) else: - args[prop.attrib.get('name')] = prop.attrib.get('value') + args[str(ParameterRef(prop.attrib.get('name')))] = str(ParameterRef(prop.attrib.get('value'))) override_action = xml_tree.find('OverrideControllerValueAction') for child in override_action: - if strtobool(child.attrib.get('active')): + if strtobool(str(ParameterRef(child.attrib.get('active')))): raise NotImplementedError("Controller override actions are not yet supported") return module, args @@ -567,7 +570,7 @@ def get_route(xml_tree, catalogs): if route is not None: for waypoint in route.iter('Waypoint'): position = waypoint.find('Position') - routing_option = str(waypoint.attrib.get('routeStrategy')) + routing_option = str(ParameterRef(waypoint.attrib.get('routeStrategy'))) waypoints.append((position, routing_option)) else: raise AttributeError("No waypoints has been set") @@ -610,7 +613,7 @@ def convert_position_to_transform(position, actor_list=None): rel_pos = position.find('RelativeRoadPosition') # get relative object and relative position - obj = rel_pos.attrib.get('entityRef') + obj = str(ParameterRef(rel_pos.attrib.get('entityRef'))) obj_actor = None actor_transform = None @@ -636,7 +639,7 @@ def convert_position_to_transform(position, actor_list=None): droll = 0 if rel_pos.find('Orientation') is not None: orientation = rel_pos.find('Orientation') - is_absolute = (orientation.attrib.get('type') == "absolute") + is_absolute = (str(ParameterRef(orientation.attrib.get('type'))) == "absolute") dyaw = math.degrees(float(ParameterRef(orientation.attrib.get('h', 0)))) dpitch = math.degrees(float(ParameterRef(orientation.attrib.get('p', 0)))) droll = math.degrees(float(ParameterRef(orientation.attrib.get('r', 0)))) @@ -818,10 +821,10 @@ def convert_condition_to_atomic(condition, actor_list): atomic = None delay_atomic = None - condition_name = condition.attrib.get('name') + condition_name = str(ParameterRef(condition.attrib.get('name'))) - if condition.attrib.get('delay') is not None and float(condition.attrib.get('delay')) != 0: - delay = float(condition.attrib.get('delay')) + if condition.attrib.get('delay') is not None and float(ParameterRef(condition.attrib.get('delay'))) != 0: + delay = float(ParameterRef(condition.attrib.get('delay'))) delay_atomic = TimeOut(delay) if condition.find('ByEntityCondition') is not None: @@ -832,14 +835,15 @@ def convert_condition_to_atomic(condition, actor_list): for triggering_entities in condition.find('ByEntityCondition').iter('TriggeringEntities'): for entity in triggering_entities.iter('EntityRef'): for actor in actor_list: - if actor is not None and entity.attrib.get('entityRef', None) == actor.attributes['role_name']: + if (actor is not None and + str(ParameterRef(entity.attrib.get('entityRef', None))) == actor.attributes['role_name']): trigger_actor = actor break for entity_condition in condition.find('ByEntityCondition').iter('EntityCondition'): if entity_condition.find('EndOfRoadCondition') is not None: end_road_condition = entity_condition.find('EndOfRoadCondition') - condition_duration = ParameterRef(end_road_condition.attrib.get('duration')) + condition_duration = float(ParameterRef(end_road_condition.attrib.get('duration'))) atomic_cls = py_trees.meta.inverter(EndofRoadTest) atomic = atomic_cls(trigger_actor, condition_duration, terminate_on_failure=True, name=condition_name) @@ -851,20 +855,21 @@ def convert_condition_to_atomic(condition, actor_list): collision_entity = collision_condition.find('EntityRef') for actor in actor_list: - if collision_entity.attrib.get('entityRef', None) == actor.attributes['role_name']: + if (str(ParameterRef(collision_entity.attrib.get('entityRef', None))) + == actor.attributes['role_name']): triggered_actor = actor break if triggered_actor is None: raise AttributeError("Cannot find actor '{}' for condition".format( - collision_condition.attrib.get('entityRef', None))) + str(ParameterRef(collision_condition.attrib.get('entityRef', None))))) atomic_cls = py_trees.meta.inverter(CollisionTest) atomic = atomic_cls(trigger_actor, other_actor=triggered_actor, terminate_on_failure=True, name=condition_name) elif collision_condition.find('ByType') is not None: - collision_type = collision_condition.find('ByType').attrib.get('type', None) + collision_type = str(ParameterRef(collision_condition.find('ByType').attrib.get('type', None))) triggered_type = OpenScenarioParser.actor_types[collision_type] @@ -878,7 +883,7 @@ def convert_condition_to_atomic(condition, actor_list): elif entity_condition.find('OffroadCondition') is not None: off_condition = entity_condition.find('OffroadCondition') - condition_duration = ParameterRef(off_condition.attrib.get('duration')) + condition_duration = float(ParameterRef(off_condition.attrib.get('duration'))) atomic_cls = py_trees.meta.inverter(OffRoadTest) atomic = atomic_cls(trigger_actor, condition_duration, terminate_on_failure=True, name=condition_name) @@ -887,19 +892,22 @@ def convert_condition_to_atomic(condition, actor_list): condition_value = ParameterRef(headtime_condition.attrib.get('value')) - condition_rule = headtime_condition.attrib.get('rule') + condition_rule = str(ParameterRef(headtime_condition.attrib.get('rule'))) condition_operator = OpenScenarioParser.operators[condition_rule] - condition_freespace = strtobool(headtime_condition.attrib.get('freespace', False)) - condition_along_route = strtobool(headtime_condition.attrib.get('alongRoute', False)) + condition_freespace = strtobool( + str(ParameterRef(headtime_condition.attrib.get('freespace', False)))) + condition_along_route = strtobool( + str(ParameterRef(headtime_condition.attrib.get('alongRoute', False)))) for actor in actor_list: - if headtime_condition.attrib.get('entityRef', None) == actor.attributes['role_name']: + if (str(ParameterRef(headtime_condition.attrib.get('entityRef', None))) + == actor.attributes['role_name']): triggered_actor = actor break if triggered_actor is None: raise AttributeError("Cannot find actor '{}' for condition".format( - headtime_condition.attrib.get('entityRef', None))) + str(ParameterRef(headtime_condition.attrib.get('entityRef', None))))) atomic = InTimeToArrivalToVehicle( trigger_actor, triggered_actor, condition_value, condition_freespace, @@ -909,15 +917,15 @@ def convert_condition_to_atomic(condition, actor_list): elif entity_condition.find('TimeToCollisionCondition') is not None: ttc_condition = entity_condition.find('TimeToCollisionCondition') - condition_rule = ttc_condition.attrib.get('rule') + condition_rule = str(ParameterRef(ttc_condition.attrib.get('rule'))) condition_operator = OpenScenarioParser.operators[condition_rule] condition_value = ParameterRef(ttc_condition.attrib.get('value')) condition_target = ttc_condition.find('TimeToCollisionConditionTarget') entity_ref_ = condition_target.find('EntityRef') - condition_freespace = strtobool(ttc_condition.attrib.get('freespace', False)) - condition_along_route = strtobool(ttc_condition.attrib.get('alongRoute', False)) + condition_freespace = strtobool(str(ParameterRef(ttc_condition.attrib.get('freespace', False)))) + condition_along_route = strtobool(str(ParameterRef(ttc_condition.attrib.get('alongRoute', False)))) if condition_target.find('Position') is not None: position = condition_target.find('Position') @@ -925,12 +933,13 @@ def convert_condition_to_atomic(condition, actor_list): trigger_actor, position, condition_value, condition_along_route, condition_operator) else: for actor in actor_list: - if entity_ref_.attrib.get('entityRef', None) == actor.attributes['role_name']: + if (str(ParameterRef(entity_ref_.attrib.get('entityRef', None))) + == actor.attributes['role_name']): triggered_actor = actor break if triggered_actor is None: raise AttributeError("Cannot find actor '{}' for condition".format( - entity_ref_.attrib.get('entityRef', None))) + str(ParameterRef(entity_ref_.attrib.get('entityRef', None))))) atomic = InTimeToArrivalToVehicle( trigger_actor, triggered_actor, condition_value, condition_freespace, @@ -938,18 +947,18 @@ def convert_condition_to_atomic(condition, actor_list): elif entity_condition.find('AccelerationCondition') is not None: accel_condition = entity_condition.find('AccelerationCondition') condition_value = ParameterRef(accel_condition.attrib.get('value')) - condition_rule = accel_condition.attrib.get('rule') + condition_rule = str(ParameterRef(accel_condition.attrib.get('rule'))) condition_operator = OpenScenarioParser.operators[condition_rule] atomic = TriggerAcceleration( trigger_actor, condition_value, condition_operator, condition_name) elif entity_condition.find('StandStillCondition') is not None: ss_condition = entity_condition.find('StandStillCondition') - duration = ParameterRef(ss_condition.attrib.get('duration')) + duration = float(ParameterRef(ss_condition.attrib.get('duration'))) atomic = StandStill(trigger_actor, condition_name, duration) elif entity_condition.find('SpeedCondition') is not None: spd_condition = entity_condition.find('SpeedCondition') condition_value = ParameterRef(spd_condition.attrib.get('value')) - condition_rule = spd_condition.attrib.get('rule') + condition_rule = str(ParameterRef(spd_condition.attrib.get('rule'))) condition_operator = OpenScenarioParser.operators[condition_rule] atomic = TriggerVelocity( @@ -957,43 +966,45 @@ def convert_condition_to_atomic(condition, actor_list): elif entity_condition.find('RelativeSpeedCondition') is not None: relspd_condition = entity_condition.find('RelativeSpeedCondition') condition_value = ParameterRef(relspd_condition.attrib.get('value')) - condition_rule = relspd_condition.attrib.get('rule') + condition_rule = str(ParameterRef(relspd_condition.attrib.get('rule'))) condition_operator = OpenScenarioParser.operators[condition_rule] for actor in actor_list: - if relspd_condition.attrib.get('entityRef', None) == actor.attributes['role_name']: + if (str(ParameterRef(relspd_condition.attrib.get('entityRef', None))) + == actor.attributes['role_name']): triggered_actor = actor break if triggered_actor is None: raise AttributeError("Cannot find actor '{}' for condition".format( - relspd_condition.attrib.get('entityRef', None))) + str(ParameterRef(relspd_condition.attrib.get('entityRef', None))))) atomic = RelativeVelocityToOtherActor( trigger_actor, triggered_actor, condition_value, condition_operator, condition_name) elif entity_condition.find('TraveledDistanceCondition') is not None: distance_condition = entity_condition.find('TraveledDistanceCondition') - distance_value = ParameterRef(distance_condition.attrib.get('value')) + distance_value = float(ParameterRef(distance_condition.attrib.get('value'))) atomic = DriveDistance(trigger_actor, distance_value, name=condition_name) elif entity_condition.find('ReachPositionCondition') is not None: rp_condition = entity_condition.find('ReachPositionCondition') - distance_value = ParameterRef(rp_condition.attrib.get('tolerance')) + distance_value = float(ParameterRef(rp_condition.attrib.get('tolerance'))) position = rp_condition.find('Position') atomic = InTriggerDistanceToOSCPosition( trigger_actor, position, distance_value, name=condition_name) elif entity_condition.find('DistanceCondition') is not None: distance_condition = entity_condition.find('DistanceCondition') - distance_value = ParameterRef(distance_condition.attrib.get('value')) + distance_value = float(ParameterRef(distance_condition.attrib.get('value'))) - distance_rule = distance_condition.attrib.get('rule') + distance_rule = str(ParameterRef(distance_condition.attrib.get('rule'))) distance_operator = OpenScenarioParser.operators[distance_rule] - distance_freespace = strtobool(distance_condition.attrib.get('freespace', False)) + distance_freespace = strtobool(str(ParameterRef(distance_condition.attrib.get('freespace', False)))) if distance_freespace: raise NotImplementedError( "DistanceCondition: freespace attribute is currently not implemented") - distance_along_route = strtobool(distance_condition.attrib.get('alongRoute', False)) + distance_along_route = strtobool( + str(ParameterRef(distance_condition.attrib.get('alongRoute', False)))) if distance_condition.find('Position') is not None: position = distance_condition.find('Position') @@ -1003,20 +1014,22 @@ def convert_condition_to_atomic(condition, actor_list): elif entity_condition.find('RelativeDistanceCondition') is not None: distance_condition = entity_condition.find('RelativeDistanceCondition') - distance_value = ParameterRef(distance_condition.attrib.get('value')) + distance_value = float(ParameterRef(distance_condition.attrib.get('value'))) - distance_freespace = distance_condition.attrib.get('freespace', "false") == "true" - rel_dis_type = distance_condition.attrib.get('relativeDistanceType') + distance_freespace = str(ParameterRef( + distance_condition.attrib.get('freespace', "false"))) == "true" + rel_dis_type = str(ParameterRef(distance_condition.attrib.get('relativeDistanceType'))) for actor in actor_list: - if distance_condition.attrib.get('entityRef', None) == actor.attributes['role_name']: + if (str(ParameterRef(distance_condition.attrib.get('entityRef', None))) + == actor.attributes['role_name']): triggered_actor = actor break if triggered_actor is None: raise AttributeError("Cannot find actor '{}' for condition".format( - distance_condition.attrib.get('entityRef', None))) + str(ParameterRef(distance_condition.attrib.get('entityRef', None))))) - condition_rule = distance_condition.attrib.get('rule') + condition_rule = str(ParameterRef(distance_condition.attrib.get('rule'))) condition_operator = OpenScenarioParser.operators[condition_rule] atomic = InTriggerDistanceToVehicle(triggered_actor, trigger_actor, distance_value, condition_operator, distance_type=rel_dis_type, @@ -1025,9 +1038,9 @@ def convert_condition_to_atomic(condition, actor_list): value_condition = condition.find('ByValueCondition') if value_condition.find('ParameterCondition') is not None: parameter_condition = value_condition.find('ParameterCondition') - arg_name = parameter_condition.attrib.get('parameterRef') + arg_name = str(ParameterRef(parameter_condition.attrib.get('parameterRef'))) value = ParameterRef(parameter_condition.attrib.get('value')) - rule = parameter_condition.attrib.get('rule') + rule = str(ParameterRef(parameter_condition.attrib.get('rule'))) if condition_name.startswith('criteria_'): if str(value) != '': arg_value = float(value) @@ -1051,19 +1064,19 @@ def convert_condition_to_atomic(condition, actor_list): elif value_condition.find('SimulationTimeCondition') is not None: simtime_condition = value_condition.find('SimulationTimeCondition') value = ParameterRef(simtime_condition.attrib.get('value')) - rule = OpenScenarioParser.operators[simtime_condition.attrib.get('rule')] + rule = OpenScenarioParser.operators[str(ParameterRef(simtime_condition.attrib.get('rule')))] atomic = SimulationTimeCondition(value, comparison_operator=rule) elif value_condition.find('TimeOfDayCondition') is not None: tod_condition = value_condition.find('TimeOfDayCondition') - condition_date = tod_condition.attrib.get('dateTime') - condition_rule = tod_condition.attrib.get('rule') + condition_date = str(ParameterRef(tod_condition.attrib.get('dateTime'))) + condition_rule = str(ParameterRef(tod_condition.attrib.get('rule'))) condition_operator = OpenScenarioParser.operators[condition_rule] atomic = TimeOfDayComparison(condition_date, condition_operator, condition_name) elif value_condition.find('StoryboardElementStateCondition') is not None: state_condition = value_condition.find('StoryboardElementStateCondition') - element_name = state_condition.attrib.get('storyboardElementRef') - element_type = state_condition.attrib.get('storyboardElementType') - state = state_condition.attrib.get('state') + element_name = str(ParameterRef(state_condition.attrib.get('storyboardElementRef'))) + element_type = str(ParameterRef(state_condition.attrib.get('storyboardElementType'))) + state = str(ParameterRef(state_condition.attrib.get('state'))) if state == "startTransition": atomic = OSCStartEndCondition(element_type, element_name, rule="START", name=state + "Condition") elif state in ["stopTransition", "endTransition", "completeState"]: @@ -1076,10 +1089,10 @@ def convert_condition_to_atomic(condition, actor_list): elif value_condition.find('TrafficSignalCondition') is not None: tl_condition = value_condition.find('TrafficSignalCondition') - name_condition = tl_condition.attrib.get('name') + name_condition = str(ParameterRef(tl_condition.attrib.get('name'))) traffic_light = OpenScenarioParser.get_traffic_light_from_osc_name(name_condition) - tl_state = tl_condition.attrib.get('state').upper() + tl_state = str(ParameterRef(tl_condition.attrib.get('state'))).upper() if tl_state not in OpenScenarioParser.tl_states: raise KeyError("CARLA only supports Green, Red, Yellow or Off") state_condition = OpenScenarioParser.tl_states[tl_state] @@ -1110,7 +1123,7 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): Note not all OpenSCENARIO actions are currently supported """ - maneuver_name = action.attrib.get('name', 'unknown') + maneuver_name = str(ParameterRef(action.attrib.get('name', 'unknown'))) if action.find('GlobalAction') is not None: global_action = action.find('GlobalAction') @@ -1119,10 +1132,10 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): if infrastructure_action.find('TrafficSignalStateAction') is not None: traffic_light_action = infrastructure_action.find('TrafficSignalStateAction') - name_condition = traffic_light_action.attrib.get('name') + name_condition = str(ParameterRef(traffic_light_action.attrib.get('name'))) traffic_light = OpenScenarioParser.get_traffic_light_from_osc_name(name_condition) - tl_state = traffic_light_action.attrib.get('state').upper() + tl_state = str(ParameterRef(traffic_light_action.attrib.get('state'))).upper() if tl_state not in OpenScenarioParser.tl_states: raise KeyError("CARLA only supports Green, Red, Yellow or Off") traffic_light_state = OpenScenarioParser.tl_states[tl_state] @@ -1163,7 +1176,7 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): elif action.find('UserDefinedAction') is not None: user_defined_action = action.find('UserDefinedAction') if user_defined_action.find('CustomCommandAction') is not None: - command = user_defined_action.find('CustomCommandAction').attrib.get('type') + command = str(ParameterRef(user_defined_action.find('CustomCommandAction').attrib.get('type'))) atomic = RunScript(command, base_path=OpenScenarioParser.osc_filepath, name=maneuver_name) elif action.find('PrivateAction') is not None: private_action = action.find('PrivateAction') @@ -1177,7 +1190,8 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): # duration and distance distance = float('inf') duration = float('inf') - dimension = long_maneuver.find("SpeedActionDynamics").attrib.get('dynamicsDimension') + dimension = str(ParameterRef(long_maneuver.find( + "SpeedActionDynamics").attrib.get('dynamicsDimension'))) if dimension == "distance": distance = ParameterRef(long_maneuver.find("SpeedActionDynamics").attrib.get( 'value', float("inf"))) @@ -1195,10 +1209,10 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): # relative velocity to given actor if long_maneuver.find("SpeedActionTarget").find("RelativeTargetSpeed") is not None: relative_speed = long_maneuver.find("SpeedActionTarget").find("RelativeTargetSpeed") - obj = relative_speed.attrib.get('entityRef') + obj = str(ParameterRef(relative_speed.attrib.get('entityRef'))) value = ParameterRef(relative_speed.attrib.get('value', 0)) - value_type = relative_speed.attrib.get('speedTargetValueType') - continuous = bool(strtobool(relative_speed.attrib.get('continuous'))) + value_type = str(ParameterRef(relative_speed.attrib.get('speedTargetValueType'))) + continuous = bool(strtobool(str(ParameterRef(relative_speed.attrib.get('continuous'))))) for traffic_actor in actor_list: if (traffic_actor is not None and 'role_name' in traffic_actor.attributes and @@ -1217,7 +1231,7 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): elif private_action.find('LongitudinalDistanceAction') is not None: long_dist_action = private_action.find("LongitudinalDistanceAction") - obj = long_dist_action.attrib.get('entityRef') + obj = str(ParameterRef(long_dist_action.attrib.get('entityRef'))) for traffic_actor in actor_list: if (traffic_actor is not None and 'role_name' in traffic_actor.attributes and traffic_actor.attributes['role_name'] == obj): @@ -1232,9 +1246,10 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): "Please specify any one attribute of [distance, timeGap]") constraints = long_dist_action.find('DynamicConstraints') - max_speed = constraints.attrib.get('maxSpeed', None) if constraints is not None else None - continues = bool(strtobool(long_dist_action.attrib.get('continuous'))) - freespace = bool(strtobool(long_dist_action.attrib.get('freespace'))) + max_speed = float(ParameterRef(constraints.attrib.get('maxSpeed', None)) + ) if constraints is not None else None + continues = bool(strtobool(str(ParameterRef(long_dist_action.attrib.get('continuous'))))) + freespace = bool(strtobool(str(ParameterRef(long_dist_action.attrib.get('freespace'))))) atomic = KeepLongitudinalGap(actor, reference_actor=obj_actor, gap=gap, gap_type=gap_type, max_speed=max_speed, continues=continues, freespace=freespace, name=maneuver_name) @@ -1252,7 +1267,8 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): # duration and distance distance = float('inf') duration = float('inf') - dimension = lat_maneuver.find("LaneChangeActionDynamics").attrib.get('dynamicsDimension') + dimension = str(ParameterRef(lat_maneuver.find( + "LaneChangeActionDynamics").attrib.get('dynamicsDimension'))) if dimension == "distance": distance = ParameterRef( lat_maneuver.find("LaneChangeActionDynamics").attrib.get('value', float("inf"))) @@ -1266,7 +1282,7 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): name=maneuver_name) elif private_action.find('LaneOffsetAction') is not None: lat_maneuver = private_action.find('LaneOffsetAction') - continuous = bool(strtobool(lat_maneuver.attrib.get('continuous', "true"))) + continuous = bool(strtobool(str(ParameterRef(lat_maneuver.attrib.get('continuous', "true"))))) # Parsing of the different Dynamic shapes is missing lane_target_offset = lat_maneuver.find('LaneOffsetTarget') @@ -1281,7 +1297,7 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): relative_offset = ParameterRef(relative_target_offset.attrib.get('value', 0)) relative_actor = None - relative_actor_name = relative_target_offset.attrib.get('entityRef', None) + relative_actor_name = str(ParameterRef(relative_target_offset.attrib.get('entityRef', None))) for _actor in actor_list: if _actor is not None and 'role_name' in _actor.attributes: if relative_actor_name == _actor.attributes['role_name']: @@ -1305,13 +1321,14 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): master_actor = None for actor_ins in actor_list: if actor_ins is not None and 'role_name' in actor_ins.attributes: - if sync_action.attrib.get('masterEntityRef', None) == actor_ins.attributes['role_name']: + if (str(ParameterRef(sync_action.attrib.get('masterEntityRef', None))) + == actor_ins.attributes['role_name']): master_actor = actor_ins break if master_actor is None: raise AttributeError("Cannot find actor '{}' for condition".format( - sync_action.attrib.get('masterEntityRef', None))) + str(ParameterRef(sync_action.attrib.get('masterEntityRef', None))))) master_position = OpenScenarioParser.convert_position_to_transform( sync_action.find('TargetPositionMaster')) @@ -1327,7 +1344,7 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): elif sync_action.find("FinalSpeed").find("RelativeSpeedToMaster") is not None: relative_speed = sync_action.find("FinalSpeed").find("RelativeSpeedToMaster") final_speed = ParameterRef(relative_speed.attrib.get('value', 0)) - relative_type = relative_speed.attrib.get('speedTargetValueType') + relative_type = float(ParameterRef(relative_speed.attrib.get('speedTargetValueType'))) atomic = SyncArrivalOSC( actor, master_actor, position, master_position, final_speed, relative_to_master=True, relative_type=relative_type, name=maneuver_name) @@ -1335,7 +1352,7 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs): raise AttributeError("Unknown speed action") elif private_action.find('ActivateControllerAction') is not None: private_action = private_action.find('ActivateControllerAction') - activate = strtobool(private_action.attrib.get('longitudinal')) + activate = strtobool(str(ParameterRef(private_action.attrib.get('longitudinal')))) atomic = ChangeAutoPilot(actor, activate, name=maneuver_name) elif private_action.find('ControllerAction') is not None: controller_action = private_action.find('ControllerAction')