32 #include <sensor_msgs/Image.h> 33 #include <sensor_msgs/CompressedImage.h> 35 #include <sensor_msgs/CameraInfo.h> 45 #include <opencv2/highgui/highgui.hpp> 47 #include <boost/thread.hpp> 49 #include "rtabmap_ros/RGBDImage.h" 90 bool approxSync =
false;
91 pnh.
param(
"approx_sync", approxSync, approxSync);
92 pnh.
param(
"queue_size", queueSize, queueSize);
127 std::string subscribedTopicsMsg =
uFormat(
"\n%s subscribed to (%s sync):\n %s \\\n %s \\\n %s \\\n %s",
129 approxSync?
"approx":
"exact",
139 void warningLoop(
const std::string & subscribedTopicsMsg,
bool approxSync)
147 ROS_WARN(
"%s: Did not receive data since 5 seconds! Make sure the input topics are " 148 "published (\"$ rostopic hz my_topic\") and the timestamps in their " 149 "header are set. %s%s",
151 approxSync?
"":
"Parameter \"approx_sync\" is false, which means that input " 152 "topics should have all the exact timestamp for the callback to be called.",
153 subscribedTopicsMsg.c_str());
159 const sensor_msgs::ImageConstPtr& imageLeft,
160 const sensor_msgs::ImageConstPtr& imageRight,
161 const sensor_msgs::CameraInfoConstPtr& cameraInfoLeft,
162 const sensor_msgs::CameraInfoConstPtr& cameraInfoRight)
167 double leftStamp = imageLeft->header.stamp.toSec();
168 double rightStamp = imageRight->header.stamp.toSec();
169 double leftInfoStamp = cameraInfoLeft->header.stamp.toSec();
170 double rightInfoStamp = cameraInfoRight->header.stamp.toSec();
172 rtabmap_ros::RGBDImage msg;
173 msg.header.frame_id = cameraInfoLeft->header.frame_id;
174 msg.header.stamp = imageLeft->header.stamp>imageRight->header.stamp?imageLeft->header.stamp:imageRight->header.stamp;
175 msg.rgb_camera_info = *cameraInfoLeft;
176 msg.depth_camera_info = *cameraInfoRight;
180 bool publishCompressed =
true;
186 publishCompressed =
false;
190 if(publishCompressed)
194 rtabmap_ros::RGBDImage msgCompressed = msg;
197 imagePtr->toCompressedImageMsg(msgCompressed.rgb_compressed,
cv_bridge::JPG);
200 imageDepthPtr->toCompressedImageMsg(msgCompressed.depth_compressed,
cv_bridge::JPG);
208 msg.rgb = *imageLeft;
209 msg.depth = *imageRight;
213 if( leftStamp != imageLeft->header.stamp.toSec() ||
214 rightStamp != imageRight->header.stamp.toSec())
216 NODELET_ERROR(
"Input stamps changed between the beginning and the end of the callback! Make " 217 "sure the node publishing the topics doesn't override the same data after publishing them. A " 218 "solution is to use this node within another nodelet manager. Stamps: " 219 "left%f->%f right=%f->%f",
220 leftStamp, imageLeft->header.stamp.toSec(),
221 rightStamp, imageRight->header.stamp.toSec());
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
std::string getTopic() const
std::string uFormat(const char *fmt,...)
#define NODELET_ERROR(...)
void publish(const boost::shared_ptr< M > &message) const
std::string resolveName(const std::string &name, bool remap=true) const
image_transport::SubscriberFilter imageLeftSub_
const std::string & getName() const
message_filters::Subscriber< sensor_msgs::CameraInfo > cameraInfoLeftSub_
void warningLoop(const std::string &subscribedTopicsMsg, bool approxSync)
ros::NodeHandle & getPrivateNodeHandle() const
message_filters::sync_policies::ExactTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo > MyExactSyncPolicy
ros::Publisher rgbdImageCompressedPub_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Publisher rgbdImagePub_
ros::NodeHandle & getNodeHandle() const
message_filters::Synchronizer< MyExactSyncPolicy > * exactSync_
message_filters::Subscriber< sensor_msgs::CameraInfo > cameraInfoRightSub_
void subscribe(ImageTransport &it, const std::string &base_topic, uint32_t queue_size, const TransportHints &transport_hints=TransportHints())
message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo > MyApproxSyncPolicy
#define NODELET_INFO(...)
uint32_t getNumSubscribers() const
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
boost::thread * warningThread_
PLUGINLIB_EXPORT_CLASS(rtabmap_ros::CoreWrapper, nodelet::Nodelet)
void callback(const sensor_msgs::ImageConstPtr &imageLeft, const sensor_msgs::ImageConstPtr &imageRight, const sensor_msgs::CameraInfoConstPtr &cameraInfoLeft, const sensor_msgs::CameraInfoConstPtr &cameraInfoRight)
message_filters::Synchronizer< MyApproxSyncPolicy > * approxSync_
image_transport::SubscriberFilter imageRightSub_
#define NODELET_DEBUG(...)
std::string getTopic() const
ros::Time lastCompressedPublished_