Skip to content

Commit

Permalink
Fix parametric entity references (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: romanodanilo <[email protected]>

Signed-off-by: romanodanilo <[email protected]>
  • Loading branch information
romanodanilo authored Jul 11, 2024
1 parent 5999161 commit 3aa8e4d
Show file tree
Hide file tree
Showing 4 changed files with 2,666 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def check_rule(checker_data: models.CheckerData) -> None:
if current_name is not None:
defined_entities.add(current_name)

logging.debug(f"Defined entities : {defined_entities}")
storyboard_node = root.find("Storyboard")
if storyboard_node is None:
logging.error(
Expand All @@ -78,8 +79,30 @@ def check_rule(checker_data: models.CheckerData) -> None:
nodes_with_entity_ref = storyboard_node.xpath(".//*[@entityRef]")

for node_with_entity_ref in nodes_with_entity_ref:
current_name = node_with_entity_ref.get("entityRef")
if current_name is not None and current_name not in defined_entities:
current_entity_ref = node_with_entity_ref.get("entityRef")

if current_entity_ref is None:
continue

has_issue = False

# Check if entityRef points to a declared param
if current_entity_ref.startswith("$"):
current_entity_param_name = current_entity_ref[1:]
current_entity_param_value = utils.get_parameter_value(
root, current_entity_param_name
)
logging.debug(f"current_entity_param_name: {current_entity_param_name}")
logging.debug(f"current_entity_param_value: {current_entity_param_value}")
# Parameter value is assigned to the current_entity_ref to search
# If parameter is not found, None is assigned to current_entity_ref
current_entity_ref = current_entity_param_value

has_issue = (
current_entity_ref is None or current_entity_ref not in defined_entities
)

if has_issue:
xpath = root.getpath(node_with_entity_ref)

issue_id = checker_data.result.register_issue(
Expand All @@ -94,5 +117,5 @@ def check_rule(checker_data: models.CheckerData) -> None:
checker_id=reference_constants.CHECKER_ID,
issue_id=issue_id,
xpath=xpath,
description=f"Entity at {xpath} with id {current_name} not found among defined Entities ",
description=f"Entity at {xpath} with id {current_entity_ref} not found among defined Entities ",
)
186 changes: 186 additions & 0 deletions tests/data/parametric_entity_ref/CutIn.xosc
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="utf-8"?>
<OpenSCENARIO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Schema/OpenSCENARIO.xsd">
<FileHeader revMajor="1" revMinor="3" date="2020-02-21T10:00:00" description="Cut-In example" author="ASAM e.V." />
<ParameterDeclarations>
<ParameterDeclaration parameterType="string" name="owner" value="A2"/>
</ParameterDeclarations>
<CatalogLocations />
<RoadNetwork>
<LogicFile filepath="Databases/AB_RQ31_Straight.xodr" />
</RoadNetwork>
<Entities>
<ScenarioObject name="Ego">
<Vehicle name="HAF" vehicleCategory="car">
<ParameterDeclarations />
<Performance maxSpeed="69.444" maxAcceleration="200" maxDeceleration="10.0" />
<BoundingBox>
<Center x="1.5" y="0.0" z="0.9" />
<Dimensions width="2.1" length="4.5" height="1.8" />
</BoundingBox>
<Axles>
<FrontAxle maxSteering="0.5" wheelDiameter="0.6" trackWidth="1.8" positionX="3.1" positionZ="0.3" />
<RearAxle maxSteering="0.0" wheelDiameter="0.6" trackWidth="1.8" positionX="0.0" positionZ="0.3" />
</Axles>
</Vehicle>
</ScenarioObject>
<ScenarioObject name="A1">
<Vehicle name="Default_Car" vehicleCategory="car">
<ParameterDeclarations />
<Performance maxSpeed="69.444" maxAcceleration="200" maxDeceleration="10.0" />
<BoundingBox>
<Center x="1.4" y="0.0" z="0.8" />
<Dimensions width="2.0" length="4.2" height="1.6" />
</BoundingBox>
<Axles>
<FrontAxle maxSteering="0.5" wheelDiameter="0.5" trackWidth="1.75" positionX="2.8" positionZ="0.25" />
<RearAxle maxSteering="0.0" wheelDiameter="0.5" trackWidth="1.75" positionX="0.0" positionZ="0.25" />
</Axles>
</Vehicle>
</ScenarioObject>
<ScenarioObject name="A2">
<Vehicle name="Default_Car" vehicleCategory="car">
<ParameterDeclarations />
<Performance maxSpeed="69.444" maxAcceleration="200" maxDeceleration="10.0" />
<BoundingBox>
<Center x="1.4" y="0.0" z="0.8" />
<Dimensions width="2.0" length="4.2" height="1.6" />
</BoundingBox>
<Axles>
<FrontAxle maxSteering="0.5" wheelDiameter="0.5" trackWidth="1.75" positionX="2.8" positionZ="0.25" />
<RearAxle maxSteering="0.0" wheelDiameter="0.5" trackWidth="1.75" positionX="0.0" positionZ="0.25" />
</Axles>
</Vehicle>
</ScenarioObject>
</Entities>
<Storyboard>
<Init>
<Actions>
<GlobalAction>
<EnvironmentAction>
<Environment name="Environment1">
<TimeOfDay animation="false" dateTime="2020-02-21T12:00:00" />
<Weather fractionalCloudCover="zeroOktas">
<Sun illuminance="100000.0" azimuth="0.0" elevation="1.571" />
<Fog visualRange="100000.0" />
<Precipitation precipitationType="dry" precipitationIntensity="0.0" />
</Weather>
<RoadCondition frictionScaleFactor="1.0" />
</Environment>
</EnvironmentAction>
</GlobalAction>
<Private entityRef="Ego">
<PrivateAction>
<LongitudinalAction>
<SpeedAction>
<SpeedActionDynamics dynamicsShape="step" value="0" dynamicsDimension="time" />
<SpeedActionTarget>
<AbsoluteTargetSpeed value="27.778" />
</SpeedActionTarget>
</SpeedAction>
</LongitudinalAction>
</PrivateAction>
<PrivateAction>
<TeleportAction>
<Position>
<LanePosition roadId="1" laneId="-3" offset="0.5" s="1000.0" />
</Position>
</TeleportAction>
</PrivateAction>
</Private>
<Private entityRef="A1">
<PrivateAction>
<LongitudinalAction>
<SpeedAction>
<SpeedActionDynamics dynamicsShape="step" value="0" dynamicsDimension="time" />
<SpeedActionTarget>
<AbsoluteTargetSpeed value="27.778" />
</SpeedActionTarget>
</SpeedAction>
</LongitudinalAction>
</PrivateAction>
<PrivateAction>
<TeleportAction>
<Position>
<RelativeLanePosition entityRef="Ego" dLane="0" ds="84.0" />
</Position>
</TeleportAction>
</PrivateAction>
</Private>
<Private entityRef="A2">
<PrivateAction>
<LongitudinalAction>
<SpeedAction>
<SpeedActionDynamics dynamicsShape="step" value="0" dynamicsDimension="time" />
<SpeedActionTarget>
<AbsoluteTargetSpeed value="30.556" />
</SpeedActionTarget>
</SpeedAction>
</LongitudinalAction>
</PrivateAction>
<PrivateAction>
<TeleportAction>
<Position>
<RelativeLanePosition entityRef="Ego" dLane="1" ds="-100.0" />
</Position>
</TeleportAction>
</PrivateAction>
</Private>
</Actions>
</Init>
<Story name="MyStory">
<ParameterDeclarations>
<ParameterDeclaration parameterType="string" name="owner" value="A2" />
</ParameterDeclarations>
<Act name="Act1">
<ManeuverGroup maximumExecutionCount="1" name="Sequence1">
<Actors selectTriggeringEntities="false">
<EntityRef entityRef="$owner" />
</Actors>
<Maneuver name="Maneuver1">
<Event name="Event1" priority="override">
<Action name="Action1">
<PrivateAction>
<LateralAction>
<LaneChangeAction targetLaneOffset="-0.0361164093018">
<LaneChangeActionDynamics dynamicsDimension="distance" dynamicsShape="cubic" value="54.8254917969"/>
<LaneChangeTarget>
<RelativeTargetLane entityRef="Ego" value="0"/>
</LaneChangeTarget>
</LaneChangeAction>
</LateralAction>
</PrivateAction>
</Action>
<StartTrigger>
<ConditionGroup>
<Condition name="StartCondition1" delay="0" conditionEdge="rising">
<ByEntityCondition>
<TriggeringEntities triggeringEntitiesRule="any">
<EntityRef entityRef="$owner" />
</TriggeringEntities>
<EntityCondition>
<DistanceCondition value="20.0" freespace="false" coordinateSystem="road" rule="greaterThan">
<Position>
<RelativeObjectPosition entityRef="Ego" dx="0" dy="0" />
</Position>
</DistanceCondition>
</EntityCondition>
</ByEntityCondition>
</Condition>
</ConditionGroup>
</StartTrigger>
</Event>
</Maneuver>
</ManeuverGroup>
</Act>
</Story>
<StopTrigger>
<ConditionGroup>
<Condition name="End_of_simulation" delay="10.0" conditionEdge="none">
<ByValueCondition>
<StoryboardElementStateCondition storyboardElementType="act" storyboardElementRef="Act1" state="completeState" />
</ByValueCondition>
</Condition>
</ConditionGroup>
</StopTrigger>
</Storyboard>
</OpenSCENARIO>
Loading

0 comments on commit 3aa8e4d

Please sign in to comment.