-
Notifications
You must be signed in to change notification settings - Fork 61
RJD-1057 (5/5): Remove non-API member functions: Improve responsibility simulator_core<->api #1337
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
RJD-1057 (5/5): Remove non-API member functions: Improve responsibility simulator_core<->api #1337
Conversation
…lized functions for distance calculations for each coordinate system
…nput instead of CanonicalizedLaneletPose
…ded-to-entity-base' into ref/RJD-1057-improve-responsibility-simulator-core-api
…wn() and setStatus() methods
…ded-to-entity-base-refactor' into ref/RJD-1057-improve-responsibility-simulator-core-api
Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
…ze(), guarantee canonicalization of input in API, add exceptions to canonicalize()
… of https://github.com/tier4/scenario_simulator_v2 into ref/RJD-1057-improve-responsibility-simulator-core-api
…ce, move it to distance utils and use globally
…ded-to-entity-base-refactor' into ref/RJD-1057-improve-responsibility-simulator-core-api
…ded-to-entity-base-refactor' into ref/RJD-1057-improve-responsibility-simulator-core-api
|
Checklist for reviewers ☑️All references to "You" in the following text refer to the code reviewer.
|
@TauTheLepton @dmoszynski
Simply put, changes that do not fall under “improve the responsibility division” should be reverted. Note: SimulatorCore, which is obviously a redundant layer, is intended to express the concept of OpenSCENARIO XML 1.3.1 6.1.5 “Abstract ASAM OpenSCENARIO architecture” in code. The names of the member functions beginning with apply / evaluate are derived exactly from the figure in this section. In the future, when scenario_simulator_v2 considers OSI (Open Simulation Interface) support, this layer may become important. |
…-responsibility-simulator-core-api Signed-off-by: Mateusz Palczuk <[email protected]>
The implementations of the removed functions have already been removed and leaving these in a header was an oversight Signed-off-by: Mateusz Palczuk <[email protected]>
…-responsibility-simulator-core-api Signed-off-by: Mateusz Palczuk <[email protected]>
Failure optional scenariosNote This is an experimental check and does not block merging the pull-request. scenario failed: execution_time_test <failure type="SimulationFailure" message="CustomCommandAction typed "exitFailure" was triggered by the named Conditions {"update time checker", "avoid startup"}: {"update time checker": Is the /simulation/interpreter/execution_time/update (= 0.006380000000000000254241072639) is greaterThan 0.005?}, {"avoid startup": Is the simulation time (= 1.800000000000000932587340685131) is greaterThan 1.000000000000000000000000000000?}" /> |
…-responsibility-simulator-core-api Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
Before making any changes, we would like to explain what were our intentions and what are some of the benefits of the changes we have proposed. Based on that and your feedback, we will then change so that the code is as expected and in line with any assumptions. OverviewWe realize some changes made here are subjective and some changes may break some existing practices. Removing templatesWe have observed that the SimulatorCore uses a combination of variadic templates and explicit arguments. What is more, we removed variadic templates with perfect arguments forwarding only in these functions were this did not add any value. Current `master` code examplesUsage of variadic templates + perfect forwardingLines 302 to 306 in b3ec542
Lines 481 to 485 in b3ec542
Usage of explicit argumentsLines 122 to 133 in b3ec542
Lines 252 to 253 in b3ec542
Lines 266 to 268 in b3ec542
Structure changesDistance evaluationWe have noticed many functions in CoordinateSystemConversion actually are used solely for implicit distance calculations (e.g. relative pose was only used to calculate length of the vector3 - distance). For this reason and to make the code more expressive we changed these functions to utilize API distance functions and moved them to DistanceConditionEvaluation class (with changed names). Code exampleCurrent versionFunction Lines 108 to 120 in b3ec542
Usage scenario_simulator_v2/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp Lines 144 to 176 in b3ec542
Proposed changesFunction Lines 147 to 159 in b7b89fa
Usage scenario_simulator_v2/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp Lines 143 to 149 in b7b89fa
Functionality changesEntity checksWe have changed some functionality in the SimulatorCore. For this change we have added This change is very similar to transitioning to using LaneletPose (instead of canonicalized) in communication with API - the canonicalization is responsibility of API. Code examplesCurrent versionLines 108 to 120 in b3ec542
Lines 188 to 204 in b3ec542
Proposed changesLines 147 to 159 in b7b89fa
Lines 177 to 189 in b7b89fa
Note This change to add entity checks in SimulatorCore was also a factor in removing some of the variadic templates. Code exampleCurrent versionLines 540 to 544 in b3ec542
Proposed changesLines 636 to 644 in b7b89fa
Changes visualized in functions signaturesIn hidden sections are all function signatures before and after the proposed changes. You can see that the argument forwarding with variadic templates was removed from all subclasses except SummaryFunctions that can be reverted with no functionality lossThese functions can be reverted to use variadic template, although all of them can be called with only one set of parameters, as the functions called with parameter pack don't have any overloads.
Functions which after reverting will loose functionality - we encourage to leave them changedThese function - if reverted to using variadic template (state from before this PR) - would loose some functionality
|
@TauTheLepton About "Removing templatesIt is true, as you say, that the perfect forwarding destination function may not be overloaded or may have no arguments. Therefore, this change is not acceptable. About "Structure changes / Distance evaluation"Distance calculations are the responsibility of While it is true that Therefore, this change is not acceptable. "Functionality changes / Entity checks"This change is reasonable and may be retained. However, please reconsider the function names. It is not possible to infer what is being processed from the function name. |
…-responsibility-simulator-core-api Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
… same as requestAcquirePosition Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
…-responsibility-simulator-core-api Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]> Bring back distance condition evaluation in syntax (taken from commit "e6ffb819399842b6b3f71a7de816f36fcc01cfe0") Signed-off-by: Mateusz Palczuk <[email protected]> Move entity check to SimulatorCore scope and use in this class Signed-off-by: Mateusz Palczuk <[email protected]> Bring back distance condition evaluation fully + lateral lane changes in syntax (taken from commit "e6ffb819399842b6b3f71a7de816f36fcc01cfe0") Bring back `evaluateLateralRelativeLanes` to `SimulatorCore::CoordinateSystemConversion` Signed-off-by: Mateusz Palczuk <[email protected]> Remove `SimulatorCore::DistanceConditionEvaluation` class Signed-off-by: Mateusz Palczuk <[email protected]> Bring back return type deduction Signed-off-by: Mateusz Palczuk <[email protected]> Remove route clear in `applyAcquirePositionAction` - make implementation mirror the master Signed-off-by: Mateusz Palczuk <[email protected]> Bring back perfect forwarding for API constructor Signed-off-by: Mateusz Palczuk <[email protected]> Move `API::boundingBoxRelativePose` to be groupped with similar functions Signed-off-by: Mateusz Palczuk <[email protected]> Remove lanelet distance function from API Signed-off-by: Mateusz Palczuk <[email protected]> Remove lanelet distance functions Signed-off-by: Mateusz Palczuk <[email protected]>
In the commit 8ecd226, we have changed the following
What hasn't changed
|
|
Hi @TauTheLepton ( CC: @dmoszynski @yamacir-kit @hakuturu583 @YoshinoriTsutake ) First of all, thank you for your significant effort and the extensive work you've put into this pull request. We truly appreciate the time and dedication you invested in tackling the complex task of improving the role separation between This PR sparked a deep and necessary discussion within the team about our core architectural principles. Through these conversations, we've had the opportunity to clarify and reaffirm some fundamental design philosophies that we believe are crucial for the long-term health and maintainability of our codebase. Specifically, we've solidified our stance on two key points:
Based on these clarified principles, we've concluded that the approach taken in this PR, while well-intentioned, moves us in a direction that diverges from our long-term architectural goals. Therefore, we have decided to close this pull request. Please understand that this decision is not a reflection on the quality or effort of your work. On the contrary, your PR was invaluable. It forced us to have this essential conversation and to solidify principles that were previously not explicitly documented. We couldn't have reached this level of clarity without your contribution. Thank you again for your hard work and for helping us sharpen our vision for the project. Best regards, |
Description
Abstract
This pull request aims to improve the responsibility division between
traffic_simulator
API andopenscenario_interpreter
SimulatorCore.The changes include refactoring, renaming functions and reordering them in the source files. So even though the number of changes reported by github is rather high, many of the changes consist of moving functions around with slight if none modifications.
Background
This pull request is one of many that aim to modularize the scenario_simulator_v2.
Details
Canonicalization
The main changes are that canonicalization process (of lanelet pose) is a responsibility of
traffic_simulator
. This way the communication withtraffic_simulator
API is done on NON canonicalized data structures and traffic_simulator has to canonicalize the data.Note
A result of aforementioned changes, most of
cpp_mock_scenarios
had to be adjusted to communicate using regular lanelet pose instead of canonicalized one.This leads to GitHub reporting many lines changed and the PR seem to be big, but many of these changes are simply adjusting
cpp_mock_scenarios
like the following.Before
scenario_simulator_v2/mock/cpp_mock_scenarios/src/collision/crashing_npc.cpp
Lines 54 to 56 in bcc35ae
After
scenario_simulator_v2/mock/cpp_mock_scenarios/src/collision/crashing_npc.cpp
Lines 54 to 56 in f1cb1c2
Important
Because of the change of canonicalization, the NativeLanePosition type in SimulatorCore has been changed
Before
scenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 37 to 39 in bcc35ae
After
scenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 36 to 38 in f1cb1c2
SimulatorCore
This PR focuses on improving the interaction between the API and SimulatorCore.
This is why SimulatorCore needed many modifications.
Below they are broken down into the subclasses of SimulatorCore.
General
Changes include conversion of some SimulatorCore classes member functions to explicitly list arguments instead of using the variadic templates.
For example
applyAddEntityAction
before changescenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 302 to 306 in dbf0c03
and after the change
scenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 332 to 338 in 6c8d04b
Many member functions of
SimulatorCore::ConditionEvaluation
have been changed to include a check whether the Entity exists and if not return NaN or other appropriate default value.For example
SimulatorCore::ConditionEvaluation::evaluateCollisionCondition
before changescenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 540 to 544 in dbf0c03
and after the change
scenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 641 to 649 in 6c8d04b
Others
Function
NonStandardOperation::activateNonUserDefinedControllers
has been moved directly to the SimulatorCore class.CoordinateSystemConversion
SimulatorCore::CoordinateSystemConversion::convert<>
functions have been renamed toconvertToNativeLanePosition
andconvertToNativeWorldPosition
and slightly improved.CoordinateSystemConversion::makeNativeRelativeWorldPosition
functions have been removed, as they were no longer needed.SimulatorCore::CoordinateSystemConversion
have been refactored and moved to a new classSimulatorCore::DistanceConditionEvaluation
as they were only used for distance calculations anyway.DistanceConditionEvaluation
This subclass has been added to group all distance functions. Many functions added to this class are functions moved from
SimulatorCore::CoordinateSystemConversion
.Note
Keep in mind, that due to the fact, that many underlying API functions can be passed some combination of Entity name and position as arguments, many function of this class have been converted to templates to accept different types as arguments.
These functions perform common checks whether an Entity exists (when the name is passed as an argument). These checks have been separated in a
prerequisite
function.CoordinateSystemConversion
class have been removed in favor of new distance functions, because the relative pose was only used for distance calculation.CoordinateSystemConversion::makeNativeRelativeLanePosition
has been removed in favor ofDistanceConditionEvaluation::lateralEntityDistance
andDistanceConditionEvaluation::longitudinalEntityDistance
CoordinateSystemConversion::makeNativeBoundingBoxRelativeLanePosition
has been removed in favor ofDistanceConditionEvaluation::lateralEntityBoundingBoxDistance
andDistanceConditionEvaluation::longitudinalEntityBoundingBoxDistance
CoordinateSystemConversion::makeNativeBoundingBoxRelativeWorldPosition
has been removed in favor ofDistanceConditionEvaluation::euclideanBoundingBoxDistance
DistanceConditionEvaluation::euclideanDistance
has been added for distance calculation.CoordinateSystemConversion::evaluateLateralRelativeLanes
has been changed tolateralRelativeLanes
with some slight modifications.lateralLaneDistance
has been developed to be used instead ofCoordinateSystemConversion::makeNativeRelativeWorldPosition
longitudinalLaneDistance
has been developed to be used instead ofCoordinateSystemConversion::makeNativeRelativeWorldPosition
lateralLaneBoundingBoxDistance
has been developed to be used instead ofCoordinateSystemConversion::makeNativeBoundingBoxRelativeLanePosition
longitudinalLaneBoundingBoxDistance
has been developed to be used instead ofCoordinateSystemConversion::makeNativeBoundingBoxRelativeLanePosition
ActionApplication
activatePerformanceAssertion
has been moved fromNonStandardOperation
class.ConditionEvaluation
evaluateRelativeSpeed
has been divided into part inConditionEvaluation
scenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 622 to 630 in f1cb1c2
and part in
API
scenario_simulator_v2/simulation/traffic_simulator/src/api/api.cpp
Lines 458 to 473 in f1cb1c2
evaluateTimeHeadaway
has been divided into part inConditionEvaluation
scenario_simulator_v2/openscenario/openscenario_interpreter/include/openscenario_interpreter/simulator_core.hpp
Lines 651 to 660 in f1cb1c2
and part in
API
scenario_simulator_v2/simulation/traffic_simulator/src/api/api.cpp
Lines 374 to 389 in f1cb1c2
NonStandardOperation
evaluateCurrentState
evaluateRelativeHeading
TrafficLightsOperation
NonStandardOperation
setConventionalTrafficLightsState
setConventionalTrafficLightConfidence
getConventionalTrafficLightsComposedState
compareConventionalTrafficLightsState
resetConventionalTrafficLightPublishRate
setV2ITrafficLightsState
resetV2ITrafficLightPublishRate
Syntax
Important
Because of the changes listed in
SimulatorCore
, manyopenscenario_interpreter
syntax classes had to be adjusted.For most of the syntax classes the changes were limited only to changing the parent class in inheritance structure, or just using the new functions from
SimulatorCore
rather than the old ones.DistanceCondition
Many changes have been applied to
DistanceCondition
ofopenscenario_interpreter
. Most of these changes are simplifications that don't use the overloaded lambda functions and visitors, but rather just use newly developedSimulatorCore::DistanceConditionEvaluation
member functions.For example the function
DistanceCondition::distance<CoordinateSystem::entity, RelativeDistanceType::euclidianDistance, RoutingAlgorithm::undefined, false>
has been changed fromscenario_simulator_v2/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp
Lines 144 to 176 in dbf0c03
to
scenario_simulator_v2/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp
Lines 143 to 149 in 6c8d04b
The simplification comes from reducing the overloaded lambdas that have identical implementations to just one function call.
ReachPositionCondition
Similarly to
DistanceCondition
the structure has been reworked to not use overloaded lambda functions and visitors, but rather directly call distance function.Distance calculation in
traffic_simulator
For simplicity some distance calculation functions have been added to
traffic_simulator
API so thatopenscenario_interpreter
did not implement distance calculations but could use these functions herescenario_simulator_v2/simulation/traffic_simulator/include/traffic_simulator/api/api.hpp
Lines 245 to 298 in 6c8d04b
EntityBase (
traffic_simulator
)requestSynchronize
In this PR additionally to all other changes, the
EntityBase::requestSynchronize
function has been refactored in order to make it easier to read and understand.Most of the logic code was kept unchanged, but some reformating was applied to use the init-statement to declare variables inside the if statements which in the same time checks whether the value is correct.
What is more, a check whether the entity this synchronize request is applied on is an Ego entity, has been moved to overloaded member function of
EgoEntity
class herescenario_simulator_v2/simulation/traffic_simulator/src/entity/ego_entity.cpp
Lines 279 to 285 in e5f3ce9
References
INTERNAL LINK 1
INTERNAL LINK 2
Destructive Changes
--
Known Limitations
--