gazebo_ros_depth_camera.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /*
18  * Desc: A dynamic controller plugin that publishes ROS image_raw camera_info topic for generic camera sensor.
19  * Author: John Hsu
20  * Date: 24 Sept 2008
21  */
22 
23 #ifndef GAZEBO_ROS_DEPTH_CAMERA_HH
24 #define GAZEBO_ROS_DEPTH_CAMERA_HH
25 
26 // ros stuff
27 #include <ros/ros.h>
28 #include <ros/callback_queue.h>
29 #include <ros/advertise_options.h>
30 
31 // ros messages stuff
32 #include <sensor_msgs/PointCloud2.h>
33 #include <sensor_msgs/Image.h>
34 #include <sensor_msgs/CameraInfo.h>
35 #include <sensor_msgs/fill_image.h>
36 #include <std_msgs/Float64.h>
38 #include <visualization_msgs/MarkerArray.h>
39 #include <visualization_msgs/Marker.h>
40 
41 // gazebo stuff
42 #include <sdf/Param.hh>
43 #include <gazebo/physics/physics.hh>
44 #include <gazebo/transport/TransportTypes.hh>
45 #include <gazebo/msgs/MessageTypes.hh>
46 #include <gazebo/common/Time.hh>
47 #include <gazebo/sensors/SensorTypes.hh>
48 #include <gazebo/plugins/DepthCameraPlugin.hh>
49 
50 // dynamic reconfigure stuff
51 #include <gazebo_plugins/GazeboRosCameraConfig.h>
52 #include <dynamic_reconfigure/server.h>
53 
54 // boost stuff
55 #include <boost/thread/mutex.hpp>
56 
57 // camera stuff
59 
60 namespace gazebo
61 {
62  class GazeboRosDepthCamera : public DepthCameraPlugin, GazeboRosCameraUtils
63  {
66  public: GazeboRosDepthCamera();
67 
69  public: ~GazeboRosDepthCamera();
70 
73  public: virtual void Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf) override;
74 
76  public: virtual void Advertise();
77 
79  protected: virtual void OnNewDepthFrame(const float *_image,
80  unsigned int _width, unsigned int _height,
81  unsigned int _depth, const std::string &_format) override;
82 
84  protected: virtual void OnNewRGBPointCloud(const float *_pcd,
85  unsigned int _width, unsigned int _height,
86  unsigned int _depth, const std::string &_format) override;
87 
89  protected: virtual void OnNewImageFrame(const unsigned char *_image,
90  unsigned int _width, unsigned int _height,
91  unsigned int _depth, const std::string &_format) override;
92 
93 #if GAZEBO_MAJOR_VERSION == 9 && GAZEBO_MINOR_VERSION > 12
94  protected: virtual void OnNewReflectanceFrame(const float * _reflectance,
96  unsigned int _width, unsigned int _height,
97  unsigned int _depth, const std::string &_format) override;
98 
100  protected: virtual void OnNewNormalsFrame(const float * _normals,
101  unsigned int _width, unsigned int _height,
102  unsigned int _depth, const std::string &_format) override;
103 #endif
104 
106  private: void FillPointdCloud(const float *_src);
107 
109  private: void FillDepthImage(const float *_src);
110 
113  private: void PointCloudConnect();
114  private: void PointCloudDisconnect();
115 
119  private: void ReflectanceConnect();
121  private: void ReflectanceDisconnect();
122 
126  private: void NormalsConnect();
128  private: void NormalsDisconnect();
129 
132  private: void DepthImageConnect();
133  private: void DepthImageDisconnect();
135 
136  private: bool FillPointCloudHelper(sensor_msgs::PointCloud2 &point_cloud_msg,
137  uint32_t rows_arg, uint32_t cols_arg,
138  uint32_t step_arg, void* data_arg);
139 
140  private: bool FillDepthImageHelper( sensor_msgs::Image& image_msg,
141  uint32_t rows_arg, uint32_t cols_arg,
142  uint32_t step_arg, void* data_arg);
143 
149 
151  private: sensor_msgs::PointCloud2 point_cloud_msg_;
152  private: sensor_msgs::Image depth_image_msg_;
153  private: sensor_msgs::Image reflectance_msg_;
154 
156  private: float * pcd_ = nullptr;
157 
158  private: double point_cloud_cutoff_;
159 
161  private: int reduce_normals_;
162 
164  private: std::string point_cloud_topic_name_;
165 
167  private: std::string reflectance_topic_name_;
168 
170  private: std::string normals_topic_name_;
171 
172  private: void InfoConnect();
173  private: void InfoDisconnect();
174 
176  protected: virtual void PublishCameraInfo();
177 
179  private: std::string depth_image_topic_name_;
182  private: void DepthInfoConnect();
183  private: void DepthInfoDisconnect();
185 
186  // overload with our own
187  private: common::Time depth_sensor_update_time_;
189 
190  private: event::ConnectionPtr load_connection_;
191  };
192 
193 }
194 #endif
gazebo::GazeboRosDepthCamera::PointCloudConnect
void PointCloudConnect()
Definition: gazebo_ros_depth_camera.cpp:193
gazebo::GazeboRosDepthCamera::reflectance_pub_
ros::Publisher reflectance_pub_
Definition: gazebo_ros_depth_camera.h:147
gazebo::GazeboRosDepthCamera::depth_image_camera_info_topic_name_
std::string depth_image_camera_info_topic_name_
Definition: gazebo_ros_depth_camera.h:180
gazebo::GazeboRosDepthCamera::point_cloud_topic_name_
std::string point_cloud_topic_name_
ROS image topic name.
Definition: gazebo_ros_depth_camera.h:164
gazebo::GazeboRosDepthCamera::depth_image_pub_
ros::Publisher depth_image_pub_
Definition: gazebo_ros_depth_camera.h:146
fill_image.h
ros::Publisher
gazebo::GazeboRosDepthCamera::use_depth_image_16UC1_format_
bool use_depth_image_16UC1_format_
Definition: gazebo_ros_depth_camera.h:184
gazebo
gazebo::GazeboRosDepthCamera::DepthImageConnect
void DepthImageConnect()
Definition: gazebo_ros_depth_camera.cpp:250
gazebo::GazeboRosDepthCamera::OnNewImageFrame
virtual void OnNewImageFrame(const unsigned char *_image, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format) override
Update the controller.
Definition: gazebo_ros_depth_camera.cpp:446
gazebo::GazeboRosDepthCamera::FillDepthImageHelper
bool FillDepthImageHelper(sensor_msgs::Image &image_msg, uint32_t rows_arg, uint32_t cols_arg, uint32_t step_arg, void *data_arg)
Definition: gazebo_ros_depth_camera.cpp:721
ros.h
gazebo::GazeboRosDepthCamera::DepthInfoConnect
void DepthInfoConnect()
Definition: gazebo_ros_depth_camera.cpp:265
gazebo::GazeboRosDepthCamera::~GazeboRosDepthCamera
~GazeboRosDepthCamera()
Destructor.
Definition: gazebo_ros_depth_camera.cpp:61
gazebo::GazeboRosDepthCamera::normals_topic_name_
std::string normals_topic_name_
ROS normals topic name.
Definition: gazebo_ros_depth_camera.h:170
gazebo::GazeboRosDepthCamera::PointCloudDisconnect
void PointCloudDisconnect()
Definition: gazebo_ros_depth_camera.cpp:202
gazebo::GazeboRosDepthCamera::Load
virtual void Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf) override
Load the plugin.
Definition: gazebo_ros_depth_camera.cpp:71
gazebo::GazeboRosDepthCamera::OnNewDepthFrame
virtual void OnNewDepthFrame(const float *_image, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format) override
Update the controller.
Definition: gazebo_ros_depth_camera.cpp:278
gazebo::GazeboRosDepthCamera::Advertise
virtual void Advertise()
Advertise point cloud, depth image, normals and reflectance.
Definition: gazebo_ros_depth_camera.cpp:146
gazebo::GazeboRosDepthCamera::FillDepthImage
void FillDepthImage(const float *_src)
push depth image data into ros topic
Definition: gazebo_ros_depth_camera.cpp:605
gazebo::GazeboRosDepthCamera
Definition: gazebo_ros_depth_camera.h:62
gazebo::GazeboRosDepthCamera::InfoConnect
void InfoConnect()
gazebo::GazeboRosDepthCamera::depth_image_camera_info_pub_
ros::Publisher depth_image_camera_info_pub_
Definition: gazebo_ros_depth_camera.h:188
gazebo::GazeboRosDepthCamera::depth_image_msg_
sensor_msgs::Image depth_image_msg_
Definition: gazebo_ros_depth_camera.h:152
gazebo::GazeboRosDepthCamera::depth_image_topic_name_
std::string depth_image_topic_name_
image where each pixel contains the depth information
Definition: gazebo_ros_depth_camera.h:179
gazebo::GazeboRosDepthCamera::DepthInfoDisconnect
void DepthInfoDisconnect()
Definition: gazebo_ros_depth_camera.cpp:271
gazebo::GazeboRosDepthCamera::reflectance_topic_name_
std::string reflectance_topic_name_
ROS reflectance topic name.
Definition: gazebo_ros_depth_camera.h:167
gazebo::GazeboRosDepthCamera::ReflectanceDisconnect
void ReflectanceDisconnect()
Decrease the counter which count the subscribers are connected.
Definition: gazebo_ros_depth_camera.cpp:230
gazebo::GazeboRosCameraUtils
Definition: gazebo_ros_camera_utils.h:56
gazebo::GazeboRosDepthCamera::last_depth_image_camera_info_update_time_
common::Time last_depth_image_camera_info_update_time_
Definition: gazebo_ros_depth_camera.h:134
gazebo::GazeboRosCameraUtils::PublishCameraInfo
void PublishCameraInfo()
Definition: gazebo_ros_camera_utils.cpp:674
gazebo::GazeboRosDepthCamera::GazeboRosDepthCamera
GazeboRosDepthCamera()
Constructor.
Definition: gazebo_ros_depth_camera.cpp:49
gazebo::GazeboRosDepthCamera::FillPointCloudHelper
bool FillPointCloudHelper(sensor_msgs::PointCloud2 &point_cloud_msg, uint32_t rows_arg, uint32_t cols_arg, uint32_t step_arg, void *data_arg)
Definition: gazebo_ros_depth_camera.cpp:627
gazebo_ros_camera_utils.h
gazebo::GazeboRosDepthCamera::ReflectanceConnect
void ReflectanceConnect()
Increase the counter which count the subscribers are connected.
Definition: gazebo_ros_depth_camera.cpp:212
gazebo::GazeboRosDepthCamera::NormalsConnect
void NormalsConnect()
Increase the counter which count the subscribers are connected.
Definition: gazebo_ros_depth_camera.cpp:221
gazebo::GazeboRosDepthCamera::point_cloud_cutoff_
double point_cloud_cutoff_
Definition: gazebo_ros_depth_camera.h:158
gazebo::GazeboRosDepthCamera::point_cloud_connect_count_
int point_cloud_connect_count_
Keep track of number of connctions for point clouds.
Definition: gazebo_ros_depth_camera.h:112
gazebo::GazeboRosDepthCamera::PublishCameraInfo
virtual void PublishCameraInfo()
Definition: gazebo_ros_depth_camera.cpp:781
gazebo::GazeboRosDepthCamera::reflectance_msg_
sensor_msgs::Image reflectance_msg_
Definition: gazebo_ros_depth_camera.h:153
gazebo::GazeboRosDepthCamera::FillPointdCloud
void FillPointdCloud(const float *_src)
Put camera data to the ROS topic.
Definition: gazebo_ros_depth_camera.cpp:580
gazebo::GazeboRosDepthCamera::reduce_normals_
int reduce_normals_
adding one value each reduce_normals_ to the array marker
Definition: gazebo_ros_depth_camera.h:161
gazebo::GazeboRosDepthCamera::depth_image_connect_count_
int depth_image_connect_count_
Keep track of number of connctions for point clouds.
Definition: gazebo_ros_depth_camera.h:131
image_transport.h
callback_queue.h
gazebo::GazeboRosDepthCamera::reflectance_connect_count_
int reflectance_connect_count_
Keep track of number of connections for reflectance.
Definition: gazebo_ros_depth_camera.h:117
gazebo::GazeboRosDepthCamera::InfoDisconnect
void InfoDisconnect()
gazebo::GazeboRosDepthCamera::pcd_
float * pcd_
copy of the pointcloud data, used to place normals in the world
Definition: gazebo_ros_depth_camera.h:156
gazebo::GazeboRosDepthCamera::load_connection_
event::ConnectionPtr load_connection_
Definition: gazebo_ros_depth_camera.h:190
advertise_options.h
gazebo::GazeboRosDepthCamera::normal_pub_
ros::Publisher normal_pub_
Definition: gazebo_ros_depth_camera.h:148
gazebo::GazeboRosDepthCamera::depth_info_connect_count_
int depth_info_connect_count_
Definition: gazebo_ros_depth_camera.h:181
gazebo::GazeboRosDepthCamera::DepthImageDisconnect
void DepthImageDisconnect()
Definition: gazebo_ros_depth_camera.cpp:258
gazebo::GazeboRosDepthCamera::depth_sensor_update_time_
common::Time depth_sensor_update_time_
Definition: gazebo_ros_depth_camera.h:187
gazebo::GazeboRosDepthCamera::OnNewRGBPointCloud
virtual void OnNewRGBPointCloud(const float *_pcd, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format) override
Update the controller.
Definition: gazebo_ros_depth_camera.cpp:331
gazebo::GazeboRosDepthCamera::NormalsDisconnect
void NormalsDisconnect()
Decrease the counter which count the subscribers are connected.
Definition: gazebo_ros_depth_camera.cpp:240
gazebo::GazeboRosDepthCamera::point_cloud_pub_
ros::Publisher point_cloud_pub_
A pointer to the ROS node. A node will be instantiated if it does not exist.
Definition: gazebo_ros_depth_camera.h:145
gazebo::GazeboRosDepthCamera::normals_connect_count_
int normals_connect_count_
Keep track of number of connections for normals.
Definition: gazebo_ros_depth_camera.h:124
gazebo::GazeboRosDepthCamera::point_cloud_msg_
sensor_msgs::PointCloud2 point_cloud_msg_
PointCloud2 point cloud message.
Definition: gazebo_ros_depth_camera.h:151


gazebo_plugins
Author(s): John Hsu
autogenerated on Thu Sep 5 2024 02:49:55