From 7c0a5fb08b97fdce16ed0952955ec57e25df5db0 Mon Sep 17 00:00:00 2001 From: Fleury Date: Mon, 9 Mar 2026 10:53:18 +0100 Subject: [PATCH 1/3] Rename example recorder files to 'writer'/'rewriter' (#2347) Signed-off-by: Fleury --- rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt | 12 ++++++------ ...ed_bag_recorder.cpp => compressed_bag_writer.cpp} | 10 +++++----- ...simple_bag_recorder.cpp => simple_bag_writer.cpp} | 10 +++++----- ...ssed_bag_recorder.py => compressed_bag_writer.py} | 4 ++-- .../{simple_bag_recorder.py => simple_bag_writer.py} | 8 ++++---- rosbag2_examples/rosbag2_examples_py/setup.py | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) rename rosbag2_examples/rosbag2_examples_cpp/src/{compressed_bag_recorder.cpp => compressed_bag_writer.cpp} (88%) rename rosbag2_examples/rosbag2_examples_cpp/src/{simple_bag_recorder.cpp => simple_bag_writer.cpp} (85%) rename rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/{compressed_bag_recorder.py => compressed_bag_writer.py} (96%) rename rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/{simple_bag_recorder.py => simple_bag_writer.py} (92%) diff --git a/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt b/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt index f90e99b3e0..463490ea1c 100644 --- a/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt +++ b/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt @@ -24,20 +24,20 @@ find_package(rosbag2_cpp REQUIRED) find_package(rosbag2_transport REQUIRED) find_package(example_interfaces REQUIRED) -add_executable(simple_bag_recorder src/simple_bag_recorder.cpp) -target_link_libraries(simple_bag_recorder +add_executable(simple_bag_writer src/simple_bag_writer.cpp) +target_link_libraries(simple_bag_writer rclcpp::rclcpp rosbag2_cpp::rosbag2_cpp ${example_interfaces_TARGETS} ) install(TARGETS - simple_bag_recorder + simple_bag_writer DESTINATION lib/${PROJECT_NAME} ) -add_executable(compressed_bag_recorder src/compressed_bag_recorder.cpp) -target_link_libraries(compressed_bag_recorder +add_executable(compressed_bag_writer.cpp src/compressed_bag_writer.cpp) +target_link_libraries(compressed_bag_writer.cpp rclcpp::rclcpp rosbag2_cpp::rosbag2_cpp rosbag2_compression::rosbag2_compression @@ -45,7 +45,7 @@ target_link_libraries(compressed_bag_recorder ) install(TARGETS - compressed_bag_recorder + compressed_bag_writer.cpp DESTINATION lib/${PROJECT_NAME} ) diff --git a/rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_recorder.cpp b/rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_writer.cpp similarity index 88% rename from rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_recorder.cpp rename to rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_writer.cpp index b95bbd0030..42fbaf04d5 100644 --- a/rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_recorder.cpp +++ b/rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_writer.cpp @@ -24,10 +24,10 @@ using std::placeholders::_1; -class CompressedBagRecorder : public rclcpp::Node { +class CompressedBagWriter : public rclcpp::Node { public: - CompressedBagRecorder() - : Node("compressed_bag_recorder") + CompressedBagWriter() + : Node("compressed_bag_writer") { rosbag2_compression::CompressionOptions compression_options; @@ -41,7 +41,7 @@ class CompressedBagRecorder : public rclcpp::Node { writer_->open("my_bag"); subscription_ = this->create_subscription( - "chatter", 10, std::bind(&CompressedBagRecorder::topic_callback, this, _1)); + "chatter", 10, std::bind(&CompressedBagWriter::topic_callback, this, _1)); } private: @@ -59,7 +59,7 @@ class CompressedBagRecorder : public rclcpp::Node { int main(int argc, char *argv[]) { rclcpp::init(argc, argv); - rclcpp::spin(std::make_shared()); + rclcpp::spin(std::make_shared()); rclcpp::shutdown(); return 0; } diff --git a/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_recorder.cpp b/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_writer.cpp similarity index 85% rename from rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_recorder.cpp rename to rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_writer.cpp index 2e04c96912..c20e227734 100644 --- a/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_recorder.cpp +++ b/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_writer.cpp @@ -21,18 +21,18 @@ using std::placeholders::_1; -class SimpleBagRecorder : public rclcpp::Node +class SimpleBagWriter : public rclcpp::Node { public: - SimpleBagRecorder() - : Node("simple_bag_recorder") + SimpleBagWriter() + : Node("simple_bag_writer") { writer_ = std::make_unique(); writer_->open("my_bag"); subscription_ = create_subscription( - "chatter", 10, std::bind(&SimpleBagRecorder::topic_callback, this, _1)); + "chatter", 10, std::bind(&SimpleBagWriter::topic_callback, this, _1)); } private: @@ -49,7 +49,7 @@ class SimpleBagRecorder : public rclcpp::Node int main(int argc, char * argv[]) { rclcpp::init(argc, argv); - rclcpp::spin(std::make_shared()); + rclcpp::spin(std::make_shared()); rclcpp::shutdown(); return 0; } diff --git a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_recorder.py b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_writer.py similarity index 96% rename from rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_recorder.py rename to rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_writer.py index a25707afed..b4c38787f3 100644 --- a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_recorder.py +++ b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_writer.py @@ -20,7 +20,7 @@ from std_msgs.msg import String -class CompressedBagRecorder(Node): +class CompressedBagWriter(Node): def __init__(self): super().__init__('compressed_bag_recorder') @@ -61,7 +61,7 @@ def topic_callback(self, msg): def main(args=None): try: with rclpy.init(args=args): - cbr = CompressedBagRecorder() + cbr = CompressedBagWriter() rclpy.spin(cbr) except (KeyboardInterrupt, ExternalShutdownException): pass diff --git a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_recorder.py b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_writer.py similarity index 92% rename from rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_recorder.py rename to rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_writer.py index b92b23a4eb..1959c179eb 100644 --- a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_recorder.py +++ b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_writer.py @@ -19,10 +19,10 @@ from std_msgs.msg import String -class SimpleBagRecorder(Node): +class SimpleBagWriter(Node): def __init__(self): - super().__init__('simple_bag_recorder') + super().__init__('simple_bag_writer') self.writer = rosbag2_py.SequentialWriter() storage_options = rosbag2_py.StorageOptions( @@ -55,8 +55,8 @@ def topic_callback(self, msg): def main(args=None): try: with rclpy.init(args=args): - sbr = SimpleBagRecorder() - rclpy.spin(sbr) + sbw = SimpleBagWriter() + rclpy.spin(sbw) except (KeyboardInterrupt, ExternalShutdownException): pass diff --git a/rosbag2_examples/rosbag2_examples_py/setup.py b/rosbag2_examples/rosbag2_examples_py/setup.py index 8f438ca8e2..ed4e018d49 100644 --- a/rosbag2_examples/rosbag2_examples_py/setup.py +++ b/rosbag2_examples/rosbag2_examples_py/setup.py @@ -25,11 +25,11 @@ entry_points={ 'console_scripts': [ 'rosbag2csv = rosbag2_examples_py.rosbag2csv:main', - 'simple_bag_recorder = rosbag2_examples_py.simple_bag_recorder:main', + 'simple_bag_writer = rosbag2_examples_py.simple_bag_writer:main', 'simple_bag_reader = rosbag2_examples_py.simple_bag_reader:main', 'data_generator_node = rosbag2_examples_py.data_generator_node:main', 'data_generator_executable = rosbag2_examples_py.data_generator_executable:main', - 'compressed_bag_recorder = rosbag2_examples_py.compressed_bag_recorder:main', + 'compressed_bag_writer = rosbag2_examples_py.compressed_bag_writer:main', ], }, ) From 746676bc44f799629ada7c3d31fa11d09e311bdb Mon Sep 17 00:00:00 2001 From: Fleury Date: Mon, 9 Mar 2026 16:24:33 +0100 Subject: [PATCH 2/3] Add simple bag recorder example (#2347) Signed-off-by: Fleury --- .../rosbag2_examples_cpp/CMakeLists.txt | 10 ++++ .../src/simple_bag_recorder.cpp | 38 +++++++++++++++ .../simple_bag_recorder.py | 46 +++++++++++++++++++ rosbag2_examples/rosbag2_examples_py/setup.py | 1 + 4 files changed, 95 insertions(+) create mode 100644 rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_recorder.cpp create mode 100644 rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_recorder.py diff --git a/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt b/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt index 463490ea1c..267603959a 100644 --- a/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt +++ b/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt @@ -24,6 +24,16 @@ find_package(rosbag2_cpp REQUIRED) find_package(rosbag2_transport REQUIRED) find_package(example_interfaces REQUIRED) +add_executable(simple_bag_recorder src/simple_bag_recorder.cpp) +target_link_libraries(simple_bag_recorder + rosbag2_transport::rosbag2_transport +) + +install(TARGETS + simple_bag_recorder + DESTINATION lib/${PROJECT_NAME} +) + add_executable(simple_bag_writer src/simple_bag_writer.cpp) target_link_libraries(simple_bag_writer rclcpp::rclcpp diff --git a/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_recorder.cpp b/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_recorder.cpp new file mode 100644 index 0000000000..3aa91180f7 --- /dev/null +++ b/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_recorder.cpp @@ -0,0 +1,38 @@ +// Copyright 2026 Open Source Robotics Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "rosbag2_transport/recorder.hpp" + +int main(int argc, char *argv[]) +{ + rclcpp::init(argc, argv); + + rosbag2_storage::StorageOptions storage_options; + storage_options.uri = "my_bag"; + + rosbag2_transport::RecordOptions record_options; + record_options.all_topics = true; + record_options.rmw_serialization_format = "cdr"; + + auto writer = std::make_unique(); + auto recorder = std::make_shared( + std::move(writer), storage_options, record_options); + + recorder->record(); + rclcpp::spin(recorder); + + recorder->stop(); + rclcpp::shutdown(); + return 0; +} diff --git a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_recorder.py b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_recorder.py new file mode 100644 index 0000000000..4b06c5877c --- /dev/null +++ b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_recorder.py @@ -0,0 +1,46 @@ +# Copyright 2026 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import rclpy +from rclpy.executors import ExternalShutdownException +import rosbag2_py + + +def main(args=None): + rclpy.init(args=args) + + storage_options = rosbag2_py.StorageOptions(uri='my_bag') + + record_options = rosbag2_py.RecordOptions() + record_options.all_topics = True + record_options.is_discovery_disabled = False + record_options.rmw_serialization_format = 'cdr' + + recorder = rosbag2_py.Recorder( + storage_options, + record_options, + 'info', + 'simple_recorder_demo') + + recorder.start_spin() + recorder.record() + + try: + while rclpy.ok(): + pass + except (KeyboardInterrupt, ExternalShutdownException): + recorder.stop_spin() + + +if __name__ == '__main__': + main() diff --git a/rosbag2_examples/rosbag2_examples_py/setup.py b/rosbag2_examples/rosbag2_examples_py/setup.py index ed4e018d49..e4d3f1b039 100644 --- a/rosbag2_examples/rosbag2_examples_py/setup.py +++ b/rosbag2_examples/rosbag2_examples_py/setup.py @@ -27,6 +27,7 @@ 'rosbag2csv = rosbag2_examples_py.rosbag2csv:main', 'simple_bag_writer = rosbag2_examples_py.simple_bag_writer:main', 'simple_bag_reader = rosbag2_examples_py.simple_bag_reader:main', + 'simple_bag_recorder = rosbag2_examples_py.simple_bag_recorder:main', 'data_generator_node = rosbag2_examples_py.data_generator_node:main', 'data_generator_executable = rosbag2_examples_py.data_generator_executable:main', 'compressed_bag_writer = rosbag2_examples_py.compressed_bag_writer:main', From 172ba285f5b166a0a160d56941fc9573e03bf091 Mon Sep 17 00:00:00 2001 From: Fleury Date: Tue, 10 Mar 2026 11:47:42 +0100 Subject: [PATCH 3/3] Add compressed bag recorder example (#2347) Signed-off-by: Fleury --- .../rosbag2_examples_cpp/CMakeLists.txt | 10 ++++ .../src/compressed_bag_recorder.cpp | 42 ++++++++++++++++ .../compressed_bag_recorder.py | 48 +++++++++++++++++++ rosbag2_examples/rosbag2_examples_py/setup.py | 1 + 4 files changed, 101 insertions(+) create mode 100644 rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_recorder.cpp create mode 100644 rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_recorder.py diff --git a/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt b/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt index 267603959a..c9ac4cafd5 100644 --- a/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt +++ b/rosbag2_examples/rosbag2_examples_cpp/CMakeLists.txt @@ -24,6 +24,16 @@ find_package(rosbag2_cpp REQUIRED) find_package(rosbag2_transport REQUIRED) find_package(example_interfaces REQUIRED) +add_executable(compressed_bag_recorder src/compressed_bag_recorder.cpp) +target_link_libraries(compressed_bag_recorder + rosbag2_transport::rosbag2_transport +) + +install(TARGETS + compressed_bag_recorder + DESTINATION lib/${PROJECT_NAME} +) + add_executable(simple_bag_recorder src/simple_bag_recorder.cpp) target_link_libraries(simple_bag_recorder rosbag2_transport::rosbag2_transport diff --git a/rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_recorder.cpp b/rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_recorder.cpp new file mode 100644 index 0000000000..044301f96f --- /dev/null +++ b/rosbag2_examples/rosbag2_examples_cpp/src/compressed_bag_recorder.cpp @@ -0,0 +1,42 @@ +// Copyright 2026 Open Source Robotics Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "rosbag2_transport/reader_writer_factory.hpp" +#include "rosbag2_transport/recorder.hpp" + +int main(int argc, char *argv[]) +{ + rclcpp::init(argc, argv); + + rosbag2_storage::StorageOptions storage_options; + storage_options.uri = "my_bag"; + + rosbag2_transport::RecordOptions record_options; + record_options.all_topics = true; + record_options.rmw_serialization_format = "cdr"; + record_options.compression_format = "zstd"; + record_options.compression_mode = "file"; + + // Calling ReaderWriterFactory creates a writer with compression parameters + auto writer = rosbag2_transport::ReaderWriterFactory::make_writer(record_options); + auto recorder = std::make_shared( + std::move(writer), storage_options, record_options); + + recorder->record(); + rclcpp::spin(recorder); + + recorder->stop(); + rclcpp::shutdown(); + return 0; +} diff --git a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_recorder.py b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_recorder.py new file mode 100644 index 0000000000..65f64d8649 --- /dev/null +++ b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/compressed_bag_recorder.py @@ -0,0 +1,48 @@ +# Copyright 2026 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import rclpy +from rclpy.executors import ExternalShutdownException +import rosbag2_py + + +def main(args=None): + rclpy.init(args=args) + + storage_options = rosbag2_py.StorageOptions(uri='my_bag') + + record_options = rosbag2_py.RecordOptions() + record_options.all_topics = True + record_options.is_discovery_disabled = False + record_options.rmw_serialization_format = 'cdr' + record_options.compression_format = 'zstd' + record_options.compression_mode = 'file' + + recorder = rosbag2_py.Recorder( + storage_options, + record_options, + 'info', + 'compressed_recorder_demo') + + recorder.start_spin() + recorder.record() + + try: + while (rclpy.ok()): + pass + except (KeyboardInterrupt, ExternalShutdownException): + recorder.stop_spin() + + +if __name__ == '__main__': + main() diff --git a/rosbag2_examples/rosbag2_examples_py/setup.py b/rosbag2_examples/rosbag2_examples_py/setup.py index e4d3f1b039..2ee62b3453 100644 --- a/rosbag2_examples/rosbag2_examples_py/setup.py +++ b/rosbag2_examples/rosbag2_examples_py/setup.py @@ -28,6 +28,7 @@ 'simple_bag_writer = rosbag2_examples_py.simple_bag_writer:main', 'simple_bag_reader = rosbag2_examples_py.simple_bag_reader:main', 'simple_bag_recorder = rosbag2_examples_py.simple_bag_recorder:main', + 'compressed_bag_recorder = rosbag2_examples_py.compressed_bag_recorder:main', 'data_generator_node = rosbag2_examples_py.data_generator_node:main', 'data_generator_executable = rosbag2_examples_py.data_generator_executable:main', 'compressed_bag_writer = rosbag2_examples_py.compressed_bag_writer:main',