|
| 1 | +/********************************************************************************************************************* |
| 2 | +Copyright (c) 2020 RoboSense |
| 3 | +All rights reserved |
| 4 | +
|
| 5 | +By downloading, copying, installing or using the software you agree to this license. If you do not agree to this |
| 6 | +license, do not download, install, copy or use the software. |
| 7 | +
|
| 8 | +License Agreement |
| 9 | +For RoboSense LiDAR SDK Library |
| 10 | +(3-clause BSD License) |
| 11 | +
|
| 12 | +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the |
| 13 | +following conditions are met: |
| 14 | +
|
| 15 | +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following |
| 16 | +disclaimer. |
| 17 | +
|
| 18 | +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following |
| 19 | +disclaimer in the documentation and/or other materials provided with the distribution. |
| 20 | +
|
| 21 | +3. Neither the names of the RoboSense, nor Suteng Innovation Technology, nor the names of other contributors may be used |
| 22 | +to endorse or promote products derived from this software without specific prior written permission. |
| 23 | +
|
| 24 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 25 | +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 | +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 28 | +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 30 | +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | +*********************************************************************************************************************/ |
| 32 | + |
| 33 | +#include "manager/node_manager.hpp" |
| 34 | +#include <rs_driver/macro/version.hpp> |
| 35 | +#include <rclcpp/rclcpp.hpp> |
| 36 | +#include <rclcpp_components/register_node_macro.hpp> |
| 37 | +#include <memory> |
| 38 | +#include <thread> |
| 39 | +#include <csignal> |
| 40 | + |
| 41 | +namespace robosense |
| 42 | +{ |
| 43 | +namespace lidar |
| 44 | +{ |
| 45 | + |
| 46 | +class RSLidarSDKComponent : public rclcpp::Node |
| 47 | +{ |
| 48 | +public: |
| 49 | + explicit RSLidarSDKComponent(const rclcpp::NodeOptions & options) |
| 50 | + : Node("rslidar_sdk_node_component", options) |
| 51 | + { |
| 52 | + // Print version information |
| 53 | + RCLCPP_INFO(this->get_logger(), "********************************************************"); |
| 54 | + RCLCPP_INFO(this->get_logger(), "********** **********"); |
| 55 | + RCLCPP_INFO(this->get_logger(), "********** RSLidar_SDK Version: v%d.%d.%d **********", |
| 56 | + RSLIDAR_VERSION_MAJOR, RSLIDAR_VERSION_MINOR, RSLIDAR_VERSION_PATCH); |
| 57 | + RCLCPP_INFO(this->get_logger(), "********** **********"); |
| 58 | + RCLCPP_INFO(this->get_logger(), "********************************************************"); |
| 59 | + |
| 60 | + // Set up config path |
| 61 | + std::string config_path; |
| 62 | + |
| 63 | +#ifdef RUN_IN_ROS_WORKSPACE |
| 64 | + config_path = ament_index_cpp::get_package_share_directory("rslidar_sdk"); |
| 65 | +#else |
| 66 | + config_path = (std::string)PROJECT_PATH; |
| 67 | +#endif |
| 68 | + |
| 69 | + config_path += "/config/config.yaml"; |
| 70 | + |
| 71 | + std::string path = this->declare_parameter<std::string>("config_path", ""); |
| 72 | + if (!path.empty()) |
| 73 | + { |
| 74 | + config_path = path; |
| 75 | + } |
| 76 | + |
| 77 | + YAML::Node config; |
| 78 | + try |
| 79 | + { |
| 80 | + config = YAML::LoadFile(config_path); |
| 81 | + RCLCPP_INFO(this->get_logger(), "--------------------------------------------------------"); |
| 82 | + RCLCPP_INFO(this->get_logger(), "Config loaded from PATH:"); |
| 83 | + RCLCPP_INFO(this->get_logger(), "%s", config_path.c_str()); |
| 84 | + RCLCPP_INFO(this->get_logger(), "--------------------------------------------------------"); |
| 85 | + } |
| 86 | + catch (...) |
| 87 | + { |
| 88 | + RCLCPP_ERROR(this->get_logger(), "The format of config file %s is wrong. Please check (e.g. indentation).", |
| 89 | + config_path.c_str()); |
| 90 | + throw std::runtime_error("Failed to load config file"); |
| 91 | + } |
| 92 | + |
| 93 | + node_manager_ = std::make_shared<NodeManager>(); |
| 94 | + node_manager_->init(config); |
| 95 | + node_manager_->start(); |
| 96 | + } |
| 97 | + |
| 98 | +private: |
| 99 | + std::shared_ptr<NodeManager> node_manager_; |
| 100 | +}; |
| 101 | + |
| 102 | +} // namespace lidar |
| 103 | +} // namespace robosense |
| 104 | + |
| 105 | +// Register the component with class_loader |
| 106 | +RCLCPP_COMPONENTS_REGISTER_NODE(robosense::lidar::RSLidarSDKComponent) |
0 commit comments