base_nodelet.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  Copyright (c) 2017, Intel Corporation
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without
00006  modification, are permitted provided that the following conditions are met:
00007 
00008  1. Redistributions of source code must retain the above copyright notice, this
00009  list of conditions and the following disclaimer.
00010 
00011  2. Redistributions in binary form must reproduce the above copyright notice,
00012  this list of conditions and the following disclaimer in the documentation
00013  and/or other materials provided with the distribution.
00014 
00015  3. Neither the name of the copyright holder nor the names of its contributors
00016  may be used to endorse or promote products derived from this software without
00017  specific prior written permission.
00018 
00019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00023  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00025  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *******************************************************************************/
00030 
00031 #pragma once
00032 #ifndef REALSENSE_CAMERA_BASE_NODELET_H
00033 #define REALSENSE_CAMERA_BASE_NODELET_H
00034 
00035 #include <iostream>
00036 #include <boost/thread.hpp>
00037 #include <boost/algorithm/string/join.hpp>
00038 #include <thread>  // NOLINT(build/c++11)
00039 #include <cstdlib>
00040 #include <cctype>
00041 #include <algorithm>
00042 #include <sstream>
00043 #include <memory>
00044 #include <map>
00045 #include <queue>
00046 #include <unistd.h>
00047 #include <signal.h>
00048 #include <string>
00049 #include <vector>
00050 
00051 #include <opencv2/core/core.hpp>
00052 #include <cv_bridge/cv_bridge.h>
00053 #include <opencv2/highgui/highgui.hpp>
00054 
00055 #include <ros/ros.h>
00056 #include <nodelet/nodelet.h>
00057 #include <sensor_msgs/PointCloud2.h>
00058 #include <sensor_msgs/image_encodings.h>
00059 #include <sensor_msgs/point_cloud2_iterator.h>
00060 #include <std_msgs/String.h>
00061 #include <std_msgs/Float32MultiArray.h>
00062 #include <image_transport/image_transport.h>
00063 #include <camera_info_manager/camera_info_manager.h>
00064 #include <librealsense/rs.hpp>
00065 #include <pluginlib/class_list_macros.h>
00066 #include <tf/transform_broadcaster.h>
00067 #include <tf2_ros/static_transform_broadcaster.h>
00068 
00069 #include <realsense_camera/CameraConfiguration.h>
00070 #include <realsense_camera/IsPowered.h>
00071 #include <realsense_camera/SetPower.h>
00072 #include <realsense_camera/ForcePower.h>
00073 #include <realsense_camera/constants.h>
00074 
00075 namespace realsense_camera
00076 {
00077 class BaseNodelet: public nodelet::Nodelet
00078 {
00079 public:
00080   // Interfaces.
00081   virtual void onInit();
00082   virtual ~BaseNodelet();
00083   virtual void setDepthEnable(bool &enable_depth);
00084   virtual bool getCameraOptionValues(realsense_camera::CameraConfiguration::Request & req,
00085       realsense_camera::CameraConfiguration::Response & res);
00086   virtual bool setPowerCameraService(realsense_camera::SetPower::Request & req,
00087       realsense_camera::SetPower::Response & res);
00088   virtual bool forcePowerCameraService(realsense_camera::ForcePower::Request & req,
00089       realsense_camera::ForcePower::Response & res);
00090   virtual bool isPoweredCameraService(realsense_camera::IsPowered::Request & req,
00091       realsense_camera::IsPowered::Response & res);
00092 
00093 protected:
00094   // Member Variables.
00095   ros::NodeHandle nh_;
00096   ros::NodeHandle pnh_;
00097   ros::Time camera_start_ts_;
00098   ros::Publisher pointcloud_publisher_;
00099   ros::ServiceServer get_options_service_;
00100   ros::ServiceServer set_power_service_;
00101   ros::ServiceServer force_power_service_;
00102   ros::ServiceServer is_powered_service_;
00103   rs_error *rs_error_ = NULL;
00104   rs_context *rs_context_ = NULL;
00105   rs_device *rs_device_;
00106   std::string nodelet_name_;
00107   std::string serial_no_;
00108   std::string usb_port_id_;
00109   std::string camera_type_;
00110   std::string mode_;
00111   bool enable_[STREAM_COUNT] = {false};
00112   int width_[STREAM_COUNT];
00113   int height_[STREAM_COUNT];
00114   int fps_[STREAM_COUNT];
00115   rs_format format_[STREAM_COUNT];
00116   std::string encoding_[STREAM_COUNT];
00117   int cv_type_[STREAM_COUNT];
00118   int unit_step_size_[STREAM_COUNT];
00119   int step_[STREAM_COUNT];
00120   double ts_[STREAM_COUNT];
00121   std::string frame_id_[STREAM_COUNT];
00122   std::string optical_frame_id_[STREAM_COUNT];
00123   cv::Mat image_[STREAM_COUNT] = {};
00124   image_transport::CameraPublisher camera_publisher_[STREAM_COUNT] = {};
00125   sensor_msgs::CameraInfoPtr camera_info_ptr_[STREAM_COUNT] = {};
00126   std::string base_frame_id_;
00127   float max_z_ = -1.0f;
00128   bool enable_pointcloud_;
00129   bool enable_tf_;
00130   bool enable_tf_dynamic_;
00131   double tf_publication_rate_;
00132   const uint16_t *image_depth16_;
00133   cv::Mat cvWrapper_;
00134   std::mutex frame_mutex_[STREAM_COUNT];
00135 
00136   boost::shared_ptr<boost::thread> transform_thread_;
00137   ros::Time transform_ts_;
00138   tf2_ros::StaticTransformBroadcaster static_tf_broadcaster_;
00139   tf::TransformBroadcaster dynamic_tf_broadcaster_;
00140   rs_extrinsics color2depth_extrinsic_;  // color frame is base frame
00141   rs_extrinsics color2ir_extrinsic_;     // color frame is base frame
00142   rs_source rs_source_ = RS_SOURCE_VIDEO;
00143   bool start_camera_ = true;
00144   bool start_stop_srv_called_ = false;
00145 
00146   struct CameraOptions
00147   {
00148     rs_option opt;
00149     double min, max, step, value;
00150   };
00151   std::vector<CameraOptions> camera_options_;
00152 
00153   std::queue<pid_t> system_proc_groups_;
00154 
00155   // Member Functions.
00156   virtual void getParameters();
00157   virtual bool connectToCamera();
00158   virtual std::vector<int> listCameras(int num_of_camera);
00159   virtual void advertiseTopics();
00160   virtual void advertiseServices();
00161   virtual std::vector<std::string> setDynamicReconfServer() { return {}; }  // must be defined in derived class
00162   virtual void startDynamicReconfCallback() { return; }  // must be defined in derived class
00163   virtual void getCameraOptions();
00164   virtual void setStaticCameraOptions(std::vector<std::string> dynamic_params);
00165   virtual void setStreams();
00166   virtual void enableStream(rs_stream stream_index, int width, int height, rs_format format, int fps);
00167   virtual void getStreamCalibData(rs_stream stream_index);
00168   virtual void disableStream(rs_stream stream_index);
00169   virtual std::string startCamera();
00170   virtual std::string stopCamera();
00171   virtual ros::Time getTimestamp(rs_stream stream_index, double frame_ts);
00172   virtual void publishTopic(rs_stream stream_index, rs::frame &  frame);
00173   virtual void setImageData(rs_stream stream_index, rs::frame &  frame);
00174   virtual void publishPCTopic();
00175   virtual void getCameraExtrinsics();
00176   virtual void publishStaticTransforms();
00177   virtual void publishDynamicTransforms();
00178   virtual void prepareTransforms();
00179   virtual void checkError();
00180   virtual bool checkForSubscriber();
00181   virtual void wrappedSystem(const std::vector<std::string>& string_argv);
00182   virtual void setFrameCallbacks();
00183   virtual std::string checkFirmwareValidation(const std::string& fw_type,
00184                                               const std::string& current_fw,
00185                                               const std::string& camera_name,
00186                                               const std::string& camera_serial_number);
00187   std::function<void(rs::frame f)> depth_frame_handler_, color_frame_handler_, ir_frame_handler_;
00188 };
00189 }  // namespace realsense_camera
00190 #endif  // REALSENSE_CAMERA_BASE_NODELET_H


realsense_camera
Author(s): Rajvi Jingar , Reagan Lopez , Matt Hansen , Mark Horn
autogenerated on Thu Jun 6 2019 21:15:58