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

HdMapUtils refactor (PR 2/6) - extend lanelet_wrapper: add ::distance and necessary parts of ::route, ::lanelet_map, ::traffic_lights #1478

Draft
wants to merge 18 commits into
base: ref/RJD-1387-hdmap-utils-to-lanelet-wrapper-pose
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4624a23
feat(traffic_simulator): expand lanelet_wrapper: add ::distance and n…
dmoszynski Dec 5, 2024
a83b14d
feat(traffic_simulator, behavior_tree_plugin, openscenario_intepreter…
dmoszynski Dec 5, 2024
5921ecf
feat(traffic_simulator): adapt test for lanelet_wrapper
dmoszynski Dec 5, 2024
91f6ad3
reftraffic_simulator): use lanelet_wrapper in hdmap_utils, remove sep…
dmoszynski Dec 5, 2024
4b3a45c
ref(traffic_simulator): little lanelet_wrapper refactor
dmoszynski Dec 5, 2024
b418a3a
ref(clang): revert undesired changes
dmoszynski Dec 5, 2024
44d4896
Trigger CI pipeline
dmoszynski Dec 9, 2024
c447c53
Merge branch 'ref/RJD-1387-hdmap-utils-to-lanelet-wrapper-pose' into …
dmoszynski Dec 9, 2024
24cb803
Merge branch 'ref/RJD-1387-hdmap-utils-to-lanelet-wrapper-pose' into …
dmoszynski Dec 9, 2024
2f5132e
Merge branch 'ref/RJD-1387-hdmap-utils-to-lanelet-wrapper-pose' into …
dmoszynski Dec 10, 2024
768b84e
ref(traffic_simulator): improve hdmaputils::countLaneChanges
dmoszynski Dec 10, 2024
c33adff
Merge remote-tracking branch 'origin/ref/RJD-1387-hdmap-utils-to-lane…
dmoszynski Dec 10, 2024
fa0acce
Merge remote-tracking branch 'origin/ref/RJD-1387-hdmap-utils-to-lane…
dmoszynski Dec 10, 2024
ab01032
Merge branch 'ref/RJD-1387-hdmap-utils-to-lanelet-wrapper-pose' into …
dmoszynski Dec 11, 2024
318cfcf
Merge remote-tracking branch 'origin/ref/RJD-1387-hdmap-utils-to-lane…
dmoszynski Dec 18, 2024
0394908
fix(traffic_simulator): fix after merge
dmoszynski Dec 18, 2024
1539dd9
Merge branch 'ref/RJD-1387-hdmap-utils-to-lanelet-wrapper-pose' into …
dmoszynski Jan 7, 2025
9b0b06e
Merge remote-tracking branch 'origin/ref/RJD-1387-hdmap-utils-to-lane…
TauTheLepton Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GetDistanceInLaneCoordinateScenario : public cpp_mock_scenarios::CppScenar
return traffic_simulator::distance::lateralDistance(
from_entity->getCanonicalizedLaneletPose().value(),
to_entity->getCanonicalizedLaneletPose().value(),
traffic_simulator::RoutingConfiguration(), api_.getHdmapUtils());
traffic_simulator::RoutingConfiguration());
}
}
return std::nullopt;
Expand All @@ -68,7 +68,7 @@ class GetDistanceInLaneCoordinateScenario : public cpp_mock_scenarios::CppScenar
if (from_entity_lanelet_pose && to_entity_lanelet_pose) {
return traffic_simulator::distance::lateralDistance(
from_entity_lanelet_pose.value(), to_entity_lanelet_pose.value(),
traffic_simulator::RoutingConfiguration(), api_.getHdmapUtils());
traffic_simulator::RoutingConfiguration());
}
}
}
Expand All @@ -86,7 +86,7 @@ class GetDistanceInLaneCoordinateScenario : public cpp_mock_scenarios::CppScenar
return traffic_simulator::distance::longitudinalDistance(
from_entity->getCanonicalizedLaneletPose().value(),
to_entity->getCanonicalizedLaneletPose().value(), false, false,
traffic_simulator::RoutingConfiguration(), api_.getHdmapUtils());
traffic_simulator::RoutingConfiguration());
}
}
return std::nullopt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class GetDistanceToLaneBoundScenario : public cpp_mock_scenarios::CppScenarioNod
}
if (auto ego_entity = api_.getEntity("ego")) {
const auto distance = traffic_simulator::distance::distanceToLaneBound(
ego_entity->getMapPose(), ego_entity->getBoundingBox(), ego_entity->getRouteLanelets(),
api_.getHdmapUtils());
ego_entity->getMapPose(), ego_entity->getBoundingBox(), ego_entity->getRouteLanelets());
// LCOV_EXCL_START
if (distance <= 0.4 && distance >= 0.52) {
stop(cpp_mock_scenarios::Result::FAILURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class SimulatorCore
routing_configuration.allow_lane_change =
(routing_algorithm == RoutingAlgorithm::value_type::shortest);
return traffic_simulator::pose::relativeLaneletPose(
from_lanelet_pose, to_lanelet_pose, routing_configuration, core->getHdmapUtils());
from_lanelet_pose, to_lanelet_pose, routing_configuration);
}

static auto makeNativeBoundingBoxRelativeLanePosition(
Expand Down Expand Up @@ -230,7 +230,7 @@ class SimulatorCore
(routing_algorithm == RoutingAlgorithm::value_type::shortest);
return traffic_simulator::pose::boundingBoxRelativeLaneletPose(
from_lanelet_pose, from_bounding_box, to_lanelet_pose, to_bounding_box,
routing_configuration, core->getHdmapUtils());
routing_configuration);
}

static auto makeNativeBoundingBoxRelativeWorldPosition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,17 @@ class ActionNode : public BT::ActionNodeBase
-> double;
auto getDistanceToFrontEntity(const math::geometry::CatmullRomSplineInterface & spline) const
-> std::optional<double>;
auto getDistanceToStopLine(
const lanelet::Ids & route_lanelets,
const std::vector<geometry_msgs::msg::Point> & waypoints) const -> std::optional<double>;
auto getDistanceToTrafficLightStopLine(
const lanelet::Ids & route_lanelets,
const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>;
auto getRightOfWayEntities() const -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
auto getRightOfWayEntities(const lanelet::Ids & following_lanelets) const
-> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
auto getYieldStopDistance(const lanelet::Ids & following_lanelets) const -> std::optional<double>;
auto getOtherEntityStatus(lanelet::Id lanelet_id) const
-> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
auto stopEntity() const -> void;
auto getHorizon() const -> double;
auto getOtherEntitiesCanonicalizedLaneletPoses() const
-> std::vector<traffic_simulator::CanonicalizedLaneletPose>;

/// throws if the derived class return RUNNING.
auto executeTick() -> BT::NodeStatus override;
Expand Down
62 changes: 20 additions & 42 deletions simulation/behavior_tree_plugin/src/action_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ auto ActionNode::getBlackBoardValues() -> void
}
}

auto ActionNode::getOtherEntitiesCanonicalizedLaneletPoses() const
-> std::vector<traffic_simulator::CanonicalizedLaneletPose>
{
std::vector<traffic_simulator::CanonicalizedLaneletPose> other_canonicalized_lanelet_poses;
for (const auto & [name, status] : other_entity_status) {
if (auto const canonicalized_lanelet_pose = status.getCanonicalizedLaneletPose()) {
other_canonicalized_lanelet_poses.push_back(canonicalized_lanelet_pose.value());
}
}
return other_canonicalized_lanelet_poses;
}

auto ActionNode::getHorizon() const -> double
{
return std::clamp(canonicalized_entity_status->getTwist().linear.x * 5.0, 20.0, 50.0);
Expand All @@ -109,43 +121,16 @@ auto ActionNode::setCanonicalizedEntityStatus(const traffic_simulator::EntitySta
entity_status, default_matching_distance_for_lanelet_pose_calculation);
}

auto ActionNode::getOtherEntityStatus(lanelet::Id lanelet_id) const
-> std::vector<traffic_simulator::CanonicalizedEntityStatus>
{
std::vector<traffic_simulator::CanonicalizedEntityStatus> ret;
for (const auto & status : other_entity_status) {
if (
status.second.laneMatchingSucceed() &&
traffic_simulator::isSameLaneletId(status.second, lanelet_id)) {
ret.emplace_back(status.second);
}
}
return ret;
}

auto ActionNode::getYieldStopDistance(const lanelet::Ids & following_lanelets) const
-> std::optional<double>
{
std::set<double> distances;
for (const auto & lanelet : following_lanelets) {
const auto right_of_way_ids = hdmap_utils->getRightOfWayLaneletIds(lanelet);
for (const auto right_of_way_id : right_of_way_ids) {
const auto other_status = getOtherEntityStatus(right_of_way_id);
if (!other_status.empty() && canonicalized_entity_status->laneMatchingSucceed()) {
const auto lanelet_pose = canonicalized_entity_status->getLaneletPose();
const auto distance_forward = hdmap_utils->getLongitudinalDistance(
lanelet_pose, traffic_simulator::helper::constructLaneletPose(lanelet, 0));
const auto distance_backward = hdmap_utils->getLongitudinalDistance(
traffic_simulator::helper::constructLaneletPose(lanelet, 0), lanelet_pose);
if (distance_forward) {
distances.insert(distance_forward.value());
} else if (distance_backward) {
distances.insert(-distance_backward.value());
}
}
}
if (distances.size() != 0) {
return *distances.begin();
if (
const auto canonicalized_lanelet_pose =
canonicalized_entity_status->getCanonicalizedLaneletPose()) {
if (const auto other_canonicalized_lanelet_poses = getOtherEntitiesCanonicalizedLaneletPoses();
!other_canonicalized_lanelet_poses.empty()) {
traffic_simulator::distance::distanceToYieldStop(
canonicalized_lanelet_pose.value(), following_lanelets, other_canonicalized_lanelet_poses);
}
}
return std::nullopt;
Expand Down Expand Up @@ -214,7 +199,7 @@ auto ActionNode::getDistanceToTrafficLightStopLine(
if (traffic_lights->isRequiredStopTrafficLightState(traffic_light_id)) {
if (
const auto collision_point =
hdmap_utils->getDistanceToTrafficLightStopLine(spline, traffic_light_id)) {
traffic_simulator::distance::distanceToTrafficLightStopLine(spline, traffic_light_id)) {
collision_points.insert(collision_point.value());
}
}
Expand All @@ -226,13 +211,6 @@ auto ActionNode::getDistanceToTrafficLightStopLine(
return std::nullopt;
}

auto ActionNode::getDistanceToStopLine(
const lanelet::Ids & route_lanelets,
const std::vector<geometry_msgs::msg::Point> & waypoints) const -> std::optional<double>
{
return hdmap_utils->getDistanceToStopLine(route_lanelets, waypoints);
}

auto ActionNode::getDistanceToFrontEntity(
const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ auto FollowPolylineTrajectoryAction::tick() -> BT::NodeStatus
} else if (
const auto entity_status_updated = traffic_simulator::follow_trajectory::makeUpdatedStatus(
static_cast<traffic_simulator::EntityStatus>(*canonicalized_entity_status),
*polyline_trajectory, behavior_parameter, hdmap_utils, step_time,
*polyline_trajectory, behavior_parameter, step_time,
default_matching_distance_for_lanelet_pose_calculation, getTargetSpeed())) {
setCanonicalizedEntityStatus(entity_status_updated.value());
setOutput("waypoints", calculateWaypoints());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ BT::NodeStatus FollowFrontEntityAction::tick()
if (trajectory == nullptr) {
return BT::NodeStatus::FAILURE;
}
auto distance_to_stopline = hdmap_utils->getDistanceToStopLine(route_lanelets, *trajectory);
auto distance_to_stopline =
traffic_simulator::distance::distanceToStopLine(route_lanelets, *trajectory);
auto distance_to_conflicting_entity = getDistanceToConflictingEntity(route_lanelets, *trajectory);
const auto front_entity_name = getFrontEntityName(*trajectory);
if (!front_entity_name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ BT::NodeStatus FollowLaneAction::tick()
return BT::NodeStatus::FAILURE;
}
}
auto distance_to_stopline = hdmap_utils->getDistanceToStopLine(route_lanelets, *trajectory);
auto distance_to_stopline =
traffic_simulator::distance::distanceToStopLine(route_lanelets, *trajectory);
auto distance_to_conflicting_entity =
getDistanceToConflictingEntity(route_lanelets, *trajectory);
if (distance_to_stopline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ BT::NodeStatus StopAtCrossingEntityAction::tick()
return BT::NodeStatus::FAILURE;
}
distance_to_stop_target_ = getDistanceToConflictingEntity(route_lanelets, *trajectory);
auto distance_to_stopline = hdmap_utils->getDistanceToStopLine(route_lanelets, *trajectory);
auto distance_to_stopline =
traffic_simulator::distance::distanceToStopLine(route_lanelets, *trajectory);
const auto distance_to_front_entity = getDistanceToFrontEntity(*trajectory);
if (!distance_to_stop_target_) {
in_stop_sequence_ = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ BT::NodeStatus StopAtStopLineAction::tick()
if (trajectory == nullptr) {
return BT::NodeStatus::FAILURE;
}
distance_to_stopline_ = hdmap_utils->getDistanceToStopLine(route_lanelets, *trajectory);
distance_to_stopline_ =
traffic_simulator::distance::distanceToStopLine(route_lanelets, *trajectory);
const auto distance_to_stop_target = getDistanceToConflictingEntity(route_lanelets, *trajectory);
const auto distance_to_front_entity = getDistanceToFrontEntity(*trajectory);
if (!distance_to_stopline_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ auto FollowPolylineTrajectoryAction::tick() -> BT::NodeStatus
} else if (
const auto entity_status_updated = traffic_simulator::follow_trajectory::makeUpdatedStatus(
static_cast<traffic_simulator::EntityStatus>(*canonicalized_entity_status),
*polyline_trajectory, behavior_parameter, hdmap_utils, step_time,
*polyline_trajectory, behavior_parameter, step_time,
default_matching_distance_for_lanelet_pose_calculation, getTargetSpeed())) {
setCanonicalizedEntityStatus(entity_status_updated.value());
setOutput("waypoints", calculateWaypoints());
Expand Down
3 changes: 3 additions & 0 deletions simulation/traffic_simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ ament_auto_add_library(traffic_simulator SHARED
src/helper/helper.cpp
src/job/job.cpp
src/job/job_list.cpp
src/lanelet_wrapper/distance.cpp
src/lanelet_wrapper/lanelet_loader.cpp
src/lanelet_wrapper/lanelet_map.cpp
src/lanelet_wrapper/lanelet_wrapper.cpp
src/lanelet_wrapper/pose.cpp
src/lanelet_wrapper/route.cpp
src/lanelet_wrapper/traffic_lights.cpp
src/lanelet_wrapper/traffic_rules.cpp
src/simulation_clock/simulation_clock.cpp
src/traffic/traffic_controller.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ namespace follow_trajectory
auto makeUpdatedStatus(
const traffic_simulator_msgs::msg::EntityStatus &,
traffic_simulator_msgs::msg::PolylineTrajectory &,
const traffic_simulator_msgs::msg::BehaviorParameter &,
const std::shared_ptr<hdmap_utils::HdMapUtils> &, double, double,
const traffic_simulator_msgs::msg::BehaviorParameter &, double, double,
std::optional<double> target_speed = std::nullopt) -> std::optional<EntityStatus>;
} // namespace follow_trajectory
} // namespace traffic_simulator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CanonicalizedLaneletPose
auto alignOrientationToLanelet() -> void;
auto hasAlternativeLaneletPose() const -> bool { return lanelet_poses_.size() > 1; }
auto getAlternativeLaneletPoseBaseOnShortestRouteFrom(
LaneletPose from, const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils,
LaneletPose from,
const RoutingConfiguration & routing_configuration = RoutingConfiguration()) const
-> std::optional<LaneletPose>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ namespace traffic_simulator
{
struct RoutingConfiguration
{
RoutingConfiguration() = default;
explicit RoutingConfiguration(const bool allow_lane_change)
: allow_lane_change(allow_lane_change){};

bool allow_lane_change = false;
traffic_simulator::RoutingGraphType routing_graph_type =
traffic_simulator::RoutingGraphType::VEHICLE_WITH_ROAD_SHOULDER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,6 @@ class HdMapUtils
traffic_simulator::RoutingConfiguration().routing_graph_type) const
-> lanelet::Ids;

auto getDistanceToStopLine(
const lanelet::Ids & route_lanelets,
const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>;

auto getDistanceToStopLine(
const lanelet::Ids & route_lanelets,
const std::vector<geometry_msgs::msg::Point> & waypoints) const -> std::optional<double>;

auto getDistanceToTrafficLightStopLine(
const lanelet::Ids & route_lanelets,
const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>;

auto getDistanceToTrafficLightStopLine(
const lanelet::Ids & route_lanelets,
const std::vector<geometry_msgs::msg::Point> & waypoints) const -> std::optional<double>;

auto getDistanceToTrafficLightStopLine(
const math::geometry::CatmullRomSplineInterface & spline,
const lanelet::Id traffic_light_id) const -> std::optional<double>;

auto getDistanceToTrafficLightStopLine(
const std::vector<geometry_msgs::msg::Point> & waypoints,
const lanelet::Id traffic_light_id) const -> std::optional<double>;

auto getFollowingLanelets(
const lanelet::Id current_lanelet_id, const lanelet::Ids & route, const double horizon = 100,
const bool include_current_lanelet_id = true,
Expand Down Expand Up @@ -173,20 +149,6 @@ class HdMapUtils

auto getLanelets(const lanelet::Ids &) const -> lanelet::Lanelets;

auto getLateralDistance(
const traffic_simulator_msgs::msg::LaneletPose & from,
const traffic_simulator_msgs::msg::LaneletPose & to,
const traffic_simulator::RoutingConfiguration & routing_configuration =
traffic_simulator::RoutingConfiguration()) const -> std::optional<double>;

auto getLeftBound(const lanelet::Id) const -> std::vector<geometry_msgs::msg::Point>;

auto getLongitudinalDistance(
const traffic_simulator_msgs::msg::LaneletPose & from_pose,
const traffic_simulator_msgs::msg::LaneletPose & to_pose,
const traffic_simulator::RoutingConfiguration & routing_configuration =
traffic_simulator::RoutingConfiguration()) const -> std::optional<double>;

auto getNearbyLaneletIds(
const geometry_msgs::msg::Point &, const double distance_threshold,
const bool include_crosswalk, const std::size_t search_count = 5) const -> lanelet::Ids;
Expand All @@ -200,8 +162,6 @@ class HdMapUtils
const traffic_simulator::RoutingGraphType type =
traffic_simulator::RoutingConfiguration().routing_graph_type) const -> lanelet::Ids;

auto getRightBound(const lanelet::Id) const -> std::vector<geometry_msgs::msg::Point>;

auto getRightOfWayLaneletIds(const lanelet::Ids &) const
-> std::unordered_map<lanelet::Id, lanelet::Ids>;

Expand All @@ -217,12 +177,6 @@ class HdMapUtils
traffic_simulator::RoutingConfiguration().routing_graph_type) const
-> double;

auto getStopLineIds() const -> lanelet::Ids;

auto getStopLineIdsOnPath(const lanelet::Ids & route_lanelets) const -> lanelet::Ids;

auto getStopLinePolygon(const lanelet::Id) const -> std::vector<geometry_msgs::msg::Point>;

auto getTangentVector(const lanelet::Id, const double s) const
-> std::optional<geometry_msgs::msg::Vector3>;

Expand Down Expand Up @@ -354,10 +308,6 @@ class HdMapUtils
const traffic_simulator::lane_change::TrajectoryShape,
const double tangent_vector_size = 100) const -> math::geometry::HermiteCurve;

auto getStopLines() const -> lanelet::ConstLineStrings3d;

auto getStopLinesOnPath(const lanelet::Ids &) const -> lanelet::ConstLineStrings3d;

auto getTrafficLightRegulatoryElementsOnPath(const lanelet::Ids &) const
-> std::vector<std::shared_ptr<const lanelet::autoware::AutowareTrafficLight>>;

Expand Down
Loading
Loading