Skip to content
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

Added option to change node name for the recorder from the Python API #1180

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ros2bag/ros2bag/verb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def add_arguments(self, parser, cli_name): # noqa: D102
'--use-sim-time', action='store_true', default=False,
help='Use simulation time.'
)
parser.add_argument(
'--node-name', type=str, default='rosbag2_recorder',
help='Specify the recorder node name. Default is rosbag2_recorder.'
)
self._subparser = parser

def main(self, *, args): # noqa: D102
Expand Down Expand Up @@ -259,7 +263,7 @@ def main(self, *, args): # noqa: D102
recorder = Recorder()

try:
recorder.record(storage_options, record_options)
recorder.record(storage_options, record_options, args.node_name)
except KeyboardInterrupt:
pass

Expand Down
9 changes: 6 additions & 3 deletions rosbag2_py/src/rosbag2_py/_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,16 @@ class Recorder

void record(
const rosbag2_storage::StorageOptions & storage_options,
RecordOptions & record_options)
RecordOptions & record_options,
std::string & node_name)
{
if (record_options.rmw_serialization_format.empty()) {
record_options.rmw_serialization_format = std::string(rmw_get_serialization_format());
}

auto writer = rosbag2_transport::ReaderWriterFactory::make_writer(record_options);
auto recorder = std::make_shared<rosbag2_transport::Recorder>(
std::move(writer), storage_options, record_options);
std::move(writer), storage_options, record_options, node_name);
recorder->record();

exec_->add_node(recorder);
Expand Down Expand Up @@ -356,7 +357,9 @@ PYBIND11_MODULE(_transport, m) {

py::class_<rosbag2_py::Recorder>(m, "Recorder")
.def(py::init())
.def("record", &rosbag2_py::Recorder::record)
.def(
"record", &rosbag2_py::Recorder::record, py::arg("storage_options"), py::arg("record_options"),
py::arg("node_name") = "rosbag2_recorder")
.def("cancel", &rosbag2_py::Recorder::cancel)
;

Expand Down