Skip to content

Commit 7fb4c1b

Browse files
authored
feat(behavior_velocity_planner): remove virtual traffic light dependency from behavior_velocity_planner and behavior_velocity_planner_common (#9746)
* feat: remove-virtual-traffic-light-dependency-from-plugin-manager Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * build passed Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * fix test Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * fix test Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * fix Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * fix typo Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> --------- Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent d86c46a commit 7fb4c1b

File tree

12 files changed

+100
-47
lines changed

12 files changed

+100
-47
lines changed

planning/behavior_velocity_planner/autoware_behavior_velocity_planner/include/autoware/behavior_velocity_planner/node.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ class BehaviorVelocityPlannerNode : public rclcpp::Node
8181
autoware_perception_msgs::msg::TrafficLightGroupArray>
8282
sub_traffic_signals_{this, "~/input/traffic_signals"};
8383

84-
autoware::universe_utils::InterProcessPollingSubscriber<
85-
tier4_v2x_msgs::msg::VirtualTrafficLightStateArray>
86-
sub_virtual_traffic_light_states_{this, "~/input/virtual_traffic_light_states"};
87-
8884
autoware::universe_utils::InterProcessPollingSubscriber<nav_msgs::msg::OccupancyGrid>
8985
sub_occupancy_grid_{this, "~/input/occupancy_grid"};
9086

planning/behavior_velocity_planner/autoware_behavior_velocity_planner/package.xml

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
<depend>tf2_geometry_msgs</depend>
5757
<depend>tf2_ros</depend>
5858
<depend>tier4_planning_msgs</depend>
59-
<depend>tier4_v2x_msgs</depend>
6059
<depend>visualization_msgs</depend>
6160

6261
<test_depend>ament_cmake_ros</test_depend>

planning/behavior_velocity_planner/autoware_behavior_velocity_planner/src/node.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ bool BehaviorVelocityPlannerNode::processData(rclcpp::Clock clock)
271271
planner_data_.route_handler_ = std::make_shared<route_handler::RouteHandler>(*map_data);
272272
}
273273

274-
// optional data
275-
getData(planner_data_.virtual_traffic_light_states, sub_virtual_traffic_light_states_);
276-
277274
// planner_data_.external_velocity_limit is std::optional type variable.
278275
const auto external_velocity_limit = sub_external_velocity_limit_.takeData();
279276
if (external_velocity_limit) {

planning/behavior_velocity_planner/autoware_behavior_velocity_planner/src/test_utils.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ void publishMandatoryTopics(
113113
test_target_node, "behavior_velocity_planner_node/input/traffic_signals");
114114
test_manager->publishMaxVelocity(
115115
test_target_node, "behavior_velocity_planner_node/input/external_velocity_limit_mps");
116-
test_manager->publishVirtualTrafficLightState(
117-
test_target_node, "behavior_velocity_planner_node/input/virtual_traffic_light_states");
118116
test_manager->publishOccupancyGrid(
119117
test_target_node, "behavior_velocity_planner_node/input/occupancy_grid");
120118
}

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/planner_data.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <sensor_msgs/msg/point_cloud2.hpp>
3131
#include <std_msgs/msg/header.hpp>
3232
#include <tier4_planning_msgs/msg/velocity_limit.hpp>
33-
#include <tier4_v2x_msgs/msg/virtual_traffic_light_state_array.hpp>
3433

3534
#include <pcl/point_cloud.h>
3635
#include <pcl/point_types.h>
@@ -64,7 +63,6 @@ struct PlannerData
6463
std::map<lanelet::Id, TrafficSignalStamped> traffic_light_id_map_raw_;
6564
std::map<lanelet::Id, TrafficSignalStamped> traffic_light_id_map_last_observed_;
6665
std::optional<tier4_planning_msgs::msg::VelocityLimit> external_velocity_limit;
67-
tier4_v2x_msgs::msg::VirtualTrafficLightStateArray::ConstSharedPtr virtual_traffic_light_states;
6866

6967
bool is_simulation = false;
7068

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/scene_module_interface.hpp

-26
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <autoware_internal_debug_msgs/msg/float64_stamped.hpp>
3333
#include <autoware_planning_msgs/msg/path.hpp>
3434
#include <tier4_planning_msgs/msg/path_with_lane_id.hpp>
35-
#include <tier4_v2x_msgs/msg/infrastructure_command_array.hpp>
3635
#include <unique_identifier_msgs/msg/uuid.hpp>
3736

3837
#include <memory>
@@ -95,17 +94,6 @@ class SceneModuleInterface
9594
planner_data_ = planner_data;
9695
}
9796

98-
std::optional<tier4_v2x_msgs::msg::InfrastructureCommand> getInfrastructureCommand()
99-
{
100-
return infrastructure_command_;
101-
}
102-
103-
void setInfrastructureCommand(
104-
const std::optional<tier4_v2x_msgs::msg::InfrastructureCommand> & command)
105-
{
106-
infrastructure_command_ = command;
107-
}
108-
10997
void setTimeKeeper(const std::shared_ptr<universe_utils::TimeKeeper> & time_keeper)
11098
{
11199
time_keeper_ = time_keeper;
@@ -123,7 +111,6 @@ class SceneModuleInterface
123111
rclcpp::Logger logger_;
124112
rclcpp::Clock::SharedPtr clock_;
125113
std::shared_ptr<const PlannerData> planner_data_;
126-
std::optional<tier4_v2x_msgs::msg::InfrastructureCommand> infrastructure_command_;
127114
autoware::motion_utils::VelocityFactorInterface velocity_factor_;
128115
std::vector<ObjectOfInterest> objects_of_interest_;
129116
mutable std::shared_ptr<universe_utils::TimeKeeper> time_keeper_;
@@ -161,9 +148,6 @@ class SceneModuleManagerInterface
161148
std::string("~/virtual_wall/") + module_name, 5);
162149
pub_velocity_factor_ = node.create_publisher<autoware_adapi_v1_msgs::msg::VelocityFactorArray>(
163150
std::string("/planning/velocity_factors/") + module_name, 1);
164-
pub_infrastructure_commands_ =
165-
node.create_publisher<tier4_v2x_msgs::msg::InfrastructureCommandArray>(
166-
"~/output/infrastructure_commands", 1);
167151

168152
processing_time_publisher_ = std::make_shared<DebugPublisher>(&node, "~/debug");
169153

@@ -201,9 +185,6 @@ class SceneModuleManagerInterface
201185
velocity_factor_array.header.frame_id = "map";
202186
velocity_factor_array.header.stamp = clock_->now();
203187

204-
tier4_v2x_msgs::msg::InfrastructureCommandArray infrastructure_command_array;
205-
infrastructure_command_array.stamp = clock_->now();
206-
207188
for (const auto & scene_module : scene_modules_) {
208189
scene_module->resetVelocityFactor();
209190
scene_module->setPlannerData(planner_data_);
@@ -215,10 +196,6 @@ class SceneModuleManagerInterface
215196
velocity_factor_array.factors.emplace_back(velocity_factor);
216197
}
217198

218-
if (const auto command = scene_module->getInfrastructureCommand()) {
219-
infrastructure_command_array.commands.push_back(*command);
220-
}
221-
222199
for (const auto & marker : scene_module->createDebugMarkerArray().markers) {
223200
debug_marker_array.markers.push_back(marker);
224201
}
@@ -227,7 +204,6 @@ class SceneModuleManagerInterface
227204
}
228205

229206
pub_velocity_factor_->publish(velocity_factor_array);
230-
pub_infrastructure_commands_->publish(infrastructure_command_array);
231207
pub_debug_->publish(debug_marker_array);
232208
if (is_publish_debug_path_) {
233209
tier4_planning_msgs::msg::PathWithLaneId debug_path;
@@ -299,8 +275,6 @@ class SceneModuleManagerInterface
299275
rclcpp::Publisher<tier4_planning_msgs::msg::PathWithLaneId>::SharedPtr pub_debug_path_;
300276
rclcpp::Publisher<autoware_adapi_v1_msgs::msg::VelocityFactorArray>::SharedPtr
301277
pub_velocity_factor_;
302-
rclcpp::Publisher<tier4_v2x_msgs::msg::InfrastructureCommandArray>::SharedPtr
303-
pub_infrastructure_commands_;
304278

305279
std::shared_ptr<DebugPublisher> processing_time_publisher_;
306280

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/package.xml

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
<depend>tf2_geometry_msgs</depend>
4646
<depend>tf2_ros</depend>
4747
<depend>tier4_planning_msgs</depend>
48-
<depend>tier4_v2x_msgs</depend>
4948
<depend>visualization_msgs</depend>
5049

5150
<test_depend>ament_cmake_ros</test_depend>

planning/behavior_velocity_planner/autoware_behavior_velocity_virtual_traffic_light_module/src/manager.cpp

+38-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <autoware/universe_utils/ros/parameter.hpp>
2222
#include <autoware_lanelet2_extension/utility/utilities.hpp>
2323

24+
#include <tier4_v2x_msgs/msg/infrastructure_command_array.hpp>
25+
2426
#include <boost/geometry/algorithms/intersects.hpp>
2527

2628
#include <lanelet2_core/geometry/LineString.h>
@@ -53,6 +55,14 @@ VirtualTrafficLightModuleManager::VirtualTrafficLightModuleManager(rclcpp::Node
5355
p.check_timeout_after_stop_line =
5456
getOrDeclareParameter<bool>(node, ns + ".check_timeout_after_stop_line");
5557
}
58+
59+
sub_virtual_traffic_light_states_ = autoware::universe_utils::InterProcessPollingSubscriber<
60+
tier4_v2x_msgs::msg::VirtualTrafficLightStateArray>::
61+
create_subscription(&node, "~/input/virtual_traffic_light_states");
62+
63+
pub_infrastructure_commands_ =
64+
node.create_publisher<tier4_v2x_msgs::msg::InfrastructureCommandArray>(
65+
"~/output/infrastructure_commands", 1);
5666
}
5767

5868
void VirtualTrafficLightModuleManager::launchNewModules(
@@ -89,17 +99,43 @@ void VirtualTrafficLightModuleManager::launchNewModules(
8999
}
90100
}
91101

92-
std::function<bool(const std::shared_ptr<SceneModuleInterface> &)>
102+
std::function<bool(const std::shared_ptr<VirtualTrafficLightModule> &)>
93103
VirtualTrafficLightModuleManager::getModuleExpiredFunction(
94104
const tier4_planning_msgs::msg::PathWithLaneId & path)
95105
{
96106
const auto id_set = planning_utils::getLaneletIdSetOnPath<VirtualTrafficLight>(
97107
path, planner_data_->route_handler_->getLaneletMapPtr(), planner_data_->current_odometry->pose);
98108

99-
return [id_set](const std::shared_ptr<SceneModuleInterface> & scene_module) {
109+
return [id_set](const std::shared_ptr<VirtualTrafficLightModule> & scene_module) {
100110
return id_set.count(scene_module->getModuleId()) == 0;
101111
};
102112
}
113+
114+
void VirtualTrafficLightModuleManager::modifyPathVelocity(
115+
tier4_planning_msgs::msg::PathWithLaneId * path)
116+
{
117+
// NOTE: virtual traffic light specific implementation
118+
// Since the argument of modifyPathVelocity cannot be changed, the specific information
119+
// of virtual traffic light states is set here.
120+
const auto virtual_traffic_light_states = sub_virtual_traffic_light_states_->takeData();
121+
for (const auto & scene_module : scene_modules_) {
122+
scene_module->setVirtualTrafficLightStates(virtual_traffic_light_states);
123+
}
124+
125+
SceneModuleManagerInterface<VirtualTrafficLightModule>::modifyPathVelocity(path);
126+
127+
// NOTE: virtual traffic light specific implementation
128+
// publish infrastructure_command_array
129+
tier4_v2x_msgs::msg::InfrastructureCommandArray infrastructure_command_array;
130+
infrastructure_command_array.stamp = clock_->now();
131+
132+
for (const auto & scene_module : scene_modules_) {
133+
if (const auto command = scene_module->getInfrastructureCommand()) {
134+
infrastructure_command_array.commands.push_back(*command);
135+
}
136+
}
137+
pub_infrastructure_commands_->publish(infrastructure_command_array);
138+
}
103139
} // namespace autoware::behavior_velocity_planner
104140

105141
#include <pluginlib/class_list_macros.hpp>

planning/behavior_velocity_planner/autoware_behavior_velocity_virtual_traffic_light_module/src/manager.hpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020
#include <autoware/behavior_velocity_planner_common/plugin_interface.hpp>
2121
#include <autoware/behavior_velocity_planner_common/plugin_wrapper.hpp>
2222
#include <autoware/behavior_velocity_planner_common/scene_module_interface.hpp>
23+
#include <autoware/universe_utils/ros/polling_subscriber.hpp>
2324
#include <rclcpp/rclcpp.hpp>
2425

2526
#include <tier4_planning_msgs/msg/path_with_lane_id.hpp>
27+
#include <tier4_v2x_msgs/msg/infrastructure_command_array.hpp>
28+
#include <tier4_v2x_msgs/msg/virtual_traffic_light_state_array.hpp>
2629

2730
#include <functional>
2831
#include <memory>
2932

3033
namespace autoware::behavior_velocity_planner
3134
{
32-
class VirtualTrafficLightModuleManager : public SceneModuleManagerInterface<>
35+
class VirtualTrafficLightModuleManager
36+
: public SceneModuleManagerInterface<VirtualTrafficLightModule>
3337
{
3438
public:
3539
explicit VirtualTrafficLightModuleManager(rclcpp::Node & node);
@@ -38,10 +42,20 @@ class VirtualTrafficLightModuleManager : public SceneModuleManagerInterface<>
3842

3943
private:
4044
VirtualTrafficLightModule::PlannerParam planner_param_;
45+
46+
void modifyPathVelocity(tier4_planning_msgs::msg::PathWithLaneId * path) override;
47+
4148
void launchNewModules(const tier4_planning_msgs::msg::PathWithLaneId & path) override;
4249

43-
std::function<bool(const std::shared_ptr<SceneModuleInterface> &)> getModuleExpiredFunction(
50+
std::function<bool(const std::shared_ptr<VirtualTrafficLightModule> &)> getModuleExpiredFunction(
4451
const tier4_planning_msgs::msg::PathWithLaneId & path) override;
52+
53+
autoware::universe_utils::InterProcessPollingSubscriber<
54+
tier4_v2x_msgs::msg::VirtualTrafficLightStateArray>::SharedPtr
55+
sub_virtual_traffic_light_states_;
56+
57+
rclcpp::Publisher<tier4_v2x_msgs::msg::InfrastructureCommandArray>::SharedPtr
58+
pub_infrastructure_commands_;
4559
};
4660

4761
class VirtualTrafficLightModulePlugin : public PluginWrapper<VirtualTrafficLightModuleManager>

planning/behavior_velocity_planner/autoware_behavior_velocity_virtual_traffic_light_module/src/scene.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ bool VirtualTrafficLightModule::isNearAnyEndLine(const size_t end_line_idx)
333333
std::optional<tier4_v2x_msgs::msg::VirtualTrafficLightState>
334334
VirtualTrafficLightModule::findCorrespondingState()
335335
{
336-
// No message
337-
if (!planner_data_->virtual_traffic_light_states) {
336+
// Note: This variable is set by virtual traffic light's manager.
337+
if (!virtual_traffic_light_states_) {
338338
return {};
339339
}
340340

341-
for (const auto & state : planner_data_->virtual_traffic_light_states->states) {
341+
for (const auto & state : virtual_traffic_light_states_->states) {
342342
if (state.id == map_data_.instrument_id) {
343343
return state;
344344
}
@@ -457,4 +457,23 @@ void VirtualTrafficLightModule::insertStopVelocityAtEndLine(
457457
module_data_.stop_head_pose_at_end_line =
458458
calcHeadPose(stop_pose, planner_data_->vehicle_info_.max_longitudinal_offset_m);
459459
}
460+
461+
std::optional<tier4_v2x_msgs::msg::InfrastructureCommand>
462+
VirtualTrafficLightModule::getInfrastructureCommand() const
463+
{
464+
return infrastructure_command_;
465+
}
466+
467+
void VirtualTrafficLightModule::setInfrastructureCommand(
468+
const std::optional<tier4_v2x_msgs::msg::InfrastructureCommand> & command)
469+
{
470+
infrastructure_command_ = command;
471+
}
472+
473+
void VirtualTrafficLightModule::setVirtualTrafficLightStates(
474+
const tier4_v2x_msgs::msg::VirtualTrafficLightStateArray::ConstSharedPtr
475+
virtual_traffic_light_states)
476+
{
477+
virtual_traffic_light_states_ = virtual_traffic_light_states;
478+
}
460479
} // namespace autoware::behavior_velocity_planner

planning/behavior_velocity_planner/autoware_behavior_velocity_virtual_traffic_light_module/src/scene.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
#include <autoware/behavior_velocity_planner_common/scene_module_interface.hpp>
1919
#include <autoware/universe_utils/geometry/boost_geometry.hpp>
20+
#include <autoware/universe_utils/ros/polling_subscriber.hpp>
2021
#include <autoware_lanelet2_extension/regulatory_elements/virtual_traffic_light.hpp>
2122
#include <autoware_lanelet2_extension/utility/query.hpp>
2223
#include <autoware_vehicle_info_utils/vehicle_info.hpp>
2324
#include <nlohmann/json.hpp>
2425
#include <rclcpp/clock.hpp>
2526
#include <rclcpp/logger.hpp>
2627

28+
#include <tier4_v2x_msgs/msg/infrastructure_command_array.hpp>
29+
#include <tier4_v2x_msgs/msg/virtual_traffic_light_state_array.hpp>
30+
2731
#include <lanelet2_core/LaneletMap.h>
2832
#include <lanelet2_routing/RoutingGraph.h>
2933

@@ -84,13 +88,23 @@ class VirtualTrafficLightModule : public SceneModuleInterface
8488
visualization_msgs::msg::MarkerArray createDebugMarkerArray() override;
8589
autoware::motion_utils::VirtualWalls createVirtualWalls() override;
8690

91+
std::optional<tier4_v2x_msgs::msg::InfrastructureCommand> getInfrastructureCommand() const;
92+
void setInfrastructureCommand(
93+
const std::optional<tier4_v2x_msgs::msg::InfrastructureCommand> & command);
94+
95+
void setVirtualTrafficLightStates(
96+
const tier4_v2x_msgs::msg::VirtualTrafficLightStateArray::ConstSharedPtr
97+
virtual_traffic_light_states);
98+
8799
private:
88100
const int64_t lane_id_;
89101
const lanelet::autoware::VirtualTrafficLight & reg_elem_;
90102
const lanelet::ConstLanelet lane_;
91103
const PlannerParam planner_param_;
104+
tier4_v2x_msgs::msg::VirtualTrafficLightStateArray::ConstSharedPtr virtual_traffic_light_states_;
92105
State state_{State::NONE};
93106
tier4_v2x_msgs::msg::InfrastructureCommand command_;
107+
std::optional<tier4_v2x_msgs::msg::InfrastructureCommand> infrastructure_command_;
94108
MapData map_data_;
95109
ModuleData module_data_;
96110

planning/behavior_velocity_planner/autoware_behavior_velocity_virtual_traffic_light_module/test/test_node_interface.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ namespace autoware::behavior_velocity_planner
2626
TEST(PlanningModuleInterfaceTest, NodeTestWithExceptionPathWithLaneID)
2727
{
2828
rclcpp::init(0, nullptr);
29+
30+
const auto plugin_info_vec = {autoware::behavior_velocity_planner::PluginInfo{
31+
"virtual_traffic_light",
32+
"autoware::behavior_velocity_planner::VirtualTrafficLightModulePlugin"}};
33+
2934
auto test_manager = autoware::behavior_velocity_planner::generateTestManager();
30-
auto test_target_node = autoware::behavior_velocity_planner::generateNode({});
35+
auto test_target_node = autoware::behavior_velocity_planner::generateNode(plugin_info_vec);
3136

3237
autoware::behavior_velocity_planner::publishMandatoryTopics(test_manager, test_target_node);
38+
test_manager->publishVirtualTrafficLightState(
39+
test_target_node, "behavior_velocity_planner_node/input/virtual_traffic_light_states");
3340

3441
// test with nominal path_with_lane_id
3542
ASSERT_NO_THROW_WITH_ERROR_MSG(test_manager->testWithNominalPathWithLaneId(test_target_node));
@@ -51,6 +58,8 @@ TEST(PlanningModuleInterfaceTest, NodeTestWithOffTrackEgoPose)
5158
auto test_manager = autoware::behavior_velocity_planner::generateTestManager();
5259
auto test_target_node = autoware::behavior_velocity_planner::generateNode(plugin_info_vec);
5360
autoware::behavior_velocity_planner::publishMandatoryTopics(test_manager, test_target_node);
61+
test_manager->publishVirtualTrafficLightState(
62+
test_target_node, "behavior_velocity_planner_node/input/virtual_traffic_light_states");
5463

5564
// test for normal trajectory
5665
ASSERT_NO_THROW_WITH_ERROR_MSG(test_manager->testWithNominalPathWithLaneId(test_target_node));

0 commit comments

Comments
 (0)