|
14 | 14 |
|
15 | 15 | #include "manager.hpp"
|
16 | 16 |
|
| 17 | +#include "tier4_autoware_utils/geometry/boost_geometry.hpp" |
| 18 | + |
17 | 19 | #include <behavior_velocity_planner_common/utilization/util.hpp>
|
| 20 | +#include <lanelet2_extension/utility/utilities.hpp> |
18 | 21 | #include <tier4_autoware_utils/math/unit_conversion.hpp>
|
19 | 22 | #include <tier4_autoware_utils/ros/parameter.hpp>
|
20 | 23 |
|
| 24 | +#include <boost/geometry/algorithms/intersects.hpp> |
| 25 | + |
| 26 | +#include <lanelet2_core/geometry/LineString.h> |
| 27 | + |
21 | 28 | #include <memory>
|
22 | 29 | #include <set>
|
23 | 30 | #include <string>
|
@@ -51,13 +58,30 @@ VirtualTrafficLightModuleManager::VirtualTrafficLightModuleManager(rclcpp::Node
|
51 | 58 | void VirtualTrafficLightModuleManager::launchNewModules(
|
52 | 59 | const autoware_auto_planning_msgs::msg::PathWithLaneId & path)
|
53 | 60 | {
|
| 61 | + tier4_autoware_utils::LineString2d ego_path_linestring; |
| 62 | + for (const auto & path_point : path.points) { |
| 63 | + ego_path_linestring.push_back( |
| 64 | + tier4_autoware_utils::fromMsg(path_point.point.pose.position).to_2d()); |
| 65 | + } |
| 66 | + |
54 | 67 | for (const auto & m : planning_utils::getRegElemMapOnPath<VirtualTrafficLight>(
|
55 | 68 | path, planner_data_->route_handler_->getLaneletMapPtr(),
|
56 | 69 | planner_data_->current_odometry->pose)) {
|
| 70 | + const auto stop_line_opt = m.first->getStopLine(); |
| 71 | + if (!stop_line_opt) { |
| 72 | + RCLCPP_FATAL( |
| 73 | + logger_, "No stop line at traffic_light_reg_elem_id = %ld, please fix the map!", |
| 74 | + m.first->id()); |
| 75 | + continue; |
| 76 | + } |
| 77 | + |
57 | 78 | // Use lanelet_id to unregister module when the route is changed
|
58 | 79 | const auto lane_id = m.second.id();
|
59 | 80 | const auto module_id = lane_id;
|
60 |
| - if (!isModuleRegistered(module_id)) { |
| 81 | + if ( |
| 82 | + !isModuleRegistered(module_id) && |
| 83 | + boost::geometry::intersects( |
| 84 | + ego_path_linestring, lanelet::utils::to2D(stop_line_opt.value()).basicLineString())) { |
61 | 85 | registerModule(std::make_shared<VirtualTrafficLightModule>(
|
62 | 86 | module_id, lane_id, *m.first, m.second, planner_param_,
|
63 | 87 | logger_.get_child("virtual_traffic_light_module"), clock_));
|
|
0 commit comments