|
| 1 | +// Copyright 2025 TIER IV, Inc. |
| 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 | +#include "traffic_light_category_merger_node.hpp" |
| 16 | + |
| 17 | +#include <memory> |
| 18 | +#include <string> |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +namespace autoware::traffic_light |
| 22 | +{ |
| 23 | + |
| 24 | +TrafficLightCategoryMergerNode::TrafficLightCategoryMergerNode( |
| 25 | + const rclcpp::NodeOptions & node_options) |
| 26 | +: rclcpp::Node("traffic_light_category_merger_node", node_options), |
| 27 | + tf_buffer_(get_clock()), |
| 28 | + tf_listener_(tf_buffer_), |
| 29 | + car_signal_sub_(this, "input/car_signals", rclcpp::QoS{1}.get_rmw_qos_profile()), |
| 30 | + pedestrian_signal_sub_(this, "input/pedestrian_signals", rclcpp::QoS{1}.get_rmw_qos_profile()), |
| 31 | + sync_(SyncPolicy(10), car_signal_sub_, pedestrian_signal_sub_) |
| 32 | +{ |
| 33 | + using std::placeholders::_1; |
| 34 | + using std::placeholders::_2; |
| 35 | + sync_.registerCallback(std::bind(&TrafficLightCategoryMergerNode::signalsCallback, this, _1, _2)); |
| 36 | + pub_traffic_light_signals_ = |
| 37 | + create_publisher<TrafficLightArray>("output/traffic_signals", rclcpp::QoS{1}); |
| 38 | +} |
| 39 | + |
| 40 | +void TrafficLightCategoryMergerNode::signalsCallback( |
| 41 | + const TrafficLightArray::ConstSharedPtr & car_signals_msg, |
| 42 | + const TrafficLightArray::ConstSharedPtr & pedestrian_signals_msg) |
| 43 | +{ |
| 44 | + TrafficLightArray output; |
| 45 | + output.header = car_signals_msg->header; |
| 46 | + output.signals.insert( |
| 47 | + output.signals.end(), car_signals_msg->signals.begin(), car_signals_msg->signals.end()); |
| 48 | + output.signals.insert( |
| 49 | + output.signals.end(), pedestrian_signals_msg->signals.begin(), |
| 50 | + pedestrian_signals_msg->signals.end()); |
| 51 | + pub_traffic_light_signals_->publish(output); |
| 52 | +} |
| 53 | + |
| 54 | +} // namespace autoware::traffic_light |
| 55 | + |
| 56 | +#include "rclcpp_components/register_node_macro.hpp" |
| 57 | +RCLCPP_COMPONENTS_REGISTER_NODE(autoware::traffic_light::TrafficLightCategoryMergerNode) |
0 commit comments