nerian_stereo_node_base.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2021 Nerian Vision GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef __NERIAN_STEREO_NODE_H__
16 #define __NERIAN_STEREO_NODE_H__
17 
18 #include <iostream>
19 #include <iomanip>
20 #include <boost/smart_ptr.hpp>
21 
22 #include <visiontransfer/asynctransfer.h>
23 #include <visiontransfer/reconstruct3d.h>
24 #include <visiontransfer/deviceparameters.h>
25 #include <visiontransfer/exceptions.h>
26 #include <visiontransfer/datachannelservice.h>
27 
28 #include <ros/ros.h>
29 #include <sensor_msgs/PointCloud2.h>
30 #include <sensor_msgs/Image.h>
31 #include <dynamic_reconfigure/server.h>
35 #include <geometry_msgs/TransformStamped.h>
36 
37 #include <cv_bridge/cv_bridge.h>
38 #include <opencv2/opencv.hpp>
39 
40 #include <colorcoder.h>
41 
42 #include <nerian_stereo/NerianStereoConfig.h>
43 #include <nerian_stereo/StereoCameraInfo.h>
44 #include <visiontransfer/deviceparameters.h>
45 #include <visiontransfer/exceptions.h>
46 
47 using namespace std;
48 using namespace visiontransfer;
49 
70 namespace nerian_stereo {
71 
73 public:
74  StereoNodeBase(): initialConfigReceived(false), frameNum(0) {
75  }
76 
78  }
79 
83  void init();
84 
85  /*
86  * \brief Initialize and publish configuration with a dynamic_reconfigure server
87  */
88  void initDynamicReconfigure();
89 
90  /*
91  * \brief Initialize the data channel service (for receiving e.g. internal IMU data)
92  */
93  void initDataChannelService();
94 
98  void prepareAsyncTransfer();
99 
100  /*
101  * \brief Collect and process a single image set (or return after timeout if none are available)
102  */
103  void processOneImageSet();
104 
105  /*
106  * \brief Queries the the supplemental data channels (IMU ...) for new data and updates ROS accordingly
107  */
108  void processDataChannels();
109 
110  /*
111  * \brief Publishes an update for the ROS transform
112  */
113  void publishTransform();
114 
115 private:
120  NONE
121  };
122 
123  virtual ros::NodeHandle& getNH() = 0;
124  virtual ros::NodeHandle& getPrivateNH() = 0;
125 
126  //
127  boost::scoped_ptr<ros::Publisher> cloudPublisher;
128  boost::scoped_ptr<ros::Publisher> disparityPublisher;
129  boost::scoped_ptr<ros::Publisher> leftImagePublisher;
130  boost::scoped_ptr<ros::Publisher> rightImagePublisher;
131  boost::scoped_ptr<ros::Publisher> cameraInfoPublisher;
132 
133  boost::scoped_ptr<tf2_ros::TransformBroadcaster> transformBroadcaster;
134 
135  // ROS dynamic_reconfigure
136  boost::scoped_ptr<dynamic_reconfigure::Server<nerian_stereo::NerianStereoConfig>> dynReconfServer;
137  nerian_stereo::NerianStereoConfig lastKnownConfig;
139 
140  // Connection to parameter server on device
141  boost::scoped_ptr<DeviceParameters> deviceParameters;
142 
143  // Parameters
144  bool useTcp;
145  std::string colorCodeDispMap;
149  std::string remotePort;
150  std::string frame; // outer frame (e.g. world)
151  std::string internalFrame; // our private frame / Transform we publish
152  std::string remoteHost;
153  std::string calibFile;
154  double execDelay;
155  double maxDepth;
158 
159  // Other members
160  int frameNum;
161  boost::scoped_ptr<Reconstruct3D> recon3d;
162  boost::scoped_ptr<ColorCoder> colCoder;
163  cv::Mat_<cv::Vec3b> colDispMap;
164  sensor_msgs::PointCloud2Ptr pointCloudMsg;
165  cv::FileStorage calibStorage;
166  nerian_stereo::StereoCameraInfoPtr camInfoMsg;
168 
169  boost::scoped_ptr<AsyncTransfer> asyncTransfer;
171  int lastLogFrames = 0;
172 
173  // DataChannelService connection, to obtain IMU data
174  boost::scoped_ptr<DataChannelService> dataChannelService;
175  // Our transform, updated with polled IMU data (if available)
176  geometry_msgs::TransformStamped currentTransform;
177 
181  void loadCameraCalibration();
182 
187  void publishImageMsg(const ImageSet& imageSet, int imageIndex, ros::Time stamp, bool allowColorCode,
188  ros::Publisher* publisher);
189 
194  void qMatrixToRosCoords(const float* src, float* dst);
195 
200  void publishPointCloudMsg(ImageSet& imageSet, ros::Time stamp);
201 
205  template <PointCloudColorMode colorMode> void copyPointCloudIntensity(ImageSet& imageSet);
206 
211  template <int coord> void copyPointCloudClamped(float* src, float* dst, int size);
212 
217  void initPointCloud();
218 
222  void publishCameraInfo(ros::Time stamp, const ImageSet& imageSet);
223 
227  template<class T> void readCalibrationArray(const char* key, T& dest);
228 
229  /*
230  * \brief Callback that receives an updated configuration from ROS; internally uses autogen_dynamicReconfigureCallback
231  */
232  void dynamicReconfigureCallback(nerian_stereo::NerianStereoConfig &config, uint32_t level);
233 
234  /*
235  * \brief Forward parameters from the device as initial values to the ROS parameter server; internally uses autogen_updateParameterServerFromDevice
236  */
237  void updateParameterServerFromDevice(std::map<std::string, ParameterInfo>& cfg);
238 
239  /*
240  * \brief Uses parameters from the device as a run-time override for limits and defaults in the dynamic_reconfigure node; internally uses autogen_updateDynamicReconfigureFromDevice
241  */
242  void updateDynamicReconfigureFromDevice(std::map<std::string, ParameterInfo>& cfg);
243 
244 
245  // The following three implementations are autogenerated by generate_nerian_config_cpp.py
246  // by parsing cfg/NerianStereo.cfg (which is also used by dynamic_reconfigure)
250  void autogen_dynamicReconfigureCallback(nerian_stereo::NerianStereoConfig &config, uint32_t level);
254  void autogen_updateParameterServerFromDevice(std::map<std::string, ParameterInfo>& cfg);
258  void autogen_updateDynamicReconfigureFromDevice(std::map<std::string, ParameterInfo>& cfg);
259 
260 };
261 
262 } // namespace
263 
264 #endif
265 
sensor_msgs::PointCloud2Ptr pointCloudMsg
boost::scoped_ptr< dynamic_reconfigure::Server< nerian_stereo::NerianStereoConfig > > dynReconfServer
boost::scoped_ptr< ColorCoder > colCoder
boost::scoped_ptr< DataChannelService > dataChannelService
nerian_stereo::StereoCameraInfoPtr camInfoMsg
boost::scoped_ptr< ros::Publisher > rightImagePublisher
geometry_msgs::TransformStamped currentTransform
boost::scoped_ptr< Reconstruct3D > recon3d
boost::scoped_ptr< ros::Publisher > cloudPublisher
boost::scoped_ptr< ros::Publisher > disparityPublisher
boost::scoped_ptr< tf2_ros::TransformBroadcaster > transformBroadcaster
A driver node that receives data from Nerian stereo devices and forwards it to ROS.
boost::scoped_ptr< ros::Publisher > leftImagePublisher
boost::scoped_ptr< DeviceParameters > deviceParameters
boost::scoped_ptr< ros::Publisher > cameraInfoPublisher
nerian_stereo::NerianStereoConfig lastKnownConfig
boost::scoped_ptr< AsyncTransfer > asyncTransfer


nerian_stereo
Author(s): Nerian Vision Technologies
autogenerated on Fri Apr 16 2021 02:11:19