@@ -223,7 +223,6 @@ bool RgbdSensor_nws_ros2::detach()
223
223
224
224
bool RgbdSensor_nws_ros2::setCamInfo (sensor_msgs::msg::CameraInfo& cameraInfo,
225
225
const std::string& frame_id,
226
- const yarp::os::Stamp& stamp,
227
226
const SensorType& sensorType)
228
227
{
229
228
double phyF = 0.0 ;
@@ -259,22 +258,21 @@ bool RgbdSensor_nws_ros2::setCamInfo(sensor_msgs::msg::CameraInfo& cameraInfo,
259
258
}
260
259
261
260
distModel = camData.find (" distortionModel" ).asString ();
262
- if (distModel != " plumb_bob" )
263
- {
264
- yCError (RGBDSENSOR_NWS_ROS2) << " Distortion model not supported" ;
265
- return false ;
266
- }
267
261
268
262
parVector.emplace_back (phyF," physFocalLength" );
269
263
parVector.emplace_back (fx," focalLengthX" );
270
264
parVector.emplace_back (fy," focalLengthY" );
271
265
parVector.emplace_back (cx," principalPointX" );
272
266
parVector.emplace_back (cy," principalPointY" );
273
- parVector.emplace_back (k1," k1" );
274
- parVector.emplace_back (k2," k2" );
275
- parVector.emplace_back (t1," t1" );
276
- parVector.emplace_back (t2," t2" );
277
- parVector.emplace_back (k3," k3" );
267
+
268
+ if (distModel != " none" )
269
+ {
270
+ parVector.emplace_back (k1," k1" );
271
+ parVector.emplace_back (k2," k2" );
272
+ parVector.emplace_back (t1," t1" );
273
+ parVector.emplace_back (t2," t2" );
274
+ parVector.emplace_back (k3," k3" );
275
+ }
278
276
279
277
for (auto & par : parVector) {
280
278
if (!camData.check (par.parname )) {
@@ -285,18 +283,19 @@ bool RgbdSensor_nws_ros2::setCamInfo(sensor_msgs::msg::CameraInfo& cameraInfo,
285
283
}
286
284
287
285
cameraInfo.header .frame_id = frame_id;
288
- cameraInfo.header .stamp .sec = static_cast <int >(stamp.getTime ()); // FIXME
289
- cameraInfo.header .stamp .nanosec = static_cast <int >(1000000000UL * (stamp.getTime () - int (stamp.getTime ()))); // FIXME
290
286
cameraInfo.width = sensorType == COLOR_SENSOR ? sensor_p->getRgbWidth () : sensor_p->getDepthWidth ();
291
287
cameraInfo.height = sensorType == COLOR_SENSOR ? sensor_p->getRgbHeight () : sensor_p->getDepthHeight ();
292
288
cameraInfo.distortion_model = distModel;
293
289
294
- cameraInfo.d .resize (5 );
295
- cameraInfo.d [0 ] = k1;
296
- cameraInfo.d [1 ] = k2;
297
- cameraInfo.d [2 ] = t1;
298
- cameraInfo.d [3 ] = t2;
299
- cameraInfo.d [4 ] = k3;
290
+ if (distModel != " none" )
291
+ {
292
+ cameraInfo.d .resize (5 );
293
+ cameraInfo.d [0 ] = k1;
294
+ cameraInfo.d [1 ] = k2;
295
+ cameraInfo.d [2 ] = t1;
296
+ cameraInfo.d [3 ] = t2;
297
+ cameraInfo.d [4 ] = k3;
298
+ }
300
299
301
300
cameraInfo.k [0 ] = fx; cameraInfo.k [1 ] = 0 ; cameraInfo.k [2 ] = cx;
302
301
cameraInfo.k [3 ] = 0 ; cameraInfo.k [4 ] = fy; cameraInfo.k [5 ] = cy;
@@ -356,7 +355,14 @@ bool RgbdSensor_nws_ros2::writeData()
356
355
oldDepthStamp = depthStamp;
357
356
}
358
357
359
- // TBD: We should check here somehow if the timestamp was correctly updated and, if not, update it ourselves.
358
+ // Call setCamInfo only the first time
359
+ if (m_firstTime) {
360
+ setCamInfo (m_camInfoData.colorCamInfo , " color_frame" , COLOR_SENSOR);
361
+ setCamInfo (m_camInfoData.depthCamInfo , " depth_frame" , DEPTH_SENSOR);
362
+ m_firstTime = false ;
363
+ }
364
+
365
+ // Use m_camInfoData for subsequent calls
360
366
if (rgb_data_ok) {
361
367
sensor_msgs::msg::Image rColorImage;
362
368
rColorImage.data .resize (colorImage.getRawImageSize ());
@@ -372,15 +378,10 @@ bool RgbdSensor_nws_ros2::writeData()
372
378
373
379
rosPublisher_color->publish (rColorImage);
374
380
375
- sensor_msgs::msg::CameraInfo camInfoC;
376
- if (setCamInfo (camInfoC, m_color_frame_id, colorStamp, COLOR_SENSOR)) {
377
- if (m_forceInfoSync) {
378
- camInfoC.header .stamp = rColorImage.header .stamp ;
379
- }
380
- rosPublisher_colorCaminfo->publish (camInfoC);
381
- } else {
382
- yCWarning (RGBDSENSOR_NWS_ROS2, " Missing color camera parameters... camera info messages will be not sent" );
381
+ if (m_forceInfoSync) {
382
+ m_camInfoData.colorCamInfo .header .stamp = rColorImage.header .stamp ;
383
383
}
384
+ rosPublisher_colorCaminfo->publish (m_camInfoData.colorCamInfo );
384
385
}
385
386
386
387
if (depth_data_ok)
@@ -399,15 +400,10 @@ bool RgbdSensor_nws_ros2::writeData()
399
400
400
401
rosPublisher_depth->publish (rDepthImage);
401
402
402
- sensor_msgs::msg::CameraInfo camInfoD;
403
- if (setCamInfo (camInfoD, m_depth_frame_id, depthStamp, DEPTH_SENSOR)) {
404
- if (m_forceInfoSync) {
405
- camInfoD.header .stamp = rDepthImage.header .stamp ;
406
- }
407
- rosPublisher_depthCaminfo->publish (camInfoD);
408
- } else {
409
- yCWarning (RGBDSENSOR_NWS_ROS2, " Missing depth camera parameters... camera info messages will be not sent" );
403
+ if (m_forceInfoSync) {
404
+ m_camInfoData.depthCamInfo .header .stamp = rDepthImage.header .stamp ;
410
405
}
406
+ rosPublisher_depthCaminfo->publish (m_camInfoData.depthCamInfo );
411
407
}
412
408
413
409
return true ;
0 commit comments