@@ -83,12 +83,7 @@ FusionNode<TargetMsg3D, ObjType, Msg2D>::FusionNode(
83
83
" /sensing/camera/camera" + std::to_string (roi_i) + " /camera_info" );
84
84
}
85
85
86
- input_offset_ms_ = declare_parameter<std::vector<double >>(" input_offset_ms" );
87
- if (!input_offset_ms_.empty () && rois_number_ > input_offset_ms_.size ()) {
88
- throw std::runtime_error (" The number of offsets does not match the number of topics." );
89
- }
90
-
91
- // sub camera info
86
+ // subscribe camera info
92
87
camera_info_subs_.resize (rois_number_);
93
88
for (std::size_t roi_i = 0 ; roi_i < rois_number_; ++roi_i) {
94
89
std::function<void (const sensor_msgs::msg::CameraInfo::ConstSharedPtr msg)> fnc =
@@ -97,18 +92,16 @@ FusionNode<TargetMsg3D, ObjType, Msg2D>::FusionNode(
97
92
input_camera_info_topics.at (roi_i), rclcpp::QoS{1 }.best_effort (), fnc);
98
93
}
99
94
100
- // sub rois
95
+ // subscribe rois
101
96
rois_subs_.resize (rois_number_);
102
- cached_det2d_msgs_.resize (rois_number_);
103
- is_fused_.resize (rois_number_, false );
104
97
for (std::size_t roi_i = 0 ; roi_i < rois_number_; ++roi_i) {
105
98
std::function<void (const typename Msg2D::ConstSharedPtr msg)> roi_callback =
106
99
std::bind (&FusionNode::roiCallback, this , std::placeholders::_1, roi_i);
107
100
rois_subs_.at (roi_i) = this ->create_subscription <Msg2D>(
108
101
input_rois_topics.at (roi_i), rclcpp::QoS{1 }.best_effort (), roi_callback);
109
102
}
110
103
111
- // subscribers
104
+ // subscribe 3d detection
112
105
std::function<void (const typename TargetMsg3D::ConstSharedPtr msg)> sub_callback =
113
106
std::bind (&FusionNode::subCallback, this , std::placeholders::_1);
114
107
sub_ =
@@ -123,8 +116,11 @@ FusionNode<TargetMsg3D, ObjType, Msg2D>::FusionNode(
123
116
timer_ = rclcpp::create_timer (
124
117
this , get_clock (), period_ns, std::bind (&FusionNode::timer_callback, this ));
125
118
126
- // camera manager initialization
127
- det2d_list_.resize (rois_number_);
119
+ // camera offset settings
120
+ std::vector<double > input_offset_ms = declare_parameter<std::vector<double >>(" input_offset_ms" );
121
+ if (!input_offset_ms.empty () && rois_number_ > input_offset_ms.size ()) {
122
+ throw std::runtime_error (" The number of offsets does not match the number of topics." );
123
+ }
128
124
129
125
// camera projection settings
130
126
std::vector<bool > point_project_to_unrectified_image =
@@ -150,16 +146,19 @@ FusionNode<TargetMsg3D, ObjType, Msg2D>::FusionNode(
150
146
}
151
147
}
152
148
}
149
+ approx_grid_cell_w_size_ = declare_parameter<float >(" approximation_grid_cell_width" );
150
+ approx_grid_cell_h_size_ = declare_parameter<float >(" approximation_grid_cell_height" );
151
+
152
+ // camera manager initialization
153
+ det2d_list_.resize (rois_number_);
153
154
for (std::size_t roi_i = 0 ; roi_i < rois_number_; ++roi_i) {
154
155
det2d_list_.at (roi_i).id = roi_i;
155
156
det2d_list_.at (roi_i).project_to_unrectified_image =
156
157
point_project_to_unrectified_image.at (roi_i);
157
158
det2d_list_.at (roi_i).approximate_camera_projection = approx_camera_projection.at (roi_i);
159
+ det2d_list_.at (roi_i).input_offset_ms = input_offset_ms.at (roi_i);
158
160
}
159
161
160
- approx_grid_cell_w_size_ = declare_parameter<float >(" approximation_grid_cell_width" );
161
- approx_grid_cell_h_size_ = declare_parameter<float >(" approximation_grid_cell_height" );
162
-
163
162
// debugger
164
163
if (declare_parameter (" debug_mode" , false )) {
165
164
std::vector<std::string> input_camera_topics;
@@ -231,16 +230,16 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::exportProcess()
231
230
{
232
231
timer_->cancel ();
233
232
234
- postprocess (*(cached_msg_. second ));
235
- publish (*(cached_msg_. second ));
233
+ postprocess (*(cached_det3d_msg_ptr_ ));
234
+ publish (*(cached_det3d_msg_ptr_ ));
236
235
237
236
// add processing time for debug
238
237
if (debug_publisher_) {
239
238
const double cyclic_time_ms = stop_watch_ptr_->toc (" cyclic_time" , true );
240
239
const double pipeline_latency_ms =
241
240
std::chrono::duration<double , std::milli>(
242
241
std::chrono::nanoseconds (
243
- (this ->get_clock ()->now () - cached_msg_. second ->header .stamp ).nanoseconds ()))
242
+ (this ->get_clock ()->now () - cached_det3d_msg_ptr_ ->header .stamp ).nanoseconds ()))
244
243
.count ();
245
244
debug_publisher_->publish <tier4_debug_msgs::msg::Float64Stamped>(
246
245
" debug/cyclic_time_ms" , cyclic_time_ms);
@@ -256,19 +255,19 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::exportProcess()
256
255
for (auto & det_2d : det2d_list_) {
257
256
det_2d.is_fused = false ;
258
257
}
259
- cached_msg_. second = nullptr ;
258
+ cached_det3d_msg_ptr_ = nullptr ;
260
259
}
261
260
262
261
template <class TargetMsg3D , class Obj , class Msg2D >
263
262
void FusionNode<TargetMsg3D, Obj, Msg2D>::subCallback(
264
- const typename TargetMsg3D::ConstSharedPtr input_msg )
263
+ const typename TargetMsg3D::ConstSharedPtr det3d_msg )
265
264
{
266
265
std::unique_ptr<ScopedTimeTrack> st_ptr;
267
266
if (time_keeper_) st_ptr = std::make_unique<ScopedTimeTrack>(__func__, *time_keeper_);
268
267
269
268
std::lock_guard<std::mutex> lock (mutex_cached_msgs_);
270
269
271
- if (cached_msg_. second != nullptr ) {
270
+ if (cached_det3d_msg_ptr_ != nullptr ) {
272
271
// PROCESS: if the main message is remained (and roi is not collected all) publish the main
273
272
// message may processed partially with arrived 2d rois
274
273
stop_watch_ptr_->toc (" processing_time" , true );
@@ -289,7 +288,7 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::subCallback(
289
288
stop_watch_ptr_->toc (" processing_time" , true );
290
289
291
290
// PROCESS: preprocess the main message
292
- typename TargetMsg3D::SharedPtr output_msg = std::make_shared<TargetMsg3D>(*input_msg );
291
+ typename TargetMsg3D::SharedPtr output_msg = std::make_shared<TargetMsg3D>(*det3d_msg );
293
292
preprocess (*output_msg);
294
293
295
294
// PROCESS: fuse the main message with the cached roi messages
@@ -338,7 +337,7 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::subCallback(
338
337
debugger_->clear ();
339
338
}
340
339
341
- fuseOnSingleImage (*input_msg , roi_i, *(roi_msgs[matched_stamp]), *output_msg);
340
+ fuseOnSingleImage (*det3d_msg , roi_i, *(roi_msgs[matched_stamp]), *output_msg);
342
341
roi_msgs.erase (matched_stamp);
343
342
det_2d.is_fused = true ;
344
343
@@ -353,8 +352,8 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::subCallback(
353
352
}
354
353
}
355
354
}
356
- cached_msg_. first = timestamp_nsec;
357
- cached_msg_. second = output_msg;
355
+ cached_det3d_msg_timestamp_ = timestamp_nsec;
356
+ cached_det3d_msg_ptr_ = output_msg;
358
357
359
358
// PROCESS: if all camera fused, postprocess and publish the main message
360
359
if (checkAllDet2dFused (det2d_list_)) {
@@ -368,7 +367,7 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::subCallback(
368
367
369
368
template <class TargetMsg3D , class Obj , class Msg2D >
370
369
void FusionNode<TargetMsg3D, Obj, Msg2D>::roiCallback(
371
- const typename Msg2D::ConstSharedPtr input_roi_msg , const std::size_t roi_i)
370
+ const typename Msg2D::ConstSharedPtr det2d_msg , const std::size_t roi_i)
372
371
{
373
372
std::unique_ptr<ScopedTimeTrack> st_ptr;
374
373
if (time_keeper_) st_ptr = std::make_unique<ScopedTimeTrack>(__func__, *time_keeper_);
@@ -377,12 +376,13 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::roiCallback(
377
376
378
377
auto & det_2d = det2d_list_.at (roi_i);
379
378
380
- int64_t timestamp_nsec = (*input_roi_msg). header . stamp . sec * static_cast < int64_t >( 1e9 ) +
381
- (*input_roi_msg ).header .stamp .nanosec ;
379
+ int64_t timestamp_nsec =
380
+ (*det2d_msg). header . stamp . sec * static_cast < int64_t >( 1e9 ) + (*det2d_msg ).header .stamp .nanosec ;
382
381
383
382
// if cached Msg exist, try to match
384
- if (cached_msg_.second != nullptr ) {
385
- int64_t new_stamp = cached_msg_.first + det_2d.input_offset_ms * static_cast <int64_t >(1e6 );
383
+ if (cached_det3d_msg_ptr_ != nullptr ) {
384
+ int64_t new_stamp =
385
+ cached_det3d_msg_timestamp_ + det_2d.input_offset_ms * static_cast <int64_t >(1e6 );
386
386
int64_t interval = abs (timestamp_nsec - new_stamp);
387
387
388
388
// PROCESS: if matched, fuse the main message with the roi message
@@ -391,19 +391,19 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::roiCallback(
391
391
if (det_2d.camera_projector_ptr == nullptr ) {
392
392
RCLCPP_WARN_THROTTLE (
393
393
this ->get_logger (), *this ->get_clock (), 5000 , " no camera info. id is %zu" , roi_i);
394
- (cached_det2d_msgs_. at (roi_i)) [timestamp_nsec] = input_roi_msg ;
394
+ det_2d. cached_det2d_msgs [timestamp_nsec] = det2d_msg ;
395
395
return ;
396
396
}
397
397
398
398
if (debugger_) {
399
399
debugger_->clear ();
400
400
}
401
401
// PROCESS: fuse the main message with the roi message
402
- fuseOnSingleImage (*(cached_msg_. second ), roi_i, *input_roi_msg , *(cached_msg_. second ));
402
+ fuseOnSingleImage (*(cached_det3d_msg_ptr_ ), roi_i, *det2d_msg , *(cached_det3d_msg_ptr_ ));
403
403
det_2d.is_fused = true ;
404
404
405
405
if (debug_publisher_) {
406
- double timestamp_interval_ms = (timestamp_nsec - cached_msg_. first ) / 1e6 ;
406
+ double timestamp_interval_ms = (timestamp_nsec - cached_det3d_msg_timestamp_ ) / 1e6 ;
407
407
debug_publisher_->publish <tier4_debug_msgs::msg::Float64Stamped>(
408
408
" debug/roi" + std::to_string (roi_i) + " /timestamp_interval_ms" , timestamp_interval_ms);
409
409
debug_publisher_->publish <tier4_debug_msgs::msg::Float64Stamped>(
@@ -421,7 +421,7 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::roiCallback(
421
421
}
422
422
}
423
423
// store roi msg if not matched
424
- det_2d.cached_det2d_msgs [timestamp_nsec] = input_roi_msg ;
424
+ det_2d.cached_det2d_msgs [timestamp_nsec] = det2d_msg ;
425
425
}
426
426
427
427
template <class TargetMsg3D , class Obj , class Msg2D >
@@ -441,7 +441,7 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::timer_callback()
441
441
timer_->cancel ();
442
442
if (mutex_cached_msgs_.try_lock ()) {
443
443
// PROCESS: if timeout, postprocess cached msg
444
- if (cached_msg_. second != nullptr ) {
444
+ if (cached_det3d_msg_ptr_ != nullptr ) {
445
445
stop_watch_ptr_->toc (" processing_time" , true );
446
446
exportProcess ();
447
447
}
@@ -450,7 +450,7 @@ void FusionNode<TargetMsg3D, Obj, Msg2D>::timer_callback()
450
450
for (auto & det_2d : det2d_list_) {
451
451
det_2d.is_fused = false ;
452
452
}
453
- cached_msg_. second = nullptr ;
453
+ cached_det3d_msg_ptr_ = nullptr ;
454
454
455
455
mutex_cached_msgs_.unlock ();
456
456
} else {
0 commit comments