sr300_nodelet.cpp
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 #include <string>
32 #include <vector>
34 
36 
37 namespace realsense_camera
38 {
39  /*
40  * Initialize the nodelet.
41  */
42  void SR300Nodelet::onInit()
43  {
46  cv_type_[RS_STREAM_COLOR] = CV_8UC3;
47  unit_step_size_[RS_STREAM_COLOR] = sizeof(unsigned char) * 3;
48 
49  format_[RS_STREAM_DEPTH] = RS_FORMAT_Z16;
51  cv_type_[RS_STREAM_DEPTH] = CV_16UC1;
52  unit_step_size_[RS_STREAM_DEPTH] = sizeof(uint16_t);
53 
56  cv_type_[RS_STREAM_INFRARED] = CV_16UC1;
57  unit_step_size_[RS_STREAM_INFRARED] = sizeof(uint16_t);
58 
59  max_z_ = SR300_MAX_Z;
60 
61  SyncNodelet::onInit();
62  }
63 
64  /*
65  * Determine fastest stream -- overrides base class
66  */
67  void SR300Nodelet::setStreams()
68  {
69  // enable camera streams
70  BaseNodelet::setStreams();
71 
72  // Find the fastest updating, enabled stream
73  fastest_stream_ = RS_STREAM_DEPTH; // default to depth
74 
75  if (fps_[RS_STREAM_COLOR] > fps_[RS_STREAM_DEPTH])
76  {
77  if (enable_[RS_STREAM_COLOR])
78  {
79  fastest_stream_ = RS_STREAM_COLOR;
80  }
81  }
82  }
83 
84  /*
85  * Set Dynamic Reconfigure Server and return the dynamic params.
86  */
87  std::vector<std::string> SR300Nodelet::setDynamicReconfServer()
88  {
89  dynamic_reconf_server_.reset(new dynamic_reconfigure::Server<realsense_camera::sr300_paramsConfig>(pnh_));
90 
91  // Get dynamic options from the dynamic reconfigure server.
92  realsense_camera::sr300_paramsConfig params_config;
93  dynamic_reconf_server_->getConfigDefault(params_config);
94  std::vector<realsense_camera::sr300_paramsConfig::AbstractParamDescriptionConstPtr> param_desc =
95  params_config.__getParamDescriptions__();
96  std::vector<std::string> dynamic_params;
97  for (realsense_camera::sr300_paramsConfig::AbstractParamDescriptionConstPtr param_desc_ptr : param_desc)
98  {
99  dynamic_params.push_back((* param_desc_ptr).name);
100  }
101 
102  return dynamic_params;
103  }
104 
105  /*
106  * Start Dynamic Reconfigure Callback.
107  */
108  void SR300Nodelet::startDynamicReconfCallback()
109  {
110  dynamic_reconf_server_->setCallback(boost::bind(&SR300Nodelet::configCallback, this, _1, _2));
111  }
112 
113  /*
114  * Get the dynamic param values.
115  */
116  void SR300Nodelet::configCallback(realsense_camera::sr300_paramsConfig &config, uint32_t level)
117  {
118  ROS_INFO_STREAM(nodelet_name_ << " - Setting dynamic camera options");
119 
120  // set the depth enable
121  BaseNodelet::setDepthEnable(config.enable_depth);
122 
123  // Set common options
124  rs_set_device_option(rs_device_, RS_OPTION_COLOR_BACKLIGHT_COMPENSATION, config.color_backlight_compensation, 0);
125  rs_set_device_option(rs_device_, RS_OPTION_COLOR_BRIGHTNESS, config.color_brightness, 0);
126  rs_set_device_option(rs_device_, RS_OPTION_COLOR_CONTRAST, config.color_contrast, 0);
127  rs_set_device_option(rs_device_, RS_OPTION_COLOR_GAIN, config.color_gain, 0);
128  rs_set_device_option(rs_device_, RS_OPTION_COLOR_GAMMA, config.color_gamma, 0);
129  rs_set_device_option(rs_device_, RS_OPTION_COLOR_HUE, config.color_hue, 0);
130  rs_set_device_option(rs_device_, RS_OPTION_COLOR_SATURATION, config.color_saturation, 0);
131  rs_set_device_option(rs_device_, RS_OPTION_COLOR_SHARPNESS, config.color_sharpness, 0);
133  config.color_enable_auto_exposure, 0);
134  if (config.color_enable_auto_exposure == 0)
135  {
136  rs_set_device_option(rs_device_, RS_OPTION_COLOR_EXPOSURE, config.color_exposure, 0);
137  }
139  config.color_enable_auto_white_balance, 0);
140  if (config.color_enable_auto_white_balance == 0)
141  {
142  rs_set_device_option(rs_device_, RS_OPTION_COLOR_WHITE_BALANCE, config.color_white_balance, 0);
143  }
144 
145  // Set SR300 options that are common with F200
146  rs_set_device_option(rs_device_, RS_OPTION_F200_LASER_POWER, config.f200_laser_power, 0);
147  rs_set_device_option(rs_device_, RS_OPTION_F200_ACCURACY, config.f200_accuracy, 0);
148  rs_set_device_option(rs_device_, RS_OPTION_F200_MOTION_RANGE, config.f200_motion_range, 0);
149  rs_set_device_option(rs_device_, RS_OPTION_F200_FILTER_OPTION, config.f200_filter_option, 0);
150  rs_set_device_option(rs_device_, RS_OPTION_F200_CONFIDENCE_THRESHOLD, config.f200_confidence_threshold, 0);
151 
152  // Set SR300 specific options
154  config.sr300_auto_range_enable_motion_versus_range, 0);
155  if (config.sr300_auto_range_enable_motion_versus_range == 1)
156  {
158  config.sr300_auto_range_min_motion_versus_range, 0);
160  config.sr300_auto_range_max_motion_versus_range, 0);
162  config.sr300_auto_range_start_motion_versus_range, 0);
163  }
165  config.sr300_auto_range_enable_laser, 0);
166  if (config.sr300_auto_range_enable_laser == 1)
167  {
169  config.sr300_auto_range_min_laser, 0);
171  config.sr300_auto_range_max_laser, 0);
173  config.sr300_auto_range_start_laser, 0);
174  }
176  config.sr300_auto_range_upper_threshold, 0);
178  config.sr300_auto_range_lower_threshold, 0);
179 /*
180  rs_set_device_option(rs_device_, RS_OPTION_SR300_WAKEUP_DEV_PHASE1_PERIOD, config.sr300_wakeup_dev_phase1_period, 0);
181  rs_set_device_option(rs_device_, RS_OPTION_SR300_WAKEUP_DEV_PHASE1_FPS, config.sr300_wakeup_dev_phase1_fps, 0);
182  rs_set_device_option(rs_device_, RS_OPTION_SR300_WAKEUP_DEV_PHASE2_PERIOD, config.sr300_wakeup_dev_phase2_period, 0);
183  rs_set_device_option(rs_device_, RS_OPTION_SR300_WAKEUP_DEV_PHASE2_FPS, config.sr300_wakeup_dev_phase2_fps, 0);
184  rs_set_device_option(rs_device_, RS_OPTION_SR300_WAKEUP_DEV_RESET, config.sr300_wakeup_dev_reset, 0);
185  rs_set_device_option(rs_device_, RS_OPTION_SR300_WAKE_ON_USB_REASON, config.sr300_wake_on_usb_reason, 0);
186  rs_set_device_option(rs_device_, RS_OPTION_SR300_WAKE_ON_USB_CONFIDENCE, config.sr300_wake_on_usb_confidence, 0);
187 */
188  }
189 } // namespace realsense_camera
RS_OPTION_COLOR_ENABLE_AUTO_EXPOSURE
void rs_set_device_option(rs_device *device, rs_option option, double value, rs_error **error)
RS_OPTION_SR300_AUTO_RANGE_START_LASER
RS_OPTION_COLOR_BACKLIGHT_COMPENSATION
RS_OPTION_SR300_AUTO_RANGE_MIN_LASER
RS_OPTION_F200_MOTION_RANGE
RS_OPTION_COLOR_ENABLE_AUTO_WHITE_BALANCE
RS_OPTION_SR300_AUTO_RANGE_MAX_LASER
const float SR300_MAX_Z
Definition: constants.h:108
RS_OPTION_SR300_AUTO_RANGE_LOWER_THRESHOLD
PLUGINLIB_EXPORT_CLASS(depth_image_proc::ConvertMetricNodelet, nodelet::Nodelet)
RS_OPTION_COLOR_HUE
RS_OPTION_COLOR_GAIN
RS_FORMAT_Z16
RS_OPTION_COLOR_CONTRAST
RS_OPTION_COLOR_WHITE_BALANCE
RS_OPTION_COLOR_EXPOSURE
GLint level
RS_OPTION_F200_CONFIDENCE_THRESHOLD
RS_OPTION_COLOR_SHARPNESS
RS_OPTION_SR300_AUTO_RANGE_MAX_MOTION_VERSUS_RANGE
const std::string TYPE_16UC1
RS_OPTION_SR300_AUTO_RANGE_ENABLE_LASER
RS_OPTION_SR300_AUTO_RANGE_START_MOTION_VERSUS_RANGE
RS_OPTION_SR300_AUTO_RANGE_UPPER_THRESHOLD
#define ROS_INFO_STREAM(args)
RS_OPTION_COLOR_SATURATION
RS_OPTION_F200_FILTER_OPTION
RS_FORMAT_RGB8
RS_OPTION_SR300_AUTO_RANGE_MIN_MOTION_VERSUS_RANGE
RS_OPTION_F200_LASER_POWER
RS_STREAM_DEPTH
RS_FORMAT_Y16
RS_STREAM_INFRARED
RS_OPTION_COLOR_BRIGHTNESS
RS_OPTION_COLOR_GAMMA
RS_STREAM_COLOR
RS_OPTION_SR300_AUTO_RANGE_ENABLE_MOTION_VERSUS_RANGE
RS_OPTION_F200_ACCURACY


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