realsense_node_factory.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2023 RealSense, Inc. All Rights Reserved.
  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. #pragma once
  15. // cpplint: c system headers
  16. #include "constants.h"
  17. #include "base_realsense_node.h"
  18. #include <builtin_interfaces/msg/time.hpp>
  19. #include <console_bridge/console.h>
  20. #include "rclcpp_components/register_node_macro.hpp"
  21. #include "ros_node_base.h"
  22. #include <algorithm>
  23. #include <csignal>
  24. #include <iostream>
  25. #include <limits>
  26. #include <map>
  27. #include <memory>
  28. #include <string>
  29. #include <utility>
  30. #include <vector>
  31. #include <thread>
  32. namespace realsense2_camera
  33. {
  34. class RealSenseNodeFactory : public RosNodeBase
  35. {
  36. public:
  37. explicit RealSenseNodeFactory(const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions());
  38. RealSenseNodeFactory(
  39. const std::string & node_name, const std::string & ns,
  40. const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions());
  41. virtual ~RealSenseNodeFactory();
  42. #ifdef USE_LIFECYCLE_NODE
  43. using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
  44. CallbackReturn on_configure(const rclcpp_lifecycle::State & state) override;
  45. CallbackReturn on_activate(const rclcpp_lifecycle::State & state) override;
  46. CallbackReturn on_deactivate(const rclcpp_lifecycle::State & state) override;
  47. CallbackReturn on_cleanup(const rclcpp_lifecycle::State & state) override;
  48. CallbackReturn on_shutdown(const rclcpp_lifecycle::State & state) override;
  49. #endif
  50. private:
  51. void init();
  52. void closeDevice();
  53. void startDevice();
  54. void stopDevice();
  55. void changeDeviceCallback(rs2::event_information& info);
  56. void getDevice(rs2::device_list list);
  57. void tryGetLogSeverity(rs2_log_severity& severity) const;
  58. static std::string parseUsbPort(std::string line);
  59. RosNodeBase::SharedPtr _node;
  60. rs2::device _device;
  61. std::unique_ptr<BaseRealSenseNode> _realSenseNode;
  62. std::string _serial_no;
  63. std::string _usb_port_id;
  64. std::string _device_type;
  65. double _wait_for_device_timeout;
  66. double _reconnect_timeout;
  67. bool _initial_reset;
  68. std::thread _query_thread;
  69. bool _is_alive;
  70. rclcpp::Logger _logger;
  71. std::shared_ptr<Parameters> _parameters;
  72. };
  73. }//end namespace