From 86b39a2d4589ffe7c35f8d2df77187cda8f7406d Mon Sep 17 00:00:00 2001 From: Taekjin LEE Date: Mon, 22 Jul 2024 14:12:30 +0900 Subject: [PATCH] refactor(traffic_light_fine_detector): fix namespace and directory structure (#7973) * refactor: add autoware on the namespace Signed-off-by: Taekjin LEE * refactor: rename nodelet to node Signed-off-by: Taekjin LEE --------- Signed-off-by: Taekjin LEE --- .../traffic_light_node_container.launch.py | 2 +- .../CMakeLists.txt | 12 +++---- ...p => traffic_light_fine_detector_node.cpp} | 34 +++++++++---------- .../traffic_light_fine_detector_node.hpp} | 16 ++++----- 4 files changed, 31 insertions(+), 33 deletions(-) rename perception/traffic_light_fine_detector/src/{nodelet.cpp => traffic_light_fine_detector_node.cpp} (93%) rename perception/traffic_light_fine_detector/{include/traffic_light_fine_detector/nodelet.hpp => src/traffic_light_fine_detector_node.hpp} (93%) diff --git a/launch/tier4_perception_launch/launch/traffic_light_recognition/traffic_light_node_container.launch.py b/launch/tier4_perception_launch/launch/traffic_light_recognition/traffic_light_node_container.launch.py index 6e77fa71cd553..ddf825921e468 100644 --- a/launch/tier4_perception_launch/launch/traffic_light_recognition/traffic_light_node_container.launch.py +++ b/launch/tier4_perception_launch/launch/traffic_light_recognition/traffic_light_node_container.launch.py @@ -137,7 +137,7 @@ def create_parameter_dict(*args): composable_node_descriptions=[ ComposableNode( package="traffic_light_fine_detector", - plugin="traffic_light::TrafficLightFineDetectorNodelet", + plugin="autoware::traffic_light::TrafficLightFineDetectorNode", name="traffic_light_fine_detector", namespace="detection", parameters=[fine_detector_model_param], diff --git a/perception/traffic_light_fine_detector/CMakeLists.txt b/perception/traffic_light_fine_detector/CMakeLists.txt index fe9fa2ffcaa8b..6b7e421d8d0a9 100644 --- a/perception/traffic_light_fine_detector/CMakeLists.txt +++ b/perception/traffic_light_fine_detector/CMakeLists.txt @@ -75,15 +75,15 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL) ${CUDA_INCLUDE_DIRS} ) - ament_auto_add_library(traffic_light_fine_detector_nodelet SHARED - src/nodelet.cpp + ament_auto_add_library(${PROJECT_NAME} SHARED + src/traffic_light_fine_detector_node.cpp ) - target_include_directories(traffic_light_fine_detector_nodelet PUBLIC + target_include_directories(${PROJECT_NAME} PUBLIC lib/include ) - target_link_libraries(traffic_light_fine_detector_nodelet + target_link_libraries(${PROJECT_NAME} ${NVINFER} ${NVONNXPARSER} ${NVINFER_PLUGIN} @@ -94,8 +94,8 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL) stdc++fs ) - rclcpp_components_register_node(traffic_light_fine_detector_nodelet - PLUGIN "traffic_light::TrafficLightFineDetectorNodelet" + rclcpp_components_register_node(${PROJECT_NAME} + PLUGIN "autoware::traffic_light::TrafficLightFineDetectorNode" EXECUTABLE traffic_light_fine_detector_node ) diff --git a/perception/traffic_light_fine_detector/src/nodelet.cpp b/perception/traffic_light_fine_detector/src/traffic_light_fine_detector_node.cpp similarity index 93% rename from perception/traffic_light_fine_detector/src/nodelet.cpp rename to perception/traffic_light_fine_detector/src/traffic_light_fine_detector_node.cpp index 8037dc5472fbe..d22a3f2074a7b 100644 --- a/perception/traffic_light_fine_detector/src/nodelet.cpp +++ b/perception/traffic_light_fine_detector/src/traffic_light_fine_detector_node.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "traffic_light_fine_detector/nodelet.hpp" +#include "traffic_light_fine_detector_node.hpp" #if (defined(_MSC_VER) or (defined(__GNUC__) and (7 <= __GNUC_MAJOR__))) #include @@ -22,6 +22,7 @@ namespace fs = ::std::filesystem; namespace fs = ::std::experimental::filesystem; #endif +#include #include #include #include @@ -46,15 +47,14 @@ float calWeightedIou( } // namespace -namespace traffic_light +namespace autoware::traffic_light { inline std::vector toFloatVector(const std::vector double_vector) { return std::vector(double_vector.begin(), double_vector.end()); } -TrafficLightFineDetectorNodelet::TrafficLightFineDetectorNodelet( - const rclcpp::NodeOptions & options) +TrafficLightFineDetectorNode::TrafficLightFineDetectorNode(const rclcpp::NodeOptions & options) : Node("traffic_light_fine_detector_node", options) { int num_class = 2; @@ -95,7 +95,7 @@ TrafficLightFineDetectorNodelet::TrafficLightFineDetectorNodelet( using std::chrono_literals::operator""ms; timer_ = rclcpp::create_timer( - this, get_clock(), 100ms, std::bind(&TrafficLightFineDetectorNodelet::connectCb, this)); + this, get_clock(), 100ms, std::bind(&TrafficLightFineDetectorNode::connectCb, this)); std::lock_guard lock(connect_mutex_); output_roi_pub_ = this->create_publisher("~/output/rois", 1); @@ -105,11 +105,10 @@ TrafficLightFineDetectorNodelet::TrafficLightFineDetectorNodelet( approximate_sync_.reset( new ApproximateSync(ApproximateSyncPolicy(10), image_sub_, rough_roi_sub_, expect_roi_sub_)); approximate_sync_->registerCallback( - std::bind(&TrafficLightFineDetectorNodelet::callback, this, _1, _2, _3)); + std::bind(&TrafficLightFineDetectorNode::callback, this, _1, _2, _3)); } else { sync_.reset(new Sync(SyncPolicy(10), image_sub_, rough_roi_sub_, expect_roi_sub_)); - sync_->registerCallback( - std::bind(&TrafficLightFineDetectorNodelet::callback, this, _1, _2, _3)); + sync_->registerCallback(std::bind(&TrafficLightFineDetectorNode::callback, this, _1, _2, _3)); } if (declare_parameter("build_only", false)) { @@ -118,7 +117,7 @@ TrafficLightFineDetectorNodelet::TrafficLightFineDetectorNodelet( } } -void TrafficLightFineDetectorNodelet::connectCb() +void TrafficLightFineDetectorNode::connectCb() { std::lock_guard lock(connect_mutex_); if (output_roi_pub_->get_subscription_count() == 0) { @@ -132,7 +131,7 @@ void TrafficLightFineDetectorNodelet::connectCb() } } -void TrafficLightFineDetectorNodelet::callback( +void TrafficLightFineDetectorNode::callback( const sensor_msgs::msg::Image::ConstSharedPtr in_image_msg, const TrafficLightRoiArray::ConstSharedPtr rough_roi_msg, const TrafficLightRoiArray::ConstSharedPtr expect_roi_msg) @@ -213,7 +212,7 @@ void TrafficLightFineDetectorNodelet::callback( exe_time_pub_->publish(exe_time_msg); } -float TrafficLightFineDetectorNodelet::evalMatchScore( +float TrafficLightFineDetectorNode::evalMatchScore( std::map & id2expectRoi, std::map & id2detections, std::map & id2bestDetection) @@ -236,7 +235,7 @@ float TrafficLightFineDetectorNodelet::evalMatchScore( return score_sum; } -void TrafficLightFineDetectorNodelet::detectionMatch( +void TrafficLightFineDetectorNode::detectionMatch( std::map & id2expectRoi, std::map & id2detections, TrafficLightRoiArray & out_rois) { @@ -298,7 +297,7 @@ void TrafficLightFineDetectorNodelet::detectionMatch( } } -bool TrafficLightFineDetectorNodelet::rosMsg2CvMat( +bool TrafficLightFineDetectorNode::rosMsg2CvMat( const sensor_msgs::msg::Image::ConstSharedPtr image_msg, cv::Mat & image, std::string encode) { try { @@ -313,8 +312,7 @@ bool TrafficLightFineDetectorNodelet::rosMsg2CvMat( return true; } -bool TrafficLightFineDetectorNodelet::fitInFrame( - cv::Point & lt, cv::Point & rb, const cv::Size & size) +bool TrafficLightFineDetectorNode::fitInFrame(cv::Point & lt, cv::Point & rb, const cv::Size & size) { const int width = static_cast(size.width); const int height = static_cast(size.height); @@ -334,7 +332,7 @@ bool TrafficLightFineDetectorNodelet::fitInFrame( return true; } -bool TrafficLightFineDetectorNodelet::readLabelFile( +bool TrafficLightFineDetectorNode::readLabelFile( const std::string & filepath, std::vector & tlr_label_id_, int & num_class) { std::ifstream labelsFile(filepath); @@ -354,7 +352,7 @@ bool TrafficLightFineDetectorNodelet::readLabelFile( return tlr_label_id_.size() != 0; } -} // namespace traffic_light +} // namespace autoware::traffic_light #include -RCLCPP_COMPONENTS_REGISTER_NODE(traffic_light::TrafficLightFineDetectorNodelet) +RCLCPP_COMPONENTS_REGISTER_NODE(autoware::traffic_light::TrafficLightFineDetectorNode) diff --git a/perception/traffic_light_fine_detector/include/traffic_light_fine_detector/nodelet.hpp b/perception/traffic_light_fine_detector/src/traffic_light_fine_detector_node.hpp similarity index 93% rename from perception/traffic_light_fine_detector/include/traffic_light_fine_detector/nodelet.hpp rename to perception/traffic_light_fine_detector/src/traffic_light_fine_detector_node.hpp index 5c89c76a11833..a5ae22946e9ab 100644 --- a/perception/traffic_light_fine_detector/include/traffic_light_fine_detector/nodelet.hpp +++ b/perception/traffic_light_fine_detector/src/traffic_light_fine_detector_node.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef TRAFFIC_LIGHT_FINE_DETECTOR__NODELET_HPP_ -#define TRAFFIC_LIGHT_FINE_DETECTOR__NODELET_HPP_ +#ifndef TRAFFIC_LIGHT_FINE_DETECTOR_NODE_HPP_ +#define TRAFFIC_LIGHT_FINE_DETECTOR_NODE_HPP_ #include #include @@ -50,15 +50,15 @@ typedef struct Detection float x, y, w, h, prob; } Detection; -namespace traffic_light +namespace autoware::traffic_light { -class TrafficLightFineDetectorNodelet : public rclcpp::Node +class TrafficLightFineDetectorNode : public rclcpp::Node { using TrafficLightRoi = tier4_perception_msgs::msg::TrafficLightRoi; using TrafficLightRoiArray = tier4_perception_msgs::msg::TrafficLightRoiArray; public: - explicit TrafficLightFineDetectorNodelet(const rclcpp::NodeOptions & options); + explicit TrafficLightFineDetectorNode(const rclcpp::NodeOptions & options); void connectCb(); /** * @brief main process function. @@ -168,8 +168,8 @@ class TrafficLightFineDetectorNodelet : public rclcpp::Node int batch_size_; std::unique_ptr trt_yolox_; -}; // TrafficLightFineDetectorNodelet +}; // TrafficLightFineDetectorNode -} // namespace traffic_light +} // namespace autoware::traffic_light -#endif // TRAFFIC_LIGHT_FINE_DETECTOR__NODELET_HPP_ +#endif // TRAFFIC_LIGHT_FINE_DETECTOR_NODE_HPP_