@@ -304,9 +304,8 @@ void TopicPublisher::init_rosbag_publishers()
304
304
if (it != topics.end ()) {
305
305
return string_to_publisher_message_type (
306
306
it->topic_metadata .type ); // Return the message type if found
307
- } else {
308
- return PublisherMessageType::UNKNOWN; //
309
307
}
308
+ return PublisherMessageType::UNKNOWN;
310
309
};
311
310
312
311
// Collect timestamps for each topic to set the frequency of the publishers
@@ -349,25 +348,24 @@ void TopicPublisher::init_rosbag_publishers()
349
348
350
349
const auto & topics = reader.get_metadata ().topics_with_message_count ;
351
350
352
- auto getMessageTypeForTopic = [&topics, &string_to_publisher_message_type](
353
- const std::string & topicName) -> PublisherMessageType {
351
+ auto get_message_type_for_topic = [&topics, &string_to_publisher_message_type](
352
+ const std::string & topicName) -> PublisherMessageType {
354
353
auto it = std::find_if (topics.begin (), topics.end (), [&topicName](const auto & topic) {
355
354
return topic.topic_metadata .name == topicName;
356
355
});
357
356
358
357
if (it != topics.end ()) {
359
358
return string_to_publisher_message_type (
360
359
it->topic_metadata .type ); // Return the message type if found
361
- } else {
362
- return PublisherMessageType::UNKNOWN;
363
360
}
361
+ return PublisherMessageType::UNKNOWN;
364
362
};
365
363
366
364
while (reader.has_next ()) {
367
365
auto bag_message = reader.read_next ();
368
366
const auto current_topic = bag_message->topic_name ;
369
367
370
- const auto message_type = getMessageTypeForTopic (current_topic);
368
+ const auto message_type = get_message_type_for_topic (current_topic);
371
369
372
370
if (message_type == PublisherMessageType::UNKNOWN) {
373
371
continue ;
@@ -869,10 +867,10 @@ void TopicPublisher::set_period_to_variable_map(
869
867
auto period_ms = std::chrono::duration_cast<std::chrono::milliseconds>(total_duration_ns) /
870
868
(timestamps_tmp.size () - 1 );
871
869
872
- PublisherVariablesVariant & publisherVar = topic_publisher_map_[topic_name];
870
+ PublisherVariablesVariant & publisher_variant = topic_publisher_map_[topic_name];
873
871
PublisherVarAccessor accessor;
874
872
875
- std::visit ([&](auto & var) { accessor.set_period (var, period_ms); }, publisherVar );
873
+ std::visit ([&](auto & var) { accessor.set_period (var, period_ms); }, publisher_variant );
876
874
}
877
875
}
878
876
}
@@ -973,24 +971,21 @@ bool TopicPublisher::set_publishers_and_timers_to_variable_map()
973
971
// Create a timer to create phase difference bw timers which will be created for each lidar
974
972
// topics
975
973
auto one_shot_timer = node_->create_wall_timer (phase_dif, [this , period_pointcloud_ns]() {
976
- for (const auto & [lidar_name, publisher_var_pair] : lidar_pub_variable_pair_map_) {
974
+ for (const auto & publisher_var_pair : lidar_pub_variable_pair_map_) {
975
+ const auto & lidar_name = publisher_var_pair.first ;
976
+ const auto & publisher_var = publisher_var_pair.second ;
977
977
if (
978
978
pointcloud_publish_timers_map_.find (lidar_name) == pointcloud_publish_timers_map_.end ()) {
979
- // Create the periodic timer
980
- auto periodic_timer =
981
- node_->create_wall_timer (period_pointcloud_ns, [this , publisher_var_pair]() {
982
- this ->pointcloud_messages_async_publisher (publisher_var_pair);
983
- });
984
- // Store the periodic timer to keep it alive
979
+ auto periodic_timer = node_->create_wall_timer (
980
+ period_pointcloud_ns,
981
+ [this , publisher_var]() { this ->pointcloud_messages_async_publisher (publisher_var); });
985
982
pointcloud_publish_timers_map_[lidar_name] = periodic_timer;
986
983
return ;
987
984
}
988
985
}
989
- // close the timer
990
986
one_shot_timer_shared_ptr_->cancel ();
991
987
});
992
-
993
- one_shot_timer_shared_ptr_ = one_shot_timer; // Store a weak pointer to the timer
988
+ one_shot_timer_shared_ptr_ = one_shot_timer;
994
989
}
995
990
return true ;
996
991
}
@@ -1010,7 +1005,8 @@ bool TopicPublisher::check_publishers_initialized_correctly()
1010
1005
node_->get_logger (),
1011
1006
" Empty area message couldn't found in the topic named: " << topic_name);
1012
1007
return false ;
1013
- } else if (!object_spawned_message) {
1008
+ }
1009
+ if (!object_spawned_message) {
1014
1010
RCLCPP_ERROR_STREAM (
1015
1011
node_->get_logger (),
1016
1012
" Object spawned message couldn't found in the topic named: " << topic_name);
0 commit comments