diff --git a/launch/azimut3/az3_mapping_robot_stereo_nav.launch b/launch/azimut3/az3_mapping_robot_stereo_nav.launch index d8e5e61f..915c2486 100644 --- a/launch/azimut3/az3_mapping_robot_stereo_nav.launch +++ b/launch/azimut3/az3_mapping_robot_stereo_nav.launch @@ -69,7 +69,7 @@ + Throttle camera images to 5 Hz (), odometry on azimut cannot run over 5Hz --> @@ -77,15 +77,22 @@ - + - - - + + + - + + + + + + + + diff --git a/src/nodelets/point_cloud_xyz.cpp b/src/nodelets/point_cloud_xyz.cpp index dcf2739e..6765febd 100644 --- a/src/nodelets/point_cloud_xyz.cpp +++ b/src/nodelets/point_cloud_xyz.cpp @@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -62,6 +63,7 @@ public: virtual ~PointCloudXYZ() { delete sync_; + delete syncDisparity_; } private: @@ -77,12 +79,18 @@ private: sync_ = new message_filters::Synchronizer(MySyncPolicy(queueSize), imageDepthSub_, cameraInfoSub_); sync_->registerCallback(boost::bind(&PointCloudXYZ::callback, this, _1, _2)); - cloudPub_ = nh.advertise("cloud", 1); + + syncDisparity_ = new message_filters::Synchronizer(MySyncDispPolicy(queueSize), disparitySub_, disparityCameraInfoSub_); + syncDisparity_->registerCallback(boost::bind(&PointCloudXYZ::callbackDisparity, this, _1, _2)); image_transport::ImageTransport it(nh); + imageDepthSub_.subscribe(it, "depth/image", 1); + cameraInfoSub_.subscribe(nh, "depth/camera_info", 1); - imageDepthSub_.subscribe(it, "depth", 1); - cameraInfoSub_.subscribe(nh, "camera_info", 1); + disparitySub_.subscribe(nh, "disparity/image", 1); + disparityCameraInfoSub_.subscribe(nh, "disparity/camera_info", 1); + + cloudPub_ = nh.advertise("cloud", 1); } @@ -135,7 +143,55 @@ private: //publish the message cloudPub_.publish(rosCloud); } -} + } + + void callbackDisparity( + const stereo_msgs::DisparityImageConstPtr& disparityMsg, + const sensor_msgs::CameraInfoConstPtr& cameraInfo) + { + if(disparityMsg->image.encoding.compare(sensor_msgs::image_encodings::TYPE_32FC1) !=0) + { + ROS_ERROR("Input type must be disparity=32FC1"); + return; + } + + // sensor_msgs::image_encodings::TYPE_32FC1 + cv::Mat disparity(disparityMsg->image.height, disparityMsg->image.width, CV_32FC1, const_cast(disparityMsg->image.data.data())); + + if(cloudPub_.getNumSubscribers()) + { + image_geometry::PinholeCameraModel model; + model.fromCameraInfo(*cameraInfo); + float cx = model.cx(); + float cy = model.cy(); + + pcl::PointCloud::Ptr pclCloud; + pclCloud = rtabmap::util3d::cloudFromDisparity( + disparity, + cx, + cy, + disparityMsg->f, + disparityMsg->T, + decimation_); + + if(voxelSize_ > 0.0) + { + pclCloud = rtabmap::util3d::voxelize(pclCloud, voxelSize_); + } + + //********************* + // Publish Map + //********************* + + sensor_msgs::PointCloud2 rosCloud; + pcl::toROSMsg(*pclCloud, rosCloud); + rosCloud.header.stamp = disparityMsg->header.stamp; + rosCloud.header.frame_id = disparityMsg->header.frame_id; + + //publish the message + cloudPub_.publish(rosCloud); + } + } private: @@ -146,10 +202,14 @@ private: image_transport::SubscriberFilter imageDepthSub_; message_filters::Subscriber cameraInfoSub_; + message_filters::Subscriber disparitySub_; + message_filters::Subscriber disparityCameraInfoSub_; - // without odometry subscription (odometry is computed by this node) typedef message_filters::sync_policies::ApproximateTime MySyncPolicy; message_filters::Synchronizer * sync_; + + typedef message_filters::sync_policies::ApproximateTime MySyncDispPolicy; + message_filters::Synchronizer * syncDisparity_; }; PLUGINLIB_EXPORT_CLASS(rtabmap::PointCloudXYZ, nodelet::Nodelet); diff --git a/src/nodelets/point_cloud_xyzrgb.cpp b/src/nodelets/point_cloud_xyzrgb.cpp index 10c1adb0..037b65c4 100644 --- a/src/nodelets/point_cloud_xyzrgb.cpp +++ b/src/nodelets/point_cloud_xyzrgb.cpp @@ -162,8 +162,6 @@ private: image_transport::SubscriberFilter imageDepthSub_; message_filters::Subscriber cameraInfoSub_; - - // without odometry subscription (odometry is computed by this node) typedef message_filters::sync_policies::ApproximateTime MySyncPolicy; message_filters::Synchronizer * sync_; };