-
Notifications
You must be signed in to change notification settings - Fork 21
Added new topics to record rosbag2 dataset #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ddfc646
ebd231b
10c9ec2
d233cdc
7dc6e73
dabbdea
5663fe4
6dcdd47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,16 @@ physical_ai_server: | |
| - leader_head | ||
| - leader_lift | ||
|
|
||
| rosbag_extra_topic_list: | ||
| - /tf | ||
| - /tf_static | ||
| - /robot_description | ||
| - /zed/zed_node/rgb/camera_info | ||
| - /zed/zed_node/left/camera_info | ||
| - /zed/zed_node/right/camera_info | ||
| - /camera_left/camera_left/color/camera_info | ||
| - /camera_right/camera_right/color/camera_info | ||
|
|
||
|
Comment on lines
33
to
39
|
||
| joint_order: | ||
| leader_left: | ||
| - arm_l_joint1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,18 @@ physical_ai_server: | |||||||||||||
| - leader_lift | ||||||||||||||
| - leader_mobile | ||||||||||||||
|
|
||||||||||||||
| rosbag_extra_topic_list: | ||||||||||||||
| - /tf | ||||||||||||||
| - /tf_static | ||||||||||||||
| - /robot_description | ||||||||||||||
| - /odom | ||||||||||||||
| - /cmd_vel | ||||||||||||||
| - /zed/zed_node/rgb/camera_info | ||||||||||||||
| - /zed/zed_node/left/camera_info | ||||||||||||||
| - /zed/zed_node/right/camera_info | ||||||||||||||
| - /camera_left/camera_left/color/camera_info | ||||||||||||||
| - /camera_right/camera_right/color/camera_info | ||||||||||||||
|
||||||||||||||
| - /zed/zed_node/rgb/camera_info | |
| - /zed/zed_node/left/camera_info | |
| - /zed/zed_node/right/camera_info | |
| - /camera_left/camera_left/color/camera_info | |
| - /camera_right/camera_right/color/camera_info | |
| - /*/camera_info |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions adding /tf_status to the recorded topics, but this topic is not present in any of the configuration files. Only /tf and /tf_static are added. If /tf_status was intended to be recorded, it should be added to the rosbag_extra_topic_list in the configuration files.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,11 @@ physical_ai_server: | |||||||
| joint_list: | ||||||||
| - leader | ||||||||
|
|
||||||||
| rosbag_extra_topic_list: | ||||||||
| - /tf | ||||||||
| - /tf_static | ||||||||
|
||||||||
| - /tf_static | |
| - /tf_static | |
| - /tf_status |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,11 @@ physical_ai_server: | |||||||
| joint_list: | ||||||||
| - leader | ||||||||
|
|
||||||||
| rosbag_extra_topic_list: | ||||||||
| - /tf | ||||||||
| - /tf_static | ||||||||
|
||||||||
| - /tf_static | |
| - /tf_static | |
| - /tf_status |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,11 @@ | |||||
| Changelog for package physical_ai_tools | ||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||||||
|
|
||||||
| 0.7.3 (2026-01-19) | ||||||
| ------------------ | ||||||
| * Modified to record /tf, /robot_description, /camera_info topics in rosbag2 | ||||||
|
||||||
| * Modified to record /tf, /robot_description, /camera_info topics in rosbag2 | |
| * Modified to record /tf, /tf_static, /robot_description, /camera_info topics in rosbag2 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,11 @@ | |||||
| Changelog for package rosbag_recorder | ||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||||||
|
|
||||||
| 0.7.3 (2026-01-19) | ||||||
| ------------------ | ||||||
| * Modified to record /tf, /robot_description, /camera_info topics in rosbag2 | ||||||
|
||||||
| * Modified to record /tf, /robot_description, /camera_info topics in rosbag2 | |
| * Modified to record /tf, /tf_static, /robot_description, /camera_info topics in rosbag2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,12 +58,26 @@ class ServiceBagRecorder : public rclcpp::Node | |
| const std::map<std::string, std::vector<std::string>> & names_and_types); | ||
| void delete_bag_directory(const std::string & bag_uri); | ||
| void create_subscriptions(); | ||
| rclcpp::QoS get_qos_for_topic(const std::string & topic); | ||
| void flush_latched_messages(); | ||
|
|
||
| rclcpp::Service<rosbag_recorder::srv::SendCommand>::SharedPtr send_command_srv_; | ||
|
|
||
| std::vector<rclcpp::GenericSubscription::SharedPtr> subscriptions_; | ||
| std::unique_ptr<rosbag2_cpp::Writer> writer_; | ||
| std::unordered_map<std::string, std::string> type_for_topic_; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve performance by avoiding repeated checks for latched topics, I suggest adding a member to cache the names of latched topics. This cache will be populated once in std::unordered_map<std::string, std::string> type_for_topic_;
std::unordered_set<std::string> latched_topics_; |
||
|
|
||
| // Cache of latched topic names to avoid repeated publisher info lookups | ||
| std::unordered_set<std::string> latched_topics_; | ||
|
||
|
|
||
| // Buffer for latched messages received before recording starts | ||
| struct BufferedMessage | ||
| { | ||
| std::shared_ptr<rclcpp::SerializedMessage> msg; | ||
| rclcpp::Time timestamp; | ||
| }; | ||
| std::unordered_map<std::string, BufferedMessage> latched_message_buffer_; | ||
|
||
|
|
||
| bool is_recording_ {false}; | ||
| std::string current_bag_uri_; | ||
| std::vector<std::string> topics_to_record_ {}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -116,6 +116,8 @@ void ServiceBagRecorder::handle_prepare(const std::vector<std::string> & topics) | |||||||||||||
| type_for_topic_[topic] = type; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Create subscriptions early to avoid data loss | ||||||||||||||
| // Latched messages will be buffered until recording starts | ||||||||||||||
| create_subscriptions(); | ||||||||||||||
|
|
||||||||||||||
| RCLCPP_INFO( | ||||||||||||||
|
|
@@ -180,7 +182,9 @@ void ServiceBagRecorder::handle_start(const std::string & uri) | |||||||||||||
| throw std::runtime_error(std::string("Failed to start recording: ") + e.what()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Set recording flag and flush buffered latched messages | ||||||||||||||
| is_recording_ = true; | ||||||||||||||
| flush_latched_messages(); | ||||||||||||||
|
||||||||||||||
|
|
||||||||||||||
| RCLCPP_INFO( | ||||||||||||||
| this->get_logger(), "Recording started: uri=%s topics=%zu", | ||||||||||||||
|
|
@@ -306,39 +310,109 @@ void ServiceBagRecorder::create_subscriptions() | |||||||||||||
| RCLCPP_INFO(this->get_logger(), "Creating subscriptions"); | ||||||||||||||
|
|
||||||||||||||
| subscriptions_.clear(); | ||||||||||||||
| latched_topics_.clear(); | ||||||||||||||
|
|
||||||||||||||
| // Create generic subscriptions for all topics | ||||||||||||||
| for (const auto & [topic, type] : type_for_topic_) { | ||||||||||||||
| auto options = rclcpp::SubscriptionOptions(); | ||||||||||||||
| auto qos = get_qos_for_topic(topic); | ||||||||||||||
|
|
||||||||||||||
| // Cache whether this topic is latched to avoid repeated publisher lookups | ||||||||||||||
| if (qos.durability() == rclcpp::DurabilityPolicy::TransientLocal) { | ||||||||||||||
| latched_topics_.insert(topic); | ||||||||||||||
| } | ||||||||||||||
|
||||||||||||||
|
|
||||||||||||||
| auto sub = this->create_generic_subscription( | ||||||||||||||
| topic, | ||||||||||||||
| type, | ||||||||||||||
| rclcpp::QoS(100), | ||||||||||||||
| qos, | ||||||||||||||
| [this, topic](std::shared_ptr<rclcpp::SerializedMessage> serialized_msg) { | ||||||||||||||
| this->handle_serialized_message(topic, serialized_msg); | ||||||||||||||
| }, | ||||||||||||||
| options); | ||||||||||||||
| subscriptions_.push_back(sub); | ||||||||||||||
| RCLCPP_INFO( | ||||||||||||||
| this->get_logger(), | ||||||||||||||
| "Subscribed to topic: %s", | ||||||||||||||
| topic.c_str()); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void ServiceBagRecorder::handle_serialized_message( | ||||||||||||||
| const std::string & topic, | ||||||||||||||
| const std::shared_ptr<rclcpp::SerializedMessage> & serialized_msg) | ||||||||||||||
| rclcpp::QoS ServiceBagRecorder::get_qos_for_topic( | ||||||||||||||
| const std::string & topic) | ||||||||||||||
| { | ||||||||||||||
| std::scoped_lock<std::mutex> lock(mutex_); | ||||||||||||||
| // Get publisher info to determine QoS settings | ||||||||||||||
| auto publishers_info = this->get_publishers_info_by_topic(topic); | ||||||||||||||
|
|
||||||||||||||
| if (!publishers_info.empty()) { | ||||||||||||||
| // Check if any publisher uses TRANSIENT_LOCAL durability | ||||||||||||||
| for (const auto & pub_info : publishers_info) { | ||||||||||||||
| if (pub_info.qos_profile().durability() == rclcpp::DurabilityPolicy::TransientLocal) { | ||||||||||||||
| RCLCPP_INFO( | ||||||||||||||
| this->get_logger(), | ||||||||||||||
| "Topic '%s' uses TRANSIENT_LOCAL durability, using matching QoS", | ||||||||||||||
| topic.c_str()); | ||||||||||||||
| // Use smaller queue size (10) for latched topics as they typically publish once | ||||||||||||||
| // and rely on durability rather than queue depth | ||||||||||||||
| return rclcpp::QoS(rclcpp::KeepLast(10)) | ||||||||||||||
|
||||||||||||||
| // Use smaller queue size (10) for latched topics as they typically publish once | |
| // and rely on durability rather than queue depth | |
| return rclcpp::QoS(rclcpp::KeepLast(10)) | |
| // Use minimal queue size (1) for latched topics as they typically publish once | |
| // and rely on durability rather than queue depth | |
| return rclcpp::QoS(rclcpp::KeepLast(1)) |
Outdated
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_qos_for_topic function calls get_publishers_info_by_topic which can be an expensive operation as it queries the ROS graph. This function is called for every topic during subscription creation. While the latched status is cached afterward, the initial call during create_subscriptions could be slow if there are many topics or if publishers haven't fully initialized yet. Consider adding error handling for the case where publisher info is not yet available, or implement a retry mechanism with appropriate logging.
Outdated
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential race condition with is_recording_ flag. The is_recording_ flag is read without atomic guarantees in the callback thread (line 405) while it's written in the service handler thread (line 186). Although both accesses are protected by mutex in their respective contexts, the ordering between setting is_recording_ = true and calling flush_latched_messages() could still lead to a narrow race window where messages arrive between these two operations and are buffered instead of being written directly. Consider setting is_recording_ after flush_latched_messages() completes, or ensure both operations are atomic with respect to message handling.
Outdated
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the most recent latched message is stored per topic. If a latched topic publishes multiple updates before recording starts, earlier messages will be overwritten. Consider whether this is the intended behavior or if all messages should be buffered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog entry is incomplete. It mentions recording /tf, /robot_description, and /camera_info topics but omits /tf_static which is actually added in all configuration files. The changelog should accurately list all topics being added, including /tf_static.