Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenScenario parameter assignment is broken #832

Open
lasuomela opened this issue Nov 8, 2021 · 15 comments · May be fixed by #833 or #834
Open

OpenScenario parameter assignment is broken #832

lasuomela opened this issue Nov 8, 2021 · 15 comments · May be fixed by #833 or #834
Assignees
Labels
bug Something isn't working OpenSCENARIO

Comments

@lasuomela
Copy link

lasuomela commented Nov 8, 2021

Describe the bug
A clear and concise description of what the bug is.

Hello, I updated the scenario runner from
05a811a
to
e5b06cc

to get OpenScenario ParameterAction support. However, now it seems that the parsing of .xosc files is somehow broken. When a parameter is used in the .xosc file, the name of the parameter is passed on instead of the value assigned to the parameter.

To Reproduce
Steps to reproduce the behavior:

  1. Declare a parameter in .xosc scenario file:
<?xml version="1.0"?>
<OpenSCENARIO>
  <FileHeader revMajor="1" revMinor="0" date="2021-05-04T00:00:00" description="CARLA:Template" author=""/>
  <ParameterDeclarations>
    <ParameterDeclaration name="route_entry_name" parameterType="string" value="Map01_testroute_maneuver"/>
  </ParameterDeclarations>
  1. Use the parameter for something, e.g. retrieve a maneuver from catalog:
<ManeuverGroup maximumExecutionCount="1" name="ManeuverSequence">
  <Actors selectTriggeringEntities="false">
    <EntityRef entityRef="ego_vehicle"/>
  </Actors>
  <CatalogReference catalogName="ManeuverCatalog" entryName="$route_entry_name"/>
</ManeuverGroup>

Expected behavior
Before updating, this retrieved the catalog maneuver with name "Map01_testroute_maneuver" correctly.

Screenshots
Leads to:
Screenshot from 2021-11-08 16-58-42
This seems to affect all parameter usage in the .xosc file. Before updating the scenario runner everything was working well. I suspect the breaking changes are introduced by 8ed24c8, however I couldn't find the cause. Can others reproduce the issue, or could it still be something on my end?

Desktop (please complete the following information):

  • OS: [Ubuntu 20.04
  • CARLA Version 0.9.12 (docker shipped)
  • Python version 3.7

I'm using the scenario runner through the ros-bridge.

Additional context
Add any other context about the problem here.

@lasuomela lasuomela added the bug Something isn't working label Nov 8, 2021
@fabianoboril
Copy link
Collaborator

I just push a new commit that should fix this issue. Please give it a try.

@lasuomela
Copy link
Author

Thanks for the quick reply. I tried the new fix, with that the ouput is
Screenshot from 2021-11-08 19-46-17
So the problem still persists

@fabianoboril
Copy link
Collaborator

Can you share your scenario file? The traceback is different now...

@lasuomela
Copy link
Author

lasuomela commented Nov 8, 2021

So I managed to solve the error message for the route maneuver catalog, resolving the error message from my previous comment by adding a string conversion to the line from your fix:

         entry = catalogs[catalog_reference.attrib.get("catalogName")][ParameterRef(catalog_reference.attrib.get("entryName"))]

->

         entry = catalogs[catalog_reference.attrib.get("catalogName")][str(ParameterRef(catalog_reference.attrib.get("entryName")))]

However, after solving I'm running into similar issues with the rest of the parameters too:

Screenshot from 2021-11-08 23-36-24

This too was solved by adding ParameterRef in openscenario_parser get_weather_from_env_action(), line 477:

        carla_weather.sun_altitude_angle = math.degrees(float(sun.attrib.get('elevation', 0)))

->

        carla_weather.sun_altitude_angle = math.degrees(float(ParameterRef(sun.attrib.get('elevation', 0))))

But the openscenario_parser.py seems to be full of this kind of catalog refs, meaning adding this in a lot places. Should this be addressed here, or on a higher level? As I said, my scenario file was working fine with the earlier commit of scenario runner, so I think there was a change introduced somewhere that causes the parameter parsing to not properly work in the master.

Also, the problem doesn't just affect catalogs.

This works (check 3rd last line):

<?xml version="1.0"?>
<OpenSCENARIO>
  <FileHeader revMajor="1" revMinor="0" date="2021-05-04T00:00:00" description="CARLA:VisualNavigatorTemplate" author=""/>
  <ParameterDeclarations>
    <ParameterDeclaration name="town_name" parameterType="string" value="Town01"/>
  </ParameterDeclarations>
  <CatalogLocations>
  </CatalogLocations>
  <RoadNetwork>
    <LogicFile filepath="Town01"/>
    <SceneGraphFile filepath=""/>
  </RoadNetwork>

This doesn't (check 3rd last line):

<?xml version="1.0"?>
<OpenSCENARIO>
  <FileHeader revMajor="1" revMinor="0" date="2021-05-04T00:00:00" description="CARLA:VisualNavigatorTemplate" author=""/>
  <ParameterDeclarations>
    <ParameterDeclaration name="town_name" parameterType="string" value="Town01"/>
  </ParameterDeclarations>
  <CatalogLocations>
  </CatalogLocations>
  <RoadNetwork>
    <LogicFile filepath="$town_name"/>
    <SceneGraphFile filepath=""/>
  </RoadNetwork>

So I think it's a general bug related to parameter parsing.

Here is my scenario file for reference anyway. I will be deleting it once we resolve this issue.

<?xml version="1.0"?>
<OpenSCENARIO>
  <FileHeader revMajor="1" revMinor="0" date="2021-05-04T00:00:00" description="CARLA:Template" author=""/>
  <ParameterDeclarations>
    <ParameterDeclaration name="town_name" parameterType="string" value="Town01"/>
    <ParameterDeclaration name="global_extractor_name" parameterType="string" value="XXX"/>
    <ParameterDeclaration name="local_extractor_name" parameterType="string" value="XXX"/>
    <ParameterDeclaration name="local_matcher_name" parameterType="string" value="XXX"/>
    <ParameterDeclaration name="gallery_global_descriptor_path" parameterType="string" value="XXX"/>
    <ParameterDeclaration name="gallery_local_descriptor_path" parameterType="string" value="XXX"/>
    <ParameterDeclaration name="image_gallery_path" parameterType="string" value="XXX"/>
    <ParameterDeclaration name="gallery_sfm_path" parameterType="string" value="XXX"/>
    <ParameterDeclaration name="localization_frequence" parameterType="string" value="2.0"/>
    <ParameterDeclaration name="top_k_matches" parameterType="string" value="15"/>
    <ParameterDeclaration name="sun_intensity" parameterType="string" value="1.0"/>
    <ParameterDeclaration name="sun_elevation" parameterType="string" value="1.31"/>
    <ParameterDeclaration name="precipitation_type" parameterType="string" value="dry"/>
    <ParameterDeclaration name="precipitation_intensity" parameterType="string" value="0.0"/>
    <ParameterDeclaration name="route_entry_name" parameterType="string" value="Map01_testroute_maneuver"/>
    <ParameterDeclaration name="target_speed" parameterType="string" value="8.0"/>
    <ParameterDeclaration name="log_file_path" parameterType="string" value="/results/test_run.json"/>
    <ParameterDeclaration name="log_results" parameterType="string" value="true"/>
    <ParameterDeclaration name="scenario_success" parameterType="string" value=""/>
    <ParameterDeclaration name="controller_entry_name" parameterType="string" value="VisualNavigatingAgent"/>
    <ParameterDeclaration name="goal_location_x" parameterType="string" value="180.0"/>
    <ParameterDeclaration name="goal_location_y" parameterType="string" value="133.0"/>
    <ParameterDeclaration name="goal_location_tolerance" parameterType="string" value="2.0"/>
    <ParameterDeclaration name="logger_script_path" parameterType="string" value="/opt/ad-runner/src/place_reg_ad/utils/run-scenario-log.sh"/>
  </ParameterDeclarations>
  <CatalogLocations>
    <ControllerCatalog>
      <Directory path="catalogs"/>
    </ControllerCatalog>
    <VehicleCatalog>
      <Directory path="catalogs"/>
    </VehicleCatalog>
    <EnvironmentCatalog>
      <Directory path="catalogs"/>
    </EnvironmentCatalog>
    <ManeuverCatalog>
      <Directory path="catalogs"/>
    </ManeuverCatalog>
  </CatalogLocations>
  <RoadNetwork>
    <LogicFile filepath="$town_name"/>
    <SceneGraphFile filepath=""/>
  </RoadNetwork>
  <Entities>
    <ScenarioObject name="ego_vehicle">
      <CatalogReference catalogName="VehicleCatalog" entryName="vehicle.tesla.model3"/>
    </ScenarioObject>
  </Entities>
  <Storyboard>
    <Init>
      <Actions>
        <GlobalAction>
          <EnvironmentAction>
            <CatalogReference catalogName="EnvironmentCatalog" entryName="Weather">
              <ParameterAssignments>
                <ParameterAssignment parameterRef="sun_intensity" value="$sun_intensity"/>
                <ParameterAssignment parameterRef="sun_elevation" value="$sun_elevation"/>
                <ParameterAssignment parameterRef="precipitation_type" value="$precipitation_type"/>
                <ParameterAssignment parameterRef="precipitation_intensity" value="$precipitation_intensity"/>
              </ParameterAssignments>
            </CatalogReference>
          </EnvironmentAction>
        </GlobalAction>
        <Private entityRef="ego_vehicle">       
          <PrivateAction>
            <ControllerAction>
                <AssignControllerAction>
                  <CatalogReference catalogName="ControllerCatalog" entryName="">
                    <ParameterAssignments>
                      <ParameterAssignment parameterRef="global_extractor_name" value="$global_extractor_name"/>
                      <ParameterAssignment parameterRef="local_extractor_name" value="$local_extractor_name"/>
                      <ParameterAssignment parameterRef="local_matcher_name" value="$local_matcher_name"/>
                      <ParameterAssignment parameterRef="gallery_global_descriptor_path" value="$gallery_global_descriptor_path"/>
                      <ParameterAssignment parameterRef="gallery_local_descriptor_path" value="$gallery_local_descriptor_path"/>
                      <ParameterAssignment parameterRef="image_gallery_path" value="$image_gallery_path"/>
                      <ParameterAssignment parameterRef="gallery_sfm_path" value="$gallery_sfm_path"/>
                      <ParameterAssignment parameterRef="localization_frequence" value="$localization_frequence"/>
                      <ParameterAssignment parameterRef="top_k_matches" value="$top_k_matches"/>
                    </ParameterAssignments>
                  </CatalogReference>
                </AssignControllerAction>
                <OverrideControllerValueAction>
                    <Throttle value="0" active="false" />
                    <Brake value="0" active="false" />
                    <Clutch value="0" active="false" />
                    <ParkingBrake value="0" active="false" />
                    <SteeringWheel value="0" active="false" />
                    <Gear number="0" active="false" />
                </OverrideControllerValueAction>
            </ControllerAction>
          </PrivateAction>
          <PrivateAction>
              <LongitudinalAction>
                  <SpeedAction>
                      <SpeedActionDynamics dynamicsShape="step" value="10" dynamicsDimension="distance"/>
                      <SpeedActionTarget>
                          <AbsoluteTargetSpeed value="$target_speed"/>
                      </SpeedActionTarget>
                  </SpeedAction>
              </LongitudinalAction>
          </PrivateAction>
        </Private>
      </Actions>
    </Init>
    <Story name="MyStory">
      <Act name="Behavior">

        <ManeuverGroup maximumExecutionCount="1" name="ManeuverSequence">
          <Actors selectTriggeringEntities="false">
            <EntityRef entityRef="ego_vehicle"/>
          </Actors>
          <CatalogReference catalogName="ManeuverCatalog" entryName="$route_entry_name"/>
        </ManeuverGroup>

        <StartTrigger>
          <ConditionGroup>
            <Condition name="overall_StartCondition" delay="0" conditionEdge="none">
              <ByValueCondition>
                <SimulationTimeCondition value="0" rule = "greaterThan"/>
              </ByValueCondition>
            </Condition>
          </ConditionGroup>
        </StartTrigger>

        <StopTrigger>
          <ConditionGroup>
            <Condition name="pr_criteria_DrivenDistanceTest" delay="0" conditionEdge="rising">
              <ByValueCondition>
                <StoryboardElementStateCondition storyboardElementType="act" storyboardElementRef="Loggers" state="completeState"/>
              </ByValueCondition>
            </Condition>
          </ConditionGroup>
        </StopTrigger>

      </Act>

      <Act name="Loggers">
        <ManeuverGroup maximumExecutionCount="1" name="logger_group">
          <Actors selectTriggeringEntities="false">
            <EntityRef entityRef="ego_vehicle"/>
          </Actors>

          <Maneuver name="logger_maneuver">
            <Event name="success_log_event" priority="overwrite">
              <Action name="success_log_command">
                <GlobalAction>
                  <ParameterAction parameterRef="scenario_success">
                    <SetAction value="true" />
                  </ParameterAction>
                </GlobalAction>
              </Action>
              <StartTrigger>
                <ConditionGroup>
                  <Condition name="success_log_startCondition" delay="0" conditionEdge="rising">
                    <ByEntityCondition>
                      <TriggeringEntities triggeringEntitiesRule="any">
                        <EntityRef entityRef="ego_vehicle"/>
                      </TriggeringEntities>
                      <EntityCondition>
                        <ReachPositionCondition tolerance="$goal_location_tolerance">
                          <Position>
                            <WorldPosition x="$goal_location_x" y="$goal_location_y" />
                          </Position>
                        </ReachPositionCondition>
                      </EntityCondition>
                    </ByEntityCondition>
                  </Condition>
                </ConditionGroup>
              </StartTrigger>
            </Event>

            <Event name="failure_log_event" priority="overwrite">
              <Action name="failure_log_command">
                <GlobalAction>
                  <ParameterAction parameterRef="scenario_success">
                      <SetAction value="false" />
                  </ParameterAction>
                </GlobalAction>
              </Action>
              <StartTrigger>
                <ConditionGroup>
                  <Condition name="failure_log_startCondition" delay="0" conditionEdge="rising">
                    <ByEntityCondition>
                      <TriggeringEntities triggeringEntitiesRule="any">
                        <EntityRef entityRef="ego_vehicle"/>
                      </TriggeringEntities>
                      <EntityCondition>
                        <CollisionCondition>
                          <ByType type="miscellaneous"/>
                        </CollisionCondition>
                      </EntityCondition>
                    </ByEntityCondition>
                  </Condition>
                </ConditionGroup>
              </StartTrigger>
            </Event>

            <Event name="log_scenario_results_event" priority="overwrite">
              <Action name="results_log_command">
                <UserDefinedAction>
                  <CustomCommandAction type="bash $logger_script_path 
                  -a $town_name 
                  -b $global_extractor_name 
                  -c $local_extractor_name 
                  -d $local_matcher_name 
                  -e $gallery_global_descriptor_path 
                  -f $gallery_local_descriptor_path 
                  -g $image_gallery_path 
                  -h $gallery_sfm_path 
                  -i $localization_frequence 
                  -j $top_k_matches 
                  -k $sun_intensity 
                  -l $sun_elevation 
                  -m $precipitation_type 
                  -n $precipitation_intensity 
                  -o $route_entry_name 
                  -p $target_speed 
                  -q $log_file_path 
                  -r $log_results
                  -s $scenario_success 
                  "/>
                </UserDefinedAction>
              </Action>
              <StartTrigger>
                <ConditionGroup>
                  <Condition name="logger_act_failure_stopcondition" delay="0" conditionEdge="rising">
                    <ByValueCondition>
                      <StoryboardElementStateCondition storyboardElementType="event" storyboardElementRef="failure_log_event" state="completeState"/>
                    </ByValueCondition>
                  </Condition>
                </ConditionGroup>
                <ConditionGroup>
                  <Condition name="logger_act_success_stopcondition" delay="0" conditionEdge="rising">
                    <ByValueCondition>
                      <StoryboardElementStateCondition storyboardElementType="event" storyboardElementRef="success_log_event" state="completeState"/>
                    </ByValueCondition>
                  </Condition>
                </ConditionGroup>
              </StartTrigger>
            </Event>
          </Maneuver>

        </ManeuverGroup>
        <StartTrigger>
          <ConditionGroup>
            <Condition name="overall_logger_StartCondition" delay="0" conditionEdge="none">
              <ByValueCondition>
                <SimulationTimeCondition value="0" rule = "greaterThan"/>
              </ByValueCondition>
            </Condition>
          </ConditionGroup>
        </StartTrigger>

        <StopTrigger>
          <ConditionGroup>
            <Condition name="logger_act_failure_stopcondition" delay="0" conditionEdge="rising">
              <ByValueCondition>
                <StoryboardElementStateCondition storyboardElementType="event" storyboardElementRef="failure_log_event" state="completeState"/>
              </ByValueCondition>
            </Condition>
          </ConditionGroup>
          <ConditionGroup>
            <Condition name="logger_act_success_stopcondition" delay="0" conditionEdge="rising">
              <ByValueCondition>
                <StoryboardElementStateCondition storyboardElementType="event" storyboardElementRef="success_log_event" state="completeState"/>
              </ByValueCondition>
            </Condition>
          </ConditionGroup>
        </StopTrigger>
        
      </Act>
    </Story>
    <StopTrigger>
      <ConditionGroup>
        <Condition name="scenario_endcondition" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <StoryboardElementStateCondition storyboardElementType="act" storyboardElementRef="Loggers" state="completeState"/>
          </ByValueCondition>
        </Condition>
      </ConditionGroup>
    </StopTrigger>
  </Storyboard>
</OpenSCENARIO>

@lasuomela
Copy link
Author

Actually, here's the minimum steps to reproduce, based on making the map choice a parameter in the FollowLeadingVehicle.xosc example (changes only on lines 6 and 11, compared to the original):

<?xml version="1.0"?>
<OpenSCENARIO>
  <FileHeader revMajor="1" revMinor="0" date="2019-06-25T00:00:00" description="CARLA:FollowLeadingVehicle" author=""/>
  <ParameterDeclarations>
    <ParameterDeclaration name="leadingSpeed" parameterType="double" value="2.0"/>
    <ParameterDeclaration name="townName" parameterType="string" value="Town01"/>
  </ParameterDeclarations>
  <CatalogLocations>
  </CatalogLocations>
  <RoadNetwork>
    <LogicFile filepath="$townName"/>
    <SceneGraphFile filepath=""/>
  </RoadNetwork>
  <Entities>
    <ScenarioObject name="ego_vehicle">
      <Vehicle name="vehicle.lincoln.mkz2017" vehicleCategory="car">
        <ParameterDeclarations/>
        <Performance maxSpeed="69.444" maxAcceleration="10.0" 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>
        <Properties>
          <Property name="type" value="ego_vehicle"/>
          <Property name="color" value="0,0,255"/>
        </Properties>
      </Vehicle>
    </ScenarioObject>
    <ScenarioObject name="adversary">
      <Vehicle name="vehicle.lincoln.mkz2017" vehicleCategory="car">
        <ParameterDeclarations/>
        <Performance maxSpeed="69.444" maxAcceleration="10.0" 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>
        <Properties>
          <Property name="type" value="simulation"/>
          <Property name="color" value="255,0,0"/>
        </Properties>
      </Vehicle>
    </ScenarioObject>
  </Entities>
  <Storyboard>
    <Init>
      <Actions>
        <GlobalAction>
          <EnvironmentAction>
            <Environment name="Environment1">
              <TimeOfDay animation="false" dateTime="2019-06-25T12:00:00"/>
              <Weather cloudState="free">
                <Sun intensity="1.0" azimuth="0.0" elevation="1.31"/>
                <Fog visualRange="100000.0"/>
                <Precipitation precipitationType="dry" intensity="0.0"/>
              </Weather>
              <RoadCondition frictionScaleFactor="1.0"/>
            </Environment>
          </EnvironmentAction>
        </GlobalAction>
        <Private entityRef="ego_vehicle">
          <PrivateAction>
            <TeleportAction>
              <Position>
                <WorldPosition x="150" y="133" z="0" h="0"/>
              </Position>
            </TeleportAction>
          </PrivateAction>          
          <PrivateAction>
            <ControllerAction>
                <AssignControllerAction>
                    <Controller name="EgoVehicleAgent">
                        <Properties>
                            <Property name="module" value="carla_ros_scenario_runner.ros_vehicle_control" />
                            <Property name="launch" value="carla_ad_agent.launch"/>
                            <Property name="launch-package" value="carla_ad_agent"/>
                        </Properties>
                    </Controller>
                </AssignControllerAction>
                <OverrideControllerValueAction>
                    <Throttle value="0" active="false" />
                    <Brake value="0" active="false" />
                    <Clutch value="0" active="false" />
                    <ParkingBrake value="0" active="false" />
                    <SteeringWheel value="0" active="false" />
                    <Gear number="0" active="false" />
                </OverrideControllerValueAction>
            </ControllerAction>
        </PrivateAction>
        </Private>
        <Private entityRef="adversary">
          <PrivateAction>
            <TeleportAction>
              <Position>
                <WorldPosition x="190" y="133" z="0" h="0"/>
              </Position>
            </TeleportAction>
          </PrivateAction>
        </Private>
      </Actions>
    </Init>
    <Story name="MyStory">
      <Act name="Behavior">
        <ManeuverGroup maximumExecutionCount="1" name="ManeuverSequence">
          <Actors selectTriggeringEntities="false">
            <EntityRef entityRef="adversary"/>
          </Actors>
          <Maneuver name="FollowLeadingVehicleManeuver">
            <Event name="LeadingVehicleKeepsVelocity" priority="overwrite">
              <Action name="LeadingVehicleKeepsVelocity">
                <PrivateAction>
                  <LongitudinalAction>
                    <SpeedAction>
                      <SpeedActionDynamics dynamicsShape="step" value="100" dynamicsDimension="distance"/>
                      <SpeedActionTarget>
                        <AbsoluteTargetSpeed value="$leadingSpeed"/>
                      </SpeedActionTarget>
                    </SpeedAction>
                  </LongitudinalAction>
                </PrivateAction>
              </Action>
              <StartTrigger>
                <ConditionGroup>
                  <Condition name="StartCondition" delay="0" conditionEdge="rising">
                    <ByEntityCondition>
                      <TriggeringEntities triggeringEntitiesRule="any">
                        <EntityRef entityRef="ego_vehicle"/>
                      </TriggeringEntities>
                      <EntityCondition>
                        <RelativeDistanceCondition entityRef="adversary" relativeDistanceType="cartesianDistance" value="40.0" freespace="false" rule="lessThan"/>
                      </EntityCondition>
                    </ByEntityCondition>
                  </Condition>
                </ConditionGroup>
              </StartTrigger>
            </Event>
          </Maneuver>
        </ManeuverGroup>
        <StartTrigger>
          <ConditionGroup>
            <Condition name="OverallStartCondition" delay="0" conditionEdge="rising">
              <ByEntityCondition>
                <TriggeringEntities triggeringEntitiesRule="any">
                  <EntityRef entityRef="ego_vehicle"/>
                </TriggeringEntities>
                <EntityCondition>
                  <TraveledDistanceCondition value="1.0"/>
                </EntityCondition>
              </ByEntityCondition>
            </Condition>
            <Condition name="StartTime" delay="0" conditionEdge="rising">
              <ByValueCondition>
                <SimulationTimeCondition value="0" rule="equalTo"/>
              </ByValueCondition>
            </Condition>
          </ConditionGroup>
        </StartTrigger>
        <StopTrigger>
          <ConditionGroup>
            <Condition name="EndCondition" delay="0" conditionEdge="rising">
              <ByEntityCondition>
                <TriggeringEntities triggeringEntitiesRule="any">
                  <EntityRef entityRef="ego_vehicle"/>
                </TriggeringEntities>
                <EntityCondition>
                  <TraveledDistanceCondition value="100.0"/>
                </EntityCondition>
              </ByEntityCondition>
            </Condition>
          </ConditionGroup>
        </StopTrigger>
      </Act>
    </Story>
    <StopTrigger>
      <ConditionGroup>
        <Condition name="criteria_RunningStopTest" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <ParameterCondition parameterRef="" value="" rule="lessThan"/>
          </ByValueCondition>
        </Condition>
        <Condition name="criteria_RunningRedLightTest" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <ParameterCondition parameterRef="" value="" rule="lessThan"/>
          </ByValueCondition>
        </Condition>
        <Condition name="criteria_WrongLaneTest" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <ParameterCondition parameterRef="" value="" rule="lessThan"/>
          </ByValueCondition>
        </Condition>
        <Condition name="criteria_OnSidewalkTest" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <ParameterCondition parameterRef="" value="" rule="lessThan"/>
          </ByValueCondition>
        </Condition>
        <Condition name="criteria_KeepLaneTest" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <ParameterCondition parameterRef="" value="" rule="lessThan"/>
          </ByValueCondition>
        </Condition>
        <Condition name="criteria_CollisionTest" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <ParameterCondition parameterRef="" value="" rule="lessThan"/>
          </ByValueCondition>
        </Condition>
        <Condition name="criteria_DrivenDistanceTest" delay="0" conditionEdge="rising">
          <ByValueCondition>
            <ParameterCondition parameterRef="distance_success" value="100" rule="lessThan"/>
          </ByValueCondition>
        </Condition>
      </ConditionGroup>
    </StopTrigger>
  </Storyboard>
</OpenSCENARIO>

Running this through the ros-bridge rviz2-plugin leads to
Screenshot from 2021-11-09 00-48-45
on my machine.

@fabianoboril fabianoboril linked a pull request Nov 9, 2021 that will close this issue
@fabianoboril
Copy link
Collaborator

fabianoboril commented Nov 9, 2021

Hi,
I pushed a new PR that addresses this problem. In fact, there were some considerable changes to enable OSC ParameterActions, that allow changing parameters at runtime. Unfortunately, that required quite some rework under the surface of scenariorunner. I hope I fixed all relevant locations. I tested it with your sample code, which seems to work now.

Please give it a try, and let me know if it solved your issues.

@lasuomela lasuomela linked a pull request Nov 9, 2021 that will close this issue
@lasuomela
Copy link
Author

lasuomela commented Nov 9, 2021

Hi,
I was working on the same changes. I cross-checked our changes to make sure most cases are handled. I also updated the ParameterRef class to handle other data types than float. See my linked PR.

But one more thing. With the changes you suggested, the ParameterAction wasn't working. This was because the config file is parsed at scenario init, so any parameters that would be affected by ParameterAction were actually hard coded at init. Because of this, ParameterAction correctly modified the parameter values stored by CarlaDataProvider, but these new values weren't accessed when evaluating Actions such as UserDefinedAction.

I resolved this for UserDefinedAction by moving parameter value resolving into RunScript.update() in atomic_behaviors.py, which is evaluated at runtime. Changes made into parameter values by ParameterAction are now correctly reflected in parameters supplied to UserDefinedAction. I don't know if this issue comes up when using parameters affected by ParameterAction with Actions types other than UserDefinedAction. To avoid circular imports, I had to move ParameterRef definition into it's own file. The solution isn't perfect, but this PR should extend the support for ParameterAction atleast a bit.

Please comment on style and naming conventions if necessary, I haven't contributed before. Thanks for your attention on the issue, this really helped me a lot!

@fabianoboril
Copy link
Collaborator

Hi,
ah good to see that you went into the code as well. What I am not getting from your statement: Are you saying my new PR is breaking ParameterActions? It shouldn't, but I haven't tested that part yet. It was just a quick fix to get your things working.

In the past, we went over the XOSC file and basically replaced all parameter calls with the default values. However, to enable dynamic parameters, the ParameterRef class was introduced. The problem that arises is that all xml-tree accesses should be routed through ParameterRef (aka attrib.get(value) --> ParameterRef(attrib.get(value))). This was forgotten for some places, and my PR intended to fix this.

@lasuomela
Copy link
Author

Hi,
Looking at ParameterRef implementation, it seems to me that running str(ParameterRef(parameter)) retrieves the value of the parameter held in CarlaDataProvider at the time of the call. Since this is now being called in openscenario_parser that is run once at the initialization of scenario, it means that the xmltree values are hard coded to the parameter values present at the initialization of the scenario, and ParameterAction has no effect on the xml tree.

This is why I moved the ParameterRef for UserDefinedAction into the atomic behaviour update() method. That is evaluated at runtime, not at scenario initialization. I tried the both ways, and this was the one that worked. Calling ParameterRef in openscenario_parser led to the parameter value in the xmltree staying the same despite ParameterAction.

I suppose other maneuvers also might need this modification?

@fabianoboril
Copy link
Collaborator

Well, the problem is that we construct the entire behavior tree for the scenario at the very beginning. If that construction fails, because a ParameterRef has to be converted to float/str/whatever, we have to do the conversion. But then, even if this is very late in the scenario, the value is already converted and may not be updated. That basically would mean that everything that can be a parameter has to be fowarded to the corresponding atomics and interpreted at runtime.

@lasuomela
Copy link
Author

lasuomela commented Nov 9, 2021 via email

@fabianoboril
Copy link
Collaborator

I guess, if we touch it now, it is better to do it right ;) Do you want to give it a try?

@lasuomela
Copy link
Author

Hmm. What would it require on code level? From how I understand the code, this would mean doing the same thing I did for UserDefinedAction for

  1. atomic behavior constructions in openscenario_parser/convert_maneuver_to_atomic()
  2. atomic condition constructions in openscenario_parser/convert_condition_to_atomic()
  3. Reworking openscenario_parser functions such as get_weather_from_env_action() into functions that are evaluated at runtime, in a similar fashion to the the atomi conditions/behaviors
  4. Something more?

All of this seems a bit much to do by myself, but I could do one piece for starters. For example rework the functions in convert_maneuver_to_atomic().

@lasuomela
Copy link
Author

Hello @fabianoboril, I began implementing the runtime parameterRef resolution for atomic behaviours. I started by implementing the functionality for AbsoluteTargetSpeed and RelativeTargetSpeed OSC instructions. Could you check the included commit to determine if my approach is okay?

The commit can be found here.

The relevant changes can be found in openscenario_parser.py lines 1051-1089
and atomic_behaviors.py lines 443-662 (class ChangeActorTargetSpeed(AtomicBehavior)).

Please let me know if this seems good, and I'll implement the changes for the rest of the atomic behaviors.

@lasuomela
Copy link
Author

Hello @fabianoboril ! (Tagging @germanros1987 in case he's not actively working on Carla at the moment.)

PR #834 now intoduces ParameterAction support to all OpenSCENARIO Actions - the parameter values are now resolved during runtime inside the AtomicBehaviors. I tested each of the actions with ParameterAction and they now seem to work correctly. Could you review the changes, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OpenSCENARIO
Projects
None yet
2 participants