36 #include <boost/thread.hpp> 38 #include "rtabmap_ros/RGBDImages.h" 79 bool approxSync =
true;
81 double approxSyncMaxInterval = 0.0;
82 pnh.
param(
"approx_sync", approxSync, approxSync);
83 pnh.
param(
"approx_sync_max_interval", approxSyncMaxInterval, approxSyncMaxInterval);
84 pnh.
param(
"queue_size", queueSize, queueSize);
85 pnh.
param(
"rgbd_cameras", rgbdCameras, rgbdCameras);
89 NODELET_INFO(
"%s: approx_sync_max_interval = %f",
getName().c_str(), approxSyncMaxInterval);
98 for(
int i=0; i<rgbdCameras; ++i)
105 std::string subscribedTopicsMsg_;
109 if(approxSync && approxSyncMaxInterval>0.0)
111 rgbd2ApproximateSync_->setMaxIntervalDuration(
ros::Duration(approxSyncMaxInterval));
114 else if(rgbdCameras==3)
117 if(approxSync && approxSyncMaxInterval>0.0)
119 rgbd3ApproximateSync_->setMaxIntervalDuration(
ros::Duration(approxSyncMaxInterval));
122 else if(rgbdCameras==4)
125 if(approxSync && approxSyncMaxInterval>0.0)
127 rgbd4ApproximateSync_->setMaxIntervalDuration(
ros::Duration(approxSyncMaxInterval));
130 else if(rgbdCameras==5)
133 if(approxSync && approxSyncMaxInterval>0.0)
135 rgbd5ApproximateSync_->setMaxIntervalDuration(
ros::Duration(approxSyncMaxInterval));
138 else if(rgbdCameras==6)
141 if(approxSync && approxSyncMaxInterval>0.0)
143 rgbd6ApproximateSync_->setMaxIntervalDuration(
ros::Duration(approxSyncMaxInterval));
146 else if(rgbdCameras==7)
148 SYNC_DECL7(
RGBDXSync, rgbd7, approxSync, queueSize, (*
rgbdSubs_[0]), (*
rgbdSubs_[1]), (*
rgbdSubs_[2]), (*
rgbdSubs_[3]), (*
rgbdSubs_[4]), (*
rgbdSubs_[5]), (*
rgbdSubs_[6]));
149 if(approxSync && approxSyncMaxInterval>0.0)
151 rgbd7ApproximateSync_->setMaxIntervalDuration(
ros::Duration(approxSyncMaxInterval));
154 else if(rgbdCameras==8)
156 SYNC_DECL8(
RGBDXSync, rgbd8, approxSync, queueSize, (*
rgbdSubs_[0]), (*
rgbdSubs_[1]), (*
rgbdSubs_[2]), (*
rgbdSubs_[3]), (*
rgbdSubs_[4]), (*
rgbdSubs_[5]), (*
rgbdSubs_[6]), (*
rgbdSubs_[7]));
157 if(approxSync && approxSyncMaxInterval>0.0)
159 rgbd8ApproximateSync_->setMaxIntervalDuration(
ros::Duration(approxSyncMaxInterval));
165 approxSync&&approxSyncMaxInterval!=0.0?
uFormat(
" (approx sync max interval=%fs)", approxSyncMaxInterval).c_str():
"");
168 void warningLoop(
const std::string & subscribedTopicsMsg,
bool approxSync)
176 ROS_WARN(
"%s: Did not receive data since 5 seconds! Make sure the input topics are " 177 "published (\"$ rostopic hz my_topic\") and the timestamps in their " 178 "header are set. %s%s",
180 approxSync?
"":
"Parameter \"approx_sync\" is false, which means that input " 181 "topics should have all the exact timestamp for the callback to be called.",
182 subscribedTopicsMsg.c_str());
187 DATA_SYNCS2(rgbd2, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage);
188 DATA_SYNCS3(rgbd3, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage);
189 DATA_SYNCS4(rgbd4, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage);
190 DATA_SYNCS5(rgbd5, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage);
191 DATA_SYNCS6(rgbd6, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage);
192 DATA_SYNCS7(rgbd7, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage);
193 DATA_SYNCS8(rgbd8, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage);
201 std::vector<message_filters::Subscriber<rtabmap_ros::RGBDImage>*>
rgbdSubs_;
205 void RGBDXSync::rgbd2Callback(
206 const rtabmap_ros::RGBDImageConstPtr& image0,
207 const rtabmap_ros::RGBDImageConstPtr& image1)
210 rtabmap_ros::RGBDImages output;
211 output.header = image0->header;
212 output.rgbd_images.resize(2);
213 output.rgbd_images[0]=(*image0);
214 output.rgbd_images[1]=(*image1);
218 void RGBDXSync::rgbd3Callback(
219 const rtabmap_ros::RGBDImageConstPtr& image0,
220 const rtabmap_ros::RGBDImageConstPtr& image1,
221 const rtabmap_ros::RGBDImageConstPtr& image2)
224 rtabmap_ros::RGBDImages output;
225 output.header = image0->header;
226 output.rgbd_images.resize(3);
227 output.rgbd_images[0]=(*image0);
228 output.rgbd_images[1]=(*image1);
229 output.rgbd_images[2]=(*image2);
233 void RGBDXSync::rgbd4Callback(
234 const rtabmap_ros::RGBDImageConstPtr& image0,
235 const rtabmap_ros::RGBDImageConstPtr& image1,
236 const rtabmap_ros::RGBDImageConstPtr& image2,
237 const rtabmap_ros::RGBDImageConstPtr& image3)
240 rtabmap_ros::RGBDImages output;
241 output.header = image0->header;
242 output.rgbd_images.resize(4);
243 output.rgbd_images[0]=(*image0);
244 output.rgbd_images[1]=(*image1);
245 output.rgbd_images[2]=(*image2);
246 output.rgbd_images[3]=(*image3);
250 void RGBDXSync::rgbd5Callback(
251 const rtabmap_ros::RGBDImageConstPtr& image0,
252 const rtabmap_ros::RGBDImageConstPtr& image1,
253 const rtabmap_ros::RGBDImageConstPtr& image2,
254 const rtabmap_ros::RGBDImageConstPtr& image3,
255 const rtabmap_ros::RGBDImageConstPtr& image4)
258 rtabmap_ros::RGBDImages output;
259 output.header = image0->header;
260 output.rgbd_images.resize(5);
261 output.rgbd_images[0]=(*image0);
262 output.rgbd_images[1]=(*image1);
263 output.rgbd_images[2]=(*image2);
264 output.rgbd_images[3]=(*image3);
265 output.rgbd_images[4]=(*image4);
269 void RGBDXSync::rgbd6Callback(
270 const rtabmap_ros::RGBDImageConstPtr& image0,
271 const rtabmap_ros::RGBDImageConstPtr& image1,
272 const rtabmap_ros::RGBDImageConstPtr& image2,
273 const rtabmap_ros::RGBDImageConstPtr& image3,
274 const rtabmap_ros::RGBDImageConstPtr& image4,
275 const rtabmap_ros::RGBDImageConstPtr& image5)
278 rtabmap_ros::RGBDImages output;
279 output.header = image0->header;
280 output.rgbd_images.resize(6);
281 output.rgbd_images[0]=(*image0);
282 output.rgbd_images[1]=(*image1);
283 output.rgbd_images[2]=(*image2);
284 output.rgbd_images[3]=(*image3);
285 output.rgbd_images[4]=(*image4);
286 output.rgbd_images[5]=(*image5);
290 void RGBDXSync::rgbd7Callback(
291 const rtabmap_ros::RGBDImageConstPtr& image0,
292 const rtabmap_ros::RGBDImageConstPtr& image1,
293 const rtabmap_ros::RGBDImageConstPtr& image2,
294 const rtabmap_ros::RGBDImageConstPtr& image3,
295 const rtabmap_ros::RGBDImageConstPtr& image4,
296 const rtabmap_ros::RGBDImageConstPtr& image5,
297 const rtabmap_ros::RGBDImageConstPtr& image6)
300 rtabmap_ros::RGBDImages output;
301 output.header = image0->header;
302 output.rgbd_images.resize(7);
303 output.rgbd_images[0]=(*image0);
304 output.rgbd_images[1]=(*image1);
305 output.rgbd_images[2]=(*image2);
306 output.rgbd_images[3]=(*image3);
307 output.rgbd_images[4]=(*image4);
308 output.rgbd_images[5]=(*image5);
309 output.rgbd_images[6]=(*image6);
313 void RGBDXSync::rgbd8Callback(
314 const rtabmap_ros::RGBDImageConstPtr& image0,
315 const rtabmap_ros::RGBDImageConstPtr& image1,
316 const rtabmap_ros::RGBDImageConstPtr& image2,
317 const rtabmap_ros::RGBDImageConstPtr& image3,
318 const rtabmap_ros::RGBDImageConstPtr& image4,
319 const rtabmap_ros::RGBDImageConstPtr& image5,
320 const rtabmap_ros::RGBDImageConstPtr& image6,
321 const rtabmap_ros::RGBDImageConstPtr& image7)
324 rtabmap_ros::RGBDImages output;
325 output.header = image0->header;
326 output.rgbd_images.resize(8);
327 output.rgbd_images[0]=(*image0);
328 output.rgbd_images[1]=(*image1);
329 output.rgbd_images[2]=(*image2);
330 output.rgbd_images[3]=(*image3);
331 output.rgbd_images[4]=(*image4);
332 output.rgbd_images[5]=(*image5);
333 output.rgbd_images[6]=(*image6);
334 output.rgbd_images[7]=(*image7);
void warningLoop(const std::string &subscribedTopicsMsg, bool approxSync)
std::string uFormat(const char *fmt,...)
#define SYNC_DECL3(CLASS, PREFIX, APPROX, QUEUE_SIZE, SUB0, SUB1, SUB2)
ros::NodeHandle & getNodeHandle() const
#define SYNC_DECL8(CLASS, PREFIX, APPROX, QUEUE_SIZE, SUB0, SUB1, SUB2, SUB3, SUB4, SUB5, SUB6, SUB7)
ros::NodeHandle & getPrivateNodeHandle() const
DATA_SYNCS5(rgbd5, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage)
DATA_SYNCS3(rgbd3, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage)
DATA_SYNCS7(rgbd7, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage)
DATA_SYNCS8(rgbd8, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage)
const std::string & getName() const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
DATA_SYNCS2(rgbd2, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage)
void publish(const boost::shared_ptr< M > &message) const
#define SYNC_DECL5(CLASS, PREFIX, APPROX, QUEUE_SIZE, SUB0, SUB1, SUB2, SUB3, SUB4)
std::vector< message_filters::Subscriber< rtabmap_ros::RGBDImage > * > rgbdSubs_
DATA_SYNCS6(rgbd6, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
DATA_SYNCS4(rgbd4, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage, rtabmap_ros::RGBDImage)
#define NODELET_INFO(...)
#define SYNC_DECL6(CLASS, PREFIX, APPROX, QUEUE_SIZE, SUB0, SUB1, SUB2, SUB3, SUB4, SUB5)
#define SYNC_DECL7(CLASS, PREFIX, APPROX, QUEUE_SIZE, SUB0, SUB1, SUB2, SUB3, SUB4, SUB5, SUB6)
PLUGINLIB_EXPORT_CLASS(rtabmap_ros::CoreWrapper, nodelet::Nodelet)
boost::thread * warningThread_
#define SYNC_DECL4(CLASS, PREFIX, APPROX, QUEUE_SIZE, SUB0, SUB1, SUB2, SUB3)
#define SYNC_DECL2(CLASS, PREFIX, APPROX, QUEUE_SIZE, SUB0, SUB1)
#define SYNC_INIT(PREFIX)
ros::Publisher rgbdImagesPub_