Skip to content
Snippets Groups Projects
Commit 6d4b0919 authored by René Paris's avatar René Paris
Browse files

Merge branch '56-followtrajectorycontrolstrategy-forced-to-single-domain' into 'main'

Revert "Merge branch 'fix/FollowTrajectoryMovementDomain' into 'main'"

Closes #56

See merge request !206
parents 3fa8f613 8d490a13
No related branches found
No related tags found
1 merge request!206Revert "Merge branch 'fix/FollowTrajectoryMovementDomain' into 'main'"
/********************************************************************************
* Copyright (c) 2021-2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
......@@ -16,6 +16,31 @@
namespace OpenScenarioEngine::v1_2
{
namespace detail
{
mantle_api::Trajectory ConvertPolyLine(
const std::shared_ptr<mantle_api::IEnvironment>& environment,
const std::string& entity,
TrajectoryRef trajectoryRef)
{
const auto& refEntity = EntityUtils::GetEntityByName(environment, entity);
const auto geometric_center = refEntity.GetProperties()->bounding_box.geometric_center;
// modifies the copy of the trajectory ref!
for (auto& polyLinePoint : std::get<mantle_api::PolyLine>(trajectoryRef->type))
{
polyLinePoint.pose.position = environment->GetGeometryHelper()->TranslateGlobalPositionLocally(
polyLinePoint.pose.position,
polyLinePoint.pose.orientation,
geometric_center);
}
return trajectoryRef.value();
}
} // namespace detail
void FollowTrajectoryAction::SetControlStrategy()
{
if (!values.trajectoryRef)
......@@ -27,23 +52,12 @@ void FollowTrajectoryAction::SetControlStrategy()
for (const auto& entity : values.entities)
{
const auto& refEntity = EntityUtils::GetEntityByName(mantle.environment, entity);
mantle_api::MovementDomain movementDomain{mantle_api::MovementDomain::kLateral};
for (auto& polyLinePoint : std::get<mantle_api::PolyLine>(values.trajectoryRef->type))
{
if (polyLinePoint.time.has_value())
{
movementDomain = mantle_api::MovementDomain::kBoth;
}
polyLinePoint.pose.position = mantle.environment->GetGeometryHelper()->TranslateGlobalPositionLocally(polyLinePoint.pose.position,
polyLinePoint.pose.orientation,
refEntity.GetProperties()->bounding_box.geometric_center);
}
auto control_strategy = std::make_shared<mantle_api::FollowTrajectoryControlStrategy>();
control_strategy->movement_domain = movementDomain;
control_strategy->trajectory = values.trajectoryRef.value();
control_strategy->timeReference = values.timeReference;
control_strategy->movement_domain = values.timeReference
? mantle_api::MovementDomain::kBoth
: mantle_api::MovementDomain::kLateral;
control_strategy->trajectory = detail::ConvertPolyLine(mantle.environment, entity, values.trajectoryRef);
const auto entity_id = mantle.environment->GetEntityRepository().Get(entity)->get().GetUniqueId();
mantle.environment->UpdateControlStrategies(entity_id, {control_strategy});
}
......
/********************************************************************************
* Copyright (c) 2021-2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2023 Ansys, Inc.
*
* This program and the accompanying materials are made available under the
......@@ -483,3 +483,49 @@ TEST(FollowTrajectoryAction, GivenFollowTrajectoryActionAndTrajectoryRef_Updates
EXPECT_EQ(polyline.at(1).pose, pose2);
EXPECT_EQ(polyline.at(2).pose, pose3);
}
TEST(FollowTrajectoryAction,
GivenFollowTrajectoryActionWithTimeReference_WhenStartAction_ThenControlStrategyHasMovementDomainBoth)
{
auto mockEnvironment = std::make_shared<MockEnvironment>();
std::vector<std::shared_ptr<ControlStrategy>> control_strategies{};
EXPECT_CALL(*mockEnvironment, UpdateControlStrategies(_, _)).WillOnce(SaveArg<1>(&control_strategies));
OpenScenarioEngine::v1_2::FollowTrajectoryAction followTrajectoryAction({std::vector<std::string>{"Vehicle1"},
0.0,
mantle_api::Trajectory{},
{mantle_api::FollowTrajectoryControlStrategy::TrajectoryTimeReference{}},
OpenScenarioEngine::v1_2::TrajectoryFollowingMode{},
mantle_api::Trajectory{}},
{mockEnvironment});
followTrajectoryAction.SetControlStrategy();
ASSERT_THAT(control_strategies, testing::SizeIs(1));
auto control_strategy = std::dynamic_pointer_cast<mantle_api::FollowTrajectoryControlStrategy>(control_strategies.front());
EXPECT_TRUE(control_strategy->timeReference.has_value());
EXPECT_THAT(control_strategy->movement_domain, mantle_api::MovementDomain::kBoth);
}
TEST(FollowTrajectoryAction,
GivenFollowTrajectoryActionWithoutTimeReference_WhenStartAction_ThenControlStrategyHasMovementDomainLateral)
{
auto mockEnvironment = std::make_shared<MockEnvironment>();
std::vector<std::shared_ptr<ControlStrategy>> control_strategies{};
EXPECT_CALL(*mockEnvironment, UpdateControlStrategies(_, _)).WillOnce(SaveArg<1>(&control_strategies));
OpenScenarioEngine::v1_2::FollowTrajectoryAction followTrajectoryAction({std::vector<std::string>{"Vehicle1"},
0.0,
mantle_api::Trajectory{},
std::nullopt,
OpenScenarioEngine::v1_2::TrajectoryFollowingMode{},
mantle_api::Trajectory{}},
{mockEnvironment});
followTrajectoryAction.SetControlStrategy();
ASSERT_THAT(control_strategies, testing::SizeIs(1));
auto control_strategy = std::dynamic_pointer_cast<mantle_api::FollowTrajectoryControlStrategy>(control_strategies.front());
EXPECT_FALSE(control_strategy->timeReference.has_value());
EXPECT_THAT(control_strategy->movement_domain, mantle_api::MovementDomain::kLateral);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment