diff --git a/ros2bag/ros2bag/verb/record.py b/ros2bag/ros2bag/verb/record.py index b7cd65173..6582ef172 100644 --- a/ros2bag/ros2bag/verb/record.py +++ b/ros2bag/ros2bag/verb/record.py @@ -46,8 +46,14 @@ def add_arguments(self, parser, cli_name): # noqa: D102 'startup will be recorded') parser.add_argument( '-p', '--polling-interval', type=int, default=100, - help='time in ms to wait between querying available topics for recording. It has no ' - 'effect if --no-discovery is enabled.' + help='time in ms to wait between querying available topics for recording. ' + 'It has no effect if --no-discovery is enabled.' + ) + parser.add_argument( + '-b', '--max-bag-size', type=int, default=0, + help='maximum size in bytes before the bagfile will be split. ' + 'Default it is zero, recording written in single bagfile and splitting ' + 'is disabled.' ) self._subparser = parser @@ -83,7 +89,8 @@ def main(self, *, args): # noqa: D102 node_prefix=NODE_NAME_PREFIX, all=True, no_discovery=args.no_discovery, - polling_interval=args.polling_interval) + polling_interval=args.polling_interval, + max_bagfile_size=args.max_bag_size) elif args.topics and len(args.topics) > 0: # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups # combined with constrained environments (as imposed by colcon test) @@ -99,6 +106,7 @@ def main(self, *, args): # noqa: D102 node_prefix=NODE_NAME_PREFIX, no_discovery=args.no_discovery, polling_interval=args.polling_interval, + max_bagfile_size=args.max_bag_size, topics=args.topics) else: self._subparser.print_help() diff --git a/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp b/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp index ca0f0a3c4..ae601f745 100644 --- a/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp +++ b/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp @@ -36,6 +36,7 @@ rosbag2_transport_record(PyObject * Py_UNUSED(self), PyObject * args, PyObject * "all", "no_discovery", "polling_interval", + "max_bagfile_size", "topics", nullptr}; @@ -46,8 +47,9 @@ rosbag2_transport_record(PyObject * Py_UNUSED(self), PyObject * args, PyObject * bool all = false; bool no_discovery = false; uint64_t polling_interval_ms = 100; + unsigned long long max_bagfile_size = 0; // NOLINT PyObject * topics = nullptr; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssss|bbKO", const_cast(kwlist), + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssss|bbKKO", const_cast(kwlist), &uri, &storage_id, &serilization_format, @@ -55,6 +57,7 @@ rosbag2_transport_record(PyObject * Py_UNUSED(self), PyObject * args, PyObject * &all, &no_discovery, &polling_interval_ms, + &max_bagfile_size, &topics)) { return nullptr; @@ -62,6 +65,7 @@ rosbag2_transport_record(PyObject * Py_UNUSED(self), PyObject * args, PyObject * storage_options.uri = std::string(uri); storage_options.storage_id = std::string(storage_id); + storage_options.max_bagfile_size = (uint64_t) max_bagfile_size; record_options.all = all; record_options.is_discovery_disabled = no_discovery; record_options.topic_polling_interval = std::chrono::milliseconds(polling_interval_ms);