Skip to content

Commit 0845ce1

Browse files
authored
Merge pull request #1531 from tier4/refactor/lanelet_wrapper_route
HdMapUtils refactor lanelet_wrapper::route
2 parents 91a2404 + 2f62f8a commit 0845ce1

File tree

11 files changed

+140
-26
lines changed

11 files changed

+140
-26
lines changed

simulation/behavior_tree_plugin/src/action_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ auto ActionNode::getDistanceToTargetEntity(
334334
if (const auto & target_lanelet_pose =
335335
traffic_simulator::pose::findRoutableAlternativeLaneletPoseFrom(
336336
canonicalized_entity_status->getLaneletId(), status.getCanonicalizedLaneletPose().value(),
337-
target_bounding_box, hdmap_utils);
337+
target_bounding_box);
338338
target_lanelet_pose) {
339339
const auto & from_lanelet_pose = canonicalized_entity_status->getCanonicalizedLaneletPose();
340340
const auto & from_bounding_box = canonicalized_entity_status->getBoundingBox();

simulation/traffic_simulator/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ament_auto_add_library(traffic_simulator SHARED
5252
src/lanelet_wrapper/lanelet_map.cpp
5353
src/lanelet_wrapper/lanelet_wrapper.cpp
5454
src/lanelet_wrapper/pose.cpp
55+
src/lanelet_wrapper/route.cpp
5556
src/lanelet_wrapper/traffic_rules.cpp
5657
src/simulation_clock/simulation_clock.cpp
5758
src/traffic/traffic_controller.cpp

simulation/traffic_simulator/include/traffic_simulator/data_type/lanelet_pose.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CanonicalizedLaneletPose
4949
auto alignOrientationToLanelet() -> void;
5050
auto hasAlternativeLaneletPose() const -> bool { return lanelet_poses_.size() > 1; }
5151
auto getAlternativeLaneletPoseBaseOnShortestRouteFrom(
52-
LaneletPose from, const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils,
52+
LaneletPose from,
5353
const RoutingConfiguration & routing_configuration = RoutingConfiguration()) const
5454
-> std::optional<LaneletPose>;
5555

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2015 Tier IV, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef TRAFFIC_SIMULATOR__LANELET_WRAPPER_ROUTE_HPP_
16+
#define TRAFFIC_SIMULATOR__LANELET_WRAPPER_ROUTE_HPP_
17+
18+
#include <lanelet2_core/geometry/Lanelet.h>
19+
20+
#include <traffic_simulator/lanelet_wrapper/lanelet_wrapper.hpp>
21+
22+
namespace traffic_simulator
23+
{
24+
namespace lanelet_wrapper
25+
{
26+
namespace route
27+
{
28+
auto route(
29+
const lanelet::Id from_lanelet_id, const lanelet::Id to_lanelet_id,
30+
const RoutingConfiguration & routing_configuration = RoutingConfiguration()) -> lanelet::Ids;
31+
} // namespace route
32+
} // namespace lanelet_wrapper
33+
} // namespace traffic_simulator
34+
#endif // TRAFFIC_SIMULATOR__LANELET_WRAPPER_ROUTE_HPP_

simulation/traffic_simulator/include/traffic_simulator/utils/pose.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ auto isAtEndOfLanelets(
113113

114114
auto findRoutableAlternativeLaneletPoseFrom(
115115
const lanelet::Id from_lanelet_id, const CanonicalizedLaneletPose & canonicalized_lanelet_pose,
116-
const traffic_simulator_msgs::msg::BoundingBox & to_bounding_box,
117-
const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr)
116+
const traffic_simulator_msgs::msg::BoundingBox & to_bounding_box)
118117
-> std::optional<traffic_simulator::CanonicalizedLaneletPose>;
119118

120119
namespace pedestrian
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 Tier IV, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef TRAFFIC_SIMULATOR__UTILS__ROUTE_HPP_
16+
#define TRAFFIC_SIMULATOR__UTILS__ROUTE_HPP_
17+
18+
#include <geometry/spline/catmull_rom_spline.hpp>
19+
#include <geometry/spline/catmull_rom_spline_interface.hpp>
20+
#include <geometry/spline/hermite_curve.hpp>
21+
#include <traffic_simulator/data_type/lane_change.hpp>
22+
#include <traffic_simulator/data_type/lanelet_pose.hpp>
23+
#include <traffic_simulator/lanelet_wrapper/route.hpp>
24+
25+
namespace traffic_simulator
26+
{
27+
inline namespace route
28+
{
29+
template <typename... Ts>
30+
auto route(Ts &&... xs)
31+
{
32+
return lanelet_wrapper::route::route(std::forward<decltype(xs)>(xs)...);
33+
}
34+
} // namespace route
35+
} // namespace traffic_simulator
36+
#endif // TRAFFIC_SIMULATOR__UTILS__ROUTE_HPP_

simulation/traffic_simulator/src/data_type/lanelet_pose.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <traffic_simulator/data_type/lanelet_pose.hpp>
2121
#include <traffic_simulator/lanelet_wrapper/lanelet_map.hpp>
2222
#include <traffic_simulator/utils/pose.hpp>
23+
#include <traffic_simulator/utils/route.hpp>
2324

2425
namespace traffic_simulator
2526
{
@@ -67,18 +68,17 @@ auto CanonicalizedLaneletPose::operator=(const CanonicalizedLaneletPose & other)
6768
}
6869

6970
auto CanonicalizedLaneletPose::getAlternativeLaneletPoseBaseOnShortestRouteFrom(
70-
LaneletPose from, const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils,
71-
const RoutingConfiguration & routing_configuration) const -> std::optional<LaneletPose>
71+
LaneletPose from, const RoutingConfiguration & routing_configuration) const
72+
-> std::optional<LaneletPose>
7273
{
7374
if (lanelet_poses_.empty()) {
7475
return std::nullopt;
7576
}
76-
lanelet::Ids shortest_route =
77-
hdmap_utils->getRoute(from.lanelet_id, lanelet_poses_[0].lanelet_id, routing_configuration);
77+
auto shortest_route =
78+
route::route(from.lanelet_id, lanelet_poses_[0].lanelet_id, routing_configuration);
7879
LaneletPose alternative_lanelet_pose = lanelet_poses_[0];
7980
for (const auto & laneletPose : lanelet_poses_) {
80-
const auto route =
81-
hdmap_utils->getRoute(from.lanelet_id, laneletPose.lanelet_id, routing_configuration);
81+
const auto route = route::route(from.lanelet_id, laneletPose.lanelet_id, routing_configuration);
8282
if (shortest_route.size() > route.size()) {
8383
shortest_route = route;
8484
alternative_lanelet_pose = laneletPose;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
// Copyright 2015 Tier IV, Inc. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include <lanelet2_core/geometry/Lanelet.h>
17+
#include <lanelet2_core/primitives/BasicRegulatoryElements.h>
18+
#include <lanelet2_core/utility/Units.h>
19+
#include <lanelet2_routing/RoutingGraphContainer.h>
20+
21+
#include <autoware_lanelet2_extension/utility/utilities.hpp>
22+
#include <traffic_simulator/helper/helper.hpp>
23+
#include <traffic_simulator/lanelet_wrapper/lanelet_map.hpp>
24+
#include <traffic_simulator/lanelet_wrapper/lanelet_wrapper.hpp>
25+
#include <traffic_simulator/lanelet_wrapper/route.hpp>
26+
27+
namespace traffic_simulator
28+
{
29+
namespace lanelet_wrapper
30+
{
31+
namespace route
32+
{
33+
auto route(
34+
const lanelet::Id from_lanelet_id, const lanelet::Id to_lanelet_id,
35+
const RoutingConfiguration & routing_configuration) -> lanelet::Ids
36+
{
37+
/// @todo improve architecture in terms of access to cache of the graph
38+
return LaneletWrapper::routeCache(routing_configuration.routing_graph_type)
39+
.getRoute(
40+
from_lanelet_id, to_lanelet_id, LaneletWrapper::map(), routing_configuration,
41+
LaneletWrapper::routingGraph(routing_configuration.routing_graph_type));
42+
}
43+
} // namespace route
44+
} // namespace lanelet_wrapper
45+
} // namespace traffic_simulator

simulation/traffic_simulator/src/utils/distance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ auto longitudinalDistance(
6868
if (to.hasAlternativeLaneletPose()) {
6969
if (
7070
const auto to_canonicalized_opt = to.getAlternativeLaneletPoseBaseOnShortestRouteFrom(
71-
static_cast<LaneletPose>(from), hdmap_utils_ptr, routing_configuration)) {
71+
static_cast<LaneletPose>(from), routing_configuration)) {
7272
to_canonicalized = to_canonicalized_opt.value();
7373
}
7474
}

simulation/traffic_simulator/src/utils/pose.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <traffic_simulator/lanelet_wrapper/pose.hpp>
2525
#include <traffic_simulator/utils/distance.hpp>
2626
#include <traffic_simulator/utils/pose.hpp>
27+
#include <traffic_simulator/utils/route.hpp>
2728
#include <traffic_simulator_msgs/msg/lanelet_pose.hpp>
2829

2930
namespace traffic_simulator
@@ -386,26 +387,25 @@ auto isAtEndOfLanelets(
386387

387388
auto findRoutableAlternativeLaneletPoseFrom(
388389
const lanelet::Id from_lanelet_id, const CanonicalizedLaneletPose & to_canonicalized_lanelet_pose,
389-
const traffic_simulator_msgs::msg::BoundingBox & to_bounding_box,
390-
const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr)
390+
const traffic_simulator_msgs::msg::BoundingBox & to_bounding_box)
391391
-> std::optional<traffic_simulator::CanonicalizedLaneletPose>
392392
{
393393
/// @note search_distance should be minimal, just to check nearest neighbour lanelets
394394
constexpr auto search_distance{3.0};
395395
/// @note default_match_to_lane_reduction_ratio is constant described in hdmap_utils.hpp
396396
constexpr auto default_match_to_lane_reduction_ratio{0.8};
397397
constexpr auto include_crosswalk{false};
398-
/**
399-
* @note hdmap_utils_ptr->getRoute requires routing_configuration,
400-
* 'allow_lane_change = true' is needed to check distances to entities on neighbour lanelets
401-
*/
398+
/**
399+
* @note route::route requires routing_configuration,
400+
* 'allow_lane_change = true' is needed to check distances to entities on neighbour lanelets
401+
*/
402402
RoutingConfiguration routing_configuration;
403403
routing_configuration.allow_lane_change = true;
404404

405405
/// @note if there is already a route from_lanelet_id->to_lanelet_id, return it
406406
/// if not, transform the 'to_lanelet_id' position into the nearby lanelets and search for a route in relation to them
407407
if (const auto to_lanelet_id = to_canonicalized_lanelet_pose.getLaneletPose().lanelet_id;
408-
!hdmap_utils_ptr->getRoute(from_lanelet_id, to_lanelet_id, routing_configuration).empty()) {
408+
!route::route(from_lanelet_id, to_lanelet_id, routing_configuration).empty()) {
409409
return to_canonicalized_lanelet_pose;
410410
} else if (const auto nearby_lanelet_ids = lanelet_wrapper::pose::findMatchingLanes(
411411
static_cast<geometry_msgs::msg::Pose>(to_canonicalized_lanelet_pose),
@@ -414,8 +414,7 @@ auto findRoutableAlternativeLaneletPoseFrom(
414414
nearby_lanelet_ids.has_value()) {
415415
std::vector<std::pair<CanonicalizedLaneletPose, lanelet::Ids>> routes;
416416
for (const auto & [distance, lanelet_id] : nearby_lanelet_ids.value()) {
417-
if (auto route =
418-
hdmap_utils_ptr->getRoute(from_lanelet_id, lanelet_id, routing_configuration);
417+
if (auto route = route::route(from_lanelet_id, lanelet_id, routing_configuration);
419418
lanelet_id == to_lanelet_id || route.empty()) {
420419
continue;
421420
} else if (const auto lanelet_pose = lanelet_wrapper::pose::toLaneletPose(

simulation/traffic_simulator/test/src/data_type/test_lanelet_pose.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ TEST_F(CanonicalizedLaneletPoseTest, getAlternativeLaneletPoseBaseOnShortestRout
191191
const auto from1 = traffic_simulator::helper::constructLaneletPose(34603, 10.0, 0.0);
192192
const auto from2 = traffic_simulator::helper::constructLaneletPose(34579, 10.0, 0.0);
193193

194-
const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from1, hdmap_utils);
195-
const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from2, hdmap_utils);
194+
const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from1);
195+
const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from2);
196196

197197
ASSERT_TRUE(result1.has_value());
198198
ASSERT_TRUE(result2.has_value());
@@ -210,8 +210,8 @@ TEST_F(CanonicalizedLaneletPoseTest, getAlternativeLaneletPoseBaseOnShortestRout
210210
const auto from1 = traffic_simulator::helper::constructLaneletPose(34603, 10.0, 0.0);
211211
const auto from2 = traffic_simulator::helper::constructLaneletPose(34579, 10.0, 0.0);
212212

213-
const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from1, hdmap_utils);
214-
const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from2, hdmap_utils);
213+
const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from1);
214+
const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from2);
215215

216216
ASSERT_TRUE(result1.has_value());
217217
ASSERT_TRUE(result2.has_value());
@@ -230,8 +230,8 @@ TEST_F(CanonicalizedLaneletPoseTest, getAlternativeLaneletPoseBaseOnShortestRout
230230
const auto from1 = traffic_simulator::helper::constructLaneletPose(34603, 10.0, 0.0);
231231
const auto from2 = traffic_simulator::helper::constructLaneletPose(34579, 10.0, 0.0);
232232

233-
const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from1, hdmap_utils);
234-
const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from2, hdmap_utils);
233+
const auto result1 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from1);
234+
const auto result2 = pose.getAlternativeLaneletPoseBaseOnShortestRouteFrom(from2);
235235

236236
ASSERT_TRUE(result1.has_value());
237237
ASSERT_TRUE(result2.has_value());

0 commit comments

Comments
 (0)