base_nodelet.h
Go to the documentation of this file.
1 /******************************************************************************
2  Copyright (c) 2017, Intel Corporation
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  3. Neither the name of the copyright holder nor the names of its contributors
16  may be used to endorse or promote products derived from this software without
17  specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *******************************************************************************/
30 
31 #pragma once
32 #ifndef REALSENSE_CAMERA_BASE_NODELET_H
33 #define REALSENSE_CAMERA_BASE_NODELET_H
34 
35 #include <iostream>
36 #include <boost/thread.hpp>
37 #include <boost/algorithm/string/join.hpp>
38 #include <thread> // NOLINT(build/c++11)
39 #include <cstdlib>
40 #include <cctype>
41 #include <algorithm>
42 #include <sstream>
43 #include <memory>
44 #include <map>
45 #include <queue>
46 #include <unistd.h>
47 #include <signal.h>
48 #include <string>
49 #include <vector>
50 
51 #include <opencv2/core/core.hpp>
52 #include <cv_bridge/cv_bridge.h>
53 #include <opencv2/highgui/highgui.hpp>
54 
55 #include <ros/ros.h>
56 #include <nodelet/nodelet.h>
57 #include <sensor_msgs/PointCloud2.h>
60 #include <std_msgs/String.h>
61 #include <std_msgs/Float32MultiArray.h>
64 #include <librealsense/rs.hpp>
68 
69 #include <realsense_camera/CameraConfiguration.h>
70 #include <realsense_camera/IsPowered.h>
71 #include <realsense_camera/SetPower.h>
72 #include <realsense_camera/ForcePower.h>
74 
76 {
78 {
79 public:
80  // Interfaces.
81  virtual void onInit();
82  virtual ~BaseNodelet();
83  virtual void setDepthEnable(bool &enable_depth);
84  virtual bool getCameraOptionValues(realsense_camera::CameraConfiguration::Request & req,
85  realsense_camera::CameraConfiguration::Response & res);
86  virtual bool setPowerCameraService(realsense_camera::SetPower::Request & req,
87  realsense_camera::SetPower::Response & res);
88  virtual bool forcePowerCameraService(realsense_camera::ForcePower::Request & req,
89  realsense_camera::ForcePower::Response & res);
90  virtual bool isPoweredCameraService(realsense_camera::IsPowered::Request & req,
91  realsense_camera::IsPowered::Response & res);
92 
93 protected:
94  // Member Variables.
106  std::string nodelet_name_;
107  std::string serial_no_;
108  std::string usb_port_id_;
109  std::string camera_type_;
110  std::string mode_;
111  bool enable_[STREAM_COUNT] = {false};
116  std::string encoding_[STREAM_COUNT];
120  double ts_[STREAM_COUNT];
121  std::string frame_id_[STREAM_COUNT];
123  cv::Mat image_[STREAM_COUNT] = {};
125  sensor_msgs::CameraInfoPtr camera_info_ptr_[STREAM_COUNT] = {};
126  std::string base_frame_id_;
127  float max_z_ = -1.0f;
132  const uint16_t *image_depth16_;
133  cv::Mat cvWrapper_;
135 
140  rs_extrinsics color2depth_extrinsic_; // color frame is base frame
141  rs_extrinsics color2ir_extrinsic_; // color frame is base frame
143  bool start_camera_ = true;
145 
147  {
149  double min, max, step, value;
150  };
151  std::vector<CameraOptions> camera_options_;
152 
153  std::queue<pid_t> system_proc_groups_;
154 
155  // Member Functions.
156  virtual void getParameters();
157  virtual bool connectToCamera();
158  virtual std::vector<int> listCameras(int num_of_camera);
159  virtual void advertiseTopics();
160  virtual void advertiseServices();
161  virtual std::vector<std::string> setDynamicReconfServer() { return {}; } // must be defined in derived class
162  virtual void startDynamicReconfCallback() { return; } // must be defined in derived class
163  virtual void getCameraOptions();
164  virtual void setStaticCameraOptions(std::vector<std::string> dynamic_params);
165  virtual void setStreams();
166  virtual void enableStream(rs_stream stream_index, int width, int height, rs_format format, int fps);
167  virtual void getStreamCalibData(rs_stream stream_index);
168  virtual void disableStream(rs_stream stream_index);
169  virtual std::string startCamera();
170  virtual std::string stopCamera();
171  virtual ros::Time getTimestamp(rs_stream stream_index, double frame_ts);
172  virtual void publishTopic(rs_stream stream_index, rs::frame & frame);
173  virtual void setImageData(rs_stream stream_index, rs::frame & frame);
174  virtual void publishPCTopic();
175  virtual void getCameraExtrinsics();
176  virtual void publishStaticTransforms();
177  virtual void publishDynamicTransforms();
178  virtual void prepareTransforms();
179  virtual void checkError();
180  virtual bool checkForSubscriber();
181  virtual void wrappedSystem(const std::vector<std::string>& string_argv);
182  virtual void setFrameCallbacks();
183  virtual std::string checkFirmwareValidation(const std::string& fw_type,
184  const std::string& current_fw,
185  const std::string& camera_name,
186  const std::string& camera_serial_number);
187  std::function<void(rs::frame f)> depth_frame_handler_, color_frame_handler_, ir_frame_handler_;
188 };
189 } // namespace realsense_camera
190 #endif // REALSENSE_CAMERA_BASE_NODELET_H
boost::shared_ptr< boost::thread > transform_thread_
Definition: base_nodelet.h:136
RS_SOURCE_VIDEO
std::string optical_frame_id_[STREAM_COUNT]
Definition: base_nodelet.h:122
tf::TransformBroadcaster dynamic_tf_broadcaster_
Definition: base_nodelet.h:139
virtual std::string stopCamera()
const uint16_t * image_depth16_
Definition: base_nodelet.h:132
virtual void setDepthEnable(bool &enable_depth)
GLint GLint GLsizei GLsizei height
virtual std::string checkFirmwareValidation(const std::string &fw_type, const std::string &current_fw, const std::string &camera_name, const std::string &camera_serial_number)
std::function< void(rs::frame f)> ir_frame_handler_
Definition: base_nodelet.h:187
ros::Publisher pointcloud_publisher_
Definition: base_nodelet.h:98
double ts_[STREAM_COUNT]
Definition: base_nodelet.h:120
virtual std::string startCamera()
virtual void publishTopic(rs_stream stream_index, rs::frame &frame)
virtual void publishStaticTransforms()
std::string encoding_[STREAM_COUNT]
Definition: base_nodelet.h:116
virtual std::vector< std::string > setDynamicReconfServer()
Definition: base_nodelet.h:161
int cv_type_[STREAM_COUNT]
Definition: base_nodelet.h:117
rs_option
virtual bool setPowerCameraService(realsense_camera::SetPower::Request &req, realsense_camera::SetPower::Response &res)
virtual void setStaticCameraOptions(std::vector< std::string > dynamic_params)
virtual void disableStream(rs_stream stream_index)
tf2_ros::StaticTransformBroadcaster static_tf_broadcaster_
Definition: base_nodelet.h:138
bool enable_[STREAM_COUNT]
Definition: base_nodelet.h:111
std::queue< pid_t > system_proc_groups_
Definition: base_nodelet.h:153
virtual void enableStream(rs_stream stream_index, int width, int height, rs_format format, int fps)
sensor_msgs::CameraInfoPtr camera_info_ptr_[STREAM_COUNT]
Definition: base_nodelet.h:125
virtual void publishDynamicTransforms()
format
virtual void startDynamicReconfCallback()
Definition: base_nodelet.h:162
std::mutex frame_mutex_[STREAM_COUNT]
Definition: base_nodelet.h:134
virtual void setImageData(rs_stream stream_index, rs::frame &frame)
virtual std::vector< int > listCameras(int num_of_camera)
virtual ros::Time getTimestamp(rs_stream stream_index, double frame_ts)
rs_format
std::string frame_id_[STREAM_COUNT]
Definition: base_nodelet.h:121
rs_format format_[STREAM_COUNT]
Definition: base_nodelet.h:115
ros::ServiceServer is_powered_service_
Definition: base_nodelet.h:102
rs_extrinsics color2depth_extrinsic_
Definition: base_nodelet.h:140
cv::Mat image_[STREAM_COUNT]
Definition: base_nodelet.h:123
virtual bool forcePowerCameraService(realsense_camera::ForcePower::Request &req, realsense_camera::ForcePower::Response &res)
virtual void wrappedSystem(const std::vector< std::string > &string_argv)
rs_source
virtual bool getCameraOptionValues(realsense_camera::CameraConfiguration::Request &req, realsense_camera::CameraConfiguration::Response &res)
const int STREAM_COUNT
Definition: constants.h:43
image_transport::CameraPublisher camera_publisher_[STREAM_COUNT]
Definition: base_nodelet.h:124
virtual bool isPoweredCameraService(realsense_camera::IsPowered::Request &req, realsense_camera::IsPowered::Response &res)
std::function< void(rs::frame f)> depth_frame_handler_
Definition: base_nodelet.h:187
int unit_step_size_[STREAM_COUNT]
Definition: base_nodelet.h:118
rs_stream
GLint GLint GLsizei width
ros::ServiceServer force_power_service_
Definition: base_nodelet.h:101
virtual void getStreamCalibData(rs_stream stream_index)
GLuint res
std::vector< CameraOptions > camera_options_
Definition: base_nodelet.h:151
ros::ServiceServer get_options_service_
Definition: base_nodelet.h:99
ros::ServiceServer set_power_service_
Definition: base_nodelet.h:100
std::function< void(rs::frame f)> color_frame_handler_
Definition: base_nodelet.h:187


realsense_camera
Author(s): Rajvi Jingar , Reagan Lopez , Matt Hansen , Mark Horn
autogenerated on Mon Jun 10 2019 14:40:37