profile_manager.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include <librealsense2/rs.hpp>
  16. #include <sensor_params.h>
  17. #define STREAM_NAME(sip) (static_cast<std::ostringstream&&>(std::ostringstream() << create_graph_resource_name(ros_stream_to_string(sip.first)) << ((sip.second>0) ? std::to_string(sip.second) : ""))).str()
  18. using namespace rs2;
  19. namespace realsense2_camera
  20. {
  21. typedef std::pair<rs2_stream, int> stream_index_pair;
  22. class ProfilesManager
  23. {
  24. public:
  25. ProfilesManager(std::shared_ptr<Parameters> parameters, rclcpp::Logger logger);
  26. virtual bool isWantedProfile(const rs2::stream_profile& profile) = 0;
  27. virtual void registerProfileParameters(std::vector<stream_profile> all_profiles, std::function<void()> update_sensor_func) = 0;
  28. bool isTypeExist();
  29. static std::string profile_string(const rs2::stream_profile& profile);
  30. void registerSensorQOSParam(std::string template_name,
  31. std::set<stream_index_pair> unique_sips,
  32. std::map<stream_index_pair, std::shared_ptr<std::string> >& params,
  33. std::string value);
  34. template<class T>
  35. void registerSensorUpdateParam(std::string template_name,
  36. std::set<stream_index_pair> unique_sips,
  37. std::map<stream_index_pair, std::shared_ptr<T> >& params,
  38. T value,
  39. std::function<void()> update_sensor_func);
  40. void addWantedProfiles(std::vector<rs2::stream_profile>& wanted_profiles);
  41. void clearParameters();
  42. bool hasSIP(const stream_index_pair& sip) const;
  43. rmw_qos_profile_t getQOS(const stream_index_pair& sip) const;
  44. rmw_qos_profile_t getInfoQOS(const stream_index_pair& sip) const;
  45. protected:
  46. std::map<stream_index_pair, rs2::stream_profile> getDefaultProfiles();
  47. protected:
  48. rclcpp::Logger _logger;
  49. SensorParams _params;
  50. std::map<stream_index_pair, std::shared_ptr<bool>> _enabled_profiles;
  51. std::map<stream_index_pair, std::shared_ptr<std::string>> _profiles_image_qos_str, _profiles_info_qos_str;
  52. std::vector<rs2::stream_profile> _all_profiles;
  53. std::vector<std::string> _parameters_names;
  54. };
  55. class VideoProfilesManager : public ProfilesManager
  56. {
  57. public:
  58. VideoProfilesManager(std::shared_ptr<Parameters> parameters, const std::string& module_name, rclcpp::Logger logger, bool force_image_default_qos = false);
  59. bool isWantedProfile(const rs2::stream_profile& profile) override;
  60. void registerProfileParameters(std::vector<stream_profile> all_profiles, std::function<void()> update_sensor_func) override;
  61. int getHeight(rs2_stream stream_type) {return _height[stream_type];};
  62. int getWidth(rs2_stream stream_type) {return _width[stream_type];};
  63. int getFPS(rs2_stream stream_type) {return _fps[stream_type];};
  64. private:
  65. bool isSameProfileValues(const rs2::stream_profile& profile, const int width, const int height, const int fps, const rs2_format format);
  66. rs2::stream_profile validateAndGetSuitableProfile(rs2_stream stream_type, rs2::stream_profile given_profile);
  67. void registerVideoSensorProfileFormat(stream_index_pair sip);
  68. void registerVideoSensorParams(std::set<stream_index_pair> sips);
  69. std::string get_profiles_descriptions(rs2_stream stream_type);
  70. std::string getProfileFormatsDescriptions(stream_index_pair sip);
  71. private:
  72. std::string _module_name;
  73. std::map<stream_index_pair, rs2_format> _formats;
  74. std::map<rs2_stream, int> _fps, _width, _height;
  75. bool _force_image_default_qos;
  76. };
  77. class MotionProfilesManager : public ProfilesManager
  78. {
  79. public:
  80. using ProfilesManager::ProfilesManager;
  81. bool isWantedProfile(const rs2::stream_profile& profile) override;
  82. void registerProfileParameters(std::vector<stream_profile> all_profiles, std::function<void()> update_sensor_func) override;
  83. private:
  84. void registerFPSParams();
  85. bool isSameProfileValues(const rs2::stream_profile& profile, const rs2_stream stype, const int fps);
  86. std::map<stream_index_pair, std::vector<int>> getAvailableFPSValues();
  87. protected:
  88. std::map<stream_index_pair, std::shared_ptr<int> > _fps;
  89. };
  90. }