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

[tmp] RJD-1057 (3/5): Remove non-API member functions: EntityManager’s member functions forwarded to EntityBase (1/2) #1333

Draft
wants to merge 51 commits into
base: RJD-1057-traffic-lights-tests
Choose a base branch
from

Conversation

TauTheLepton
Copy link
Contributor

@TauTheLepton TauTheLepton commented Jul 31, 2024

Description

DO NOT MERGE | THIS IS A TEMPORARY PR | WHEN THE RIGHT TIME COMES, A CLONE WILL BE CAST TO MASTER

Abstract

This pull request introduces the change of exposing direct access to Entity objects through the API. This change increases flexibility of using the API and removes the need to have many forwarding functions to Entities member functions.

Background

This pull request is one of many that aim to modularize the scenario_simulator_v2.

Details

The main goal of this PR was to remove numerous member functions of EntityManager (and subsequently some of API too) that forwarded calls to Entities member functions:

#define FORWARD_TO_ENTITY(IDENTIFIER, ...) \
/*! \
@brief Forward to arguments to the EntityBase::IDENTIFIER function. \
@return return value of the EntityBase::IDENTIFIER function. \
@note This function was defined by FORWARD_TO_ENTITY macro.         \
*/ \
template <typename... Ts> \
decltype(auto) IDENTIFIER(const std::string & name, Ts &&... xs) __VA_ARGS__ \
try { \
return entities_.at(name)->IDENTIFIER(std::forward<decltype(xs)>(xs)...); \
} catch (const std::out_of_range &) { \
THROW_SEMANTIC_ERROR("entity : ", name, "does not exist"); \
} \
static_assert(true, "")
// clang-format on
FORWARD_TO_ENTITY(activateOutOfRangeJob, );
FORWARD_TO_ENTITY(asFieldOperatorApplication, const);
FORWARD_TO_ENTITY(cancelRequest, );
FORWARD_TO_ENTITY(get2DPolygon, const);
FORWARD_TO_ENTITY(getBehaviorParameter, const);
FORWARD_TO_ENTITY(getBoundingBox, const);
FORWARD_TO_ENTITY(getCanonicalizedStatusBeforeUpdate, const);
FORWARD_TO_ENTITY(getCurrentAccel, const);
FORWARD_TO_ENTITY(getCurrentTwist, const);
FORWARD_TO_ENTITY(getDefaultMatchingDistanceForLaneletPoseCalculation, const);
FORWARD_TO_ENTITY(getEntityType, const);
FORWARD_TO_ENTITY(getEntityTypename, const);
FORWARD_TO_ENTITY(getLinearJerk, const);
FORWARD_TO_ENTITY(getRouteLanelets, const);
FORWARD_TO_ENTITY(getStandStillDuration, const);
FORWARD_TO_ENTITY(getTraveledDistance, const);
FORWARD_TO_ENTITY(isControlledBySimulator, );
FORWARD_TO_ENTITY(laneMatchingSucceed, const);
FORWARD_TO_ENTITY(reachPosition, const);
FORWARD_TO_ENTITY(requestAcquirePosition, );
FORWARD_TO_ENTITY(requestAssignRoute, );
FORWARD_TO_ENTITY(requestClearRoute, );
FORWARD_TO_ENTITY(requestFollowTrajectory, );
FORWARD_TO_ENTITY(requestLaneChange, );
FORWARD_TO_ENTITY(requestSynchronize, );
FORWARD_TO_ENTITY(requestWalkStraight, );
FORWARD_TO_ENTITY(setAcceleration, );
FORWARD_TO_ENTITY(setAccelerationLimit, );
FORWARD_TO_ENTITY(setAccelerationRateLimit, );
FORWARD_TO_ENTITY(setBehaviorParameter, );
FORWARD_TO_ENTITY(setControlledBySimulator, );
FORWARD_TO_ENTITY(setDecelerationLimit, );
FORWARD_TO_ENTITY(setDecelerationRateLimit, );
FORWARD_TO_ENTITY(setLinearJerk, );
FORWARD_TO_ENTITY(setLinearVelocity, );
FORWARD_TO_ENTITY(setMapPose, );
FORWARD_TO_ENTITY(setTwist, );
FORWARD_TO_ENTITY(setVelocityLimit, );
FORWARD_TO_ENTITY(requestSpeedChange, );

This has largely been achieved by exposing direct access to Entity and its member functions through the API::getEntity function:

auto getEntity(const std::string & name) const -> std::shared_ptr<entity::EntityBase>;

The following change was to adjust all cpp mock scenarios to use the new interface.
This is the main reason why this PR is so large - all mock scenarios had to be corrected.

Scenarios using the new interface have been changed similarly to the example below.
Before:

void onUpdate() override
{
if (api_.isInLanelet("ego", 34408, 0.1)) {
stop(cpp_mock_scenarios::Result::SUCCESS);
}
}
void onInitialize() override
{
api_.spawn(
"ego",
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34741, 10.0, 0.0, api_.getHdmapUtils()),
getVehicleParameters());
api_.setEntityStatus(
"ego",
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34513, 0.0, 0.0, api_.getHdmapUtils()),
traffic_simulator::helper::constructActionStatus(10));
api_.requestSpeedChange("ego", 10, true);
const geometry_msgs::msg::Pose goal_pose = traffic_simulator::pose::toMapPose(
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34408, 1.0, 0.0, api_.getHdmapUtils()));
api_.requestAcquirePosition("ego", goal_pose);
}

After:
void onUpdate() override
{
if (api_.getEntity("ego")->isInLanelet(34408, 0.1)) {
stop(cpp_mock_scenarios::Result::SUCCESS);
}
}
void onInitialize() override
{
api_.spawn(
"ego",
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34741, 10.0, 0.0, api_.getHdmapUtils()),
getVehicleParameters());
auto entity = api_.getEntity("ego");
entity->setStatus(
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34513, 0.0, 0.0, api_.getHdmapUtils()),
traffic_simulator::helper::constructActionStatus(10));
entity->requestSpeedChange(10, true);
const geometry_msgs::msg::Pose goal_pose = traffic_simulator::pose::toMapPose(
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34408, 1.0, 0.0, api_.getHdmapUtils()));
entity->requestAcquirePosition(goal_pose);
}

Similar changes had to be applied to the whole codebase relying on the API like simulator_core.hpp.

What is more, EgoEntity has been modified in such a way, that the function

auto asFieldOperatorApplication() const -> concealer::FieldOperatorApplication & override;

has been replaced with a set of other functions below:
auto engage() -> void;
auto isEngaged() const -> bool;
auto isEngageable() const -> bool;
auto replanRoute(const std::vector<geometry_msgs::msg::PoseStamped> & route) -> void;
auto sendCooperateCommand(const std::string & module_name, const std::string & command) -> void;
auto requestAutoModeForCooperation(const std::string & module_name, bool enable) -> void;
auto getMinimumRiskManeuverBehaviorName() const -> std::string;
auto getMinimumRiskManeuverStateName() const -> std::string;
auto getEmergencyStateName() const -> std::string;
auto getTurnIndicatorsCommandName() const -> const std::string;

This change simplifies the interface of calling Ego specific actions like engage or sendCooperateCommand.

References

INTERNAL LINK

Destructive Changes

Known Limitations

TauTheLepton and others added 30 commits June 19, 2024 13:16
… exceptions were thrown

Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
…p-time' into RJD-1057-remove-functions-forwarded-to-entity-base
…d' into RJD-1057-remove-functions-forwarded-to-entity-base
…tityBase, also some getters, left setVelocityLimit and setBehaviorParameter
…develop templated is() in EntityBase and use it, rename isEgoSpawned to isAnyEgoSpawned, refactor
…ng setBehaviorParameter and setVelocityLimit
…ng request*, move requestLaneChange to EntityBase
…n forwarding, set "waiting" as init action state in behavior_tree
…develop getEgoEntity and dedicated methods in EgoEntity
…o RJD-1057-remove-functions-forwarded-to-entity-base
…y in calc it directly in evaluateTimeHeadway
dmoszynski and others added 5 commits July 1, 2024 15:55
Signed-off-by: Mateusz Palczuk <[email protected]>
…om-entity-manager' into RJD-1057-remove-functions-forwarded-to-entity-base-middle

Signed-off-by: Mateusz Palczuk <[email protected]>
…to RJD-1057-remove-functions-forwarded-to-entity-base-middle

Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
@dmoszynski dmoszynski self-assigned this Jul 31, 2024
@yamacir-kit yamacir-kit deleted the branch RJD-1057-traffic-lights-tests September 18, 2024 01:41
@yamacir-kit yamacir-kit deleted the RJD-1057-remove-functions-forwarded-to-entity-base-middle branch September 18, 2024 01:42
@TauTheLepton TauTheLepton restored the RJD-1057-remove-functions-forwarded-to-entity-base-middle branch October 2, 2024 07:32
@TauTheLepton TauTheLepton reopened this Oct 2, 2024
…ctions-forwarded-to-entity-base-middle

Signed-off-by: Mateusz Palczuk <[email protected]>
@TauTheLepton TauTheLepton added the bump major If this pull request merged, bump major version of the scenario_simulator_v2 label Oct 3, 2024
@TauTheLepton TauTheLepton self-assigned this Oct 15, 2024
@dmoszynski dmoszynski changed the title [tmp] Remove non-API member functions: EntityManager’s member functions forwarded to EntityBase (1/2) [tmp] RJD-1057 (3/5): Remove non-API member functions: EntityManager’s member functions forwarded to EntityBase (1/2) Oct 15, 2024
Copy link

sonarcloud bot commented Nov 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump major If this pull request merged, bump major version of the scenario_simulator_v2 wait for regression test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants