gazebo_ros_image_sonar.hh
Go to the documentation of this file.
1 /*
2  * This file was modified from the original version within Gazebo:
3  *
4  * Copyright (C) 2014 Open Source Robotics Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Modifications:
19  *
20  * Copyright 2018 Nils Bore (nbore@kth.se)
21  *
22  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
23  *
24  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
25  *
26  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
27  *
28  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GAZEBO_ROS_DEPTH_CAMERA_HH
35 #define GAZEBO_ROS_DEPTH_CAMERA_HH
36 
37 // ros stuff
38 #include <ros/ros.h>
39 #include <ros/callback_queue.h>
40 #include <ros/advertise_options.h>
41 
42 // ros messages stuff
43 #include <sensor_msgs/PointCloud2.h>
44 #include <sensor_msgs/Image.h>
45 #include <sensor_msgs/CameraInfo.h>
46 #include <sensor_msgs/fill_image.h>
47 #include <std_msgs/Float64.h>
49 
50 // gazebo stuff
51 #include <sdf/Param.hh>
52 #include <gazebo/physics/physics.hh>
53 #include <gazebo/transport/TransportTypes.hh>
54 #include <gazebo/msgs/MessageTypes.hh>
55 #include <gazebo/common/Time.hh>
56 #include <gazebo/sensors/SensorTypes.hh>
57 #include <gazebo/plugins/DepthCameraPlugin.hh>
58 
59 // dynamic reconfigure stuff
60 #include <gazebo_plugins/GazeboRosCameraConfig.h>
61 #include <dynamic_reconfigure/server.h>
62 
63 // boost stuff
64 #include <boost/thread/mutex.hpp>
65 
66 // camera stuff
68 
69 #include <opencv2/core.hpp>
70 
71 namespace gazebo
72 {
73  class GazeboRosImageSonar : public SensorPlugin, GazeboRosCameraUtils
74  {
77  public: GazeboRosImageSonar();
78 
80  public: ~GazeboRosImageSonar();
81 
84  public: virtual void Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf);
85 
87  public: virtual void Advertise();
88 
90  protected: virtual void OnNewDepthFrame(const float *_image,
91  unsigned int _width, unsigned int _height,
92  unsigned int _depth, const std::string &_format);
93 
95  protected: virtual void OnNewRGBPointCloud(const float *_pcd,
96  unsigned int _width, unsigned int _height,
97  unsigned int _depth, const std::string &_format);
98 
100  protected: virtual void OnNewImageFrame(const unsigned char *_image,
101  unsigned int _width, unsigned int _height,
102  unsigned int _depth, const std::string &_format);
103 
105  private: void FillPointdCloud(const float *_src);
106 
108  private: void FillDepthImage(const float *_src);
109 
111  private: void ComputeSonarImage(const float *_src);
112  private: cv::Mat ComputeNormalImage(cv::Mat& depth);
113  private: cv::Mat ConstructSonarImage(cv::Mat& depth, cv::Mat& normals);
114  private: cv::Mat ConstructScanImage(cv::Mat& depth, cv::Mat& SNR);
115  private: void ApplySpeckleNoise(cv::Mat& scan, float fov);
116  private: void ApplySmoothing(cv::Mat& scan, float fov);
117  private: void ApplyMedianFilter(cv::Mat& scan);
118  private: cv::Mat ConstructVisualScanImage(cv::Mat& raw_scan);
119 
122  private: void PointCloudConnect();
123  private: void PointCloudDisconnect();
124 
127  private: void DepthImageConnect();
128  private: void DepthImageDisconnect();
129  private: void NormalImageConnect();
130  private: void NormalImageDisconnect();
131  private: void MultibeamImageConnect();
132  private: void MultibeamImageDisconnect();
133  private: void SonarImageConnect();
134  private: void SonarImageDisconnect();
135  private: void RawSonarImageConnect();
136  private: void RawSonarImageDisconnect();
138 
139  private: bool FillPointCloudHelper(sensor_msgs::PointCloud2 &point_cloud_msg,
140  uint32_t rows_arg, uint32_t cols_arg,
141  uint32_t step_arg, void* data_arg);
142 
143  private: bool FillDepthImageHelper( sensor_msgs::Image& image_msg,
144  uint32_t rows_arg, uint32_t cols_arg,
145  uint32_t step_arg, void* data_arg);
146 
154 
156  private: sensor_msgs::PointCloud2 point_cloud_msg_;
157  private: sensor_msgs::Image depth_image_msg_;
158  private: sensor_msgs::Image normal_image_msg_;
159  private: sensor_msgs::Image multibeam_image_msg_;
160  private: sensor_msgs::Image sonar_image_msg_;
161  private: sensor_msgs::Image raw_sonar_image_msg_;
162 
163  private: double point_cloud_cutoff_;
164 
166  private: std::string point_cloud_topic_name_;
167  std::default_random_engine generator;
168 
169  private: void InfoConnect();
170  private: void InfoDisconnect();
171 
173  protected: virtual void PublishCameraInfo();
174 
176  private: std::string depth_image_topic_name_;
179  private: void DepthInfoConnect();
180  private: void DepthInfoDisconnect();
181 
182  // overload with our own
183  private: common::Time depth_sensor_update_time_;
185 
186  private: event::ConnectionPtr load_connection_;
187 
188  // from DepthCameraPlugin
189  protected: unsigned int width, height, depth;
190  protected: std::string format;
191 
192  // precomputed things for the forward-looking sonar
193  protected: cv::Mat dist_matrix_;
194  std::vector<std::vector<int> > angle_range_indices_;
195  std::vector<int> angle_nbr_indices_;
196 
197  protected: sensors::DepthCameraSensorPtr parentSensor;
198  protected: rendering::DepthCameraPtr depthCamera;
199 
200  private: event::ConnectionPtr newDepthFrameConnection;
201  private: event::ConnectionPtr newRGBPointCloudConnection;
202  private: event::ConnectionPtr newImageFrameConnection;
203  };
204 
205 }
206 #endif
cv::Mat ConstructSonarImage(cv::Mat &depth, cv::Mat &normals)
virtual void OnNewImageFrame(const unsigned char *_image, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format)
Update the controller.
std::string depth_image_topic_name_
image where each pixel contains the depth information
event::ConnectionPtr newRGBPointCloudConnection
bool FillDepthImageHelper(sensor_msgs::Image &image_msg, uint32_t rows_arg, uint32_t cols_arg, uint32_t step_arg, void *data_arg)
void ComputeSonarImage(const float *_src)
push depth image data into ros topic
virtual void OnNewRGBPointCloud(const float *_pcd, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format)
Update the controller.
void ApplySpeckleNoise(cv::Mat &scan, float fov)
void ApplySmoothing(cv::Mat &scan, float fov)
common::Time last_depth_image_camera_info_update_time_
cv::Mat ComputeNormalImage(cv::Mat &depth)
cv::Mat ConstructVisualScanImage(cv::Mat &raw_scan)
rendering::DepthCameraPtr depthCamera
ros::Publisher point_cloud_pub_
A pointer to the ROS node. A node will be instantiated if it does not exist.
void FillDepthImage(const float *_src)
push depth image data into ros topic
std::string point_cloud_topic_name_
ROS image topic name.
virtual void OnNewDepthFrame(const float *_image, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format)
Update the controller.
virtual void Advertise()
Advertise point cloud and depth image.
sensors::DepthCameraSensorPtr parentSensor
virtual void Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf)
Load the plugin.
std::default_random_engine generator
bool FillPointCloudHelper(sensor_msgs::PointCloud2 &point_cloud_msg, uint32_t rows_arg, uint32_t cols_arg, uint32_t step_arg, void *data_arg)
sensor_msgs::PointCloud2 point_cloud_msg_
PointCloud2 point cloud message.
cv::Mat ConstructScanImage(cv::Mat &depth, cv::Mat &SNR)
event::ConnectionPtr newDepthFrameConnection
event::ConnectionPtr newImageFrameConnection
int depth_image_connect_count_
Keep track of number of connctions for point clouds.
void FillPointdCloud(const float *_src)
Put camera data to the ROS topic.
std::vector< std::vector< int > > angle_range_indices_
int point_cloud_connect_count_
Keep track of number of connctions for point clouds.


uuv_sensor_ros_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Thu Jun 18 2020 03:28:33