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

Consistent node naming across ros2cli tools #60

Merged
merged 4 commits into from
Feb 12, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion ros2bag/ros2bag/verb/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os

from ros2bag.verb import VerbExtension

from ros2cli.node import NODE_NAME_PREFIX
from rosbag2_transport import rosbag2_transport_py


Expand All @@ -42,4 +42,5 @@ def main(self, *, args): # noqa: D102
rosbag2_transport_py.play(
uri=bag_file,
storage_id=args.storage,
node_prefix=NODE_NAME_PREFIX,
read_ahead_queue_size=args.read_ahead_queue_size)
4 changes: 3 additions & 1 deletion ros2bag/ros2bag/verb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from ros2cli.node.strategy import NodeStrategy
from ros2cli.node.strategy import add_arguments

from ros2cli.node import NODE_NAME_PREFIX
from rosbag2_transport import rosbag2_transport_py


Expand Down Expand Up @@ -75,6 +75,7 @@ def main(self, *, args): # noqa: D102
uri=uri,
storage_id=args.storage,
serialization_format=args.serialization_format,
node_prefix=NODE_NAME_PREFIX,
all=True,
no_discovery=args.no_discovery,
polling_interval=args.polling_interval)
Expand All @@ -83,6 +84,7 @@ def main(self, *, args): # noqa: D102
uri=uri,
storage_id=args.storage,
serialization_format=args.serialization_format,
node_prefix=NODE_NAME_PREFIX,
no_discovery=args.no_discovery,
polling_interval=args.polling_interval,
topics=args.topics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define ROSBAG2_TRANSPORT__PLAY_OPTIONS_HPP_

#include <cstddef>
#include <string>

namespace rosbag2_transport
{
Expand All @@ -24,6 +25,7 @@ struct PlayOptions
{
public:
size_t read_ahead_queue_size;
std::string node_prefix = "";
};

} // namespace rosbag2_transport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct RecordOptions
std::vector<std::string> topics;
std::string rmw_serialization_format;
std::chrono::milliseconds topic_polling_interval;
std::string node_prefix = "";
};

} // namespace rosbag2_transport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Rosbag2Transport
void print_bag_info(const std::string & uri, const std::string & storage_id);

private:
std::shared_ptr<Rosbag2Node> setup_node();
std::shared_ptr<Rosbag2Node> setup_node(std::string node_prefix = "");

std::shared_ptr<rosbag2::SequentialReader> reader_;
std::shared_ptr<rosbag2::Writer> writer_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void Rosbag2Transport::record(
writer_->open(
storage_options, {rmw_get_serialization_format(), record_options.rmw_serialization_format});

auto transport_node = setup_node();
auto transport_node = setup_node(record_options.node_prefix);

Recorder recorder(writer_, transport_node);
recorder.record(record_options);
Expand All @@ -76,10 +76,10 @@ void Rosbag2Transport::record(
}
}

std::shared_ptr<Rosbag2Node> Rosbag2Transport::setup_node()
std::shared_ptr<Rosbag2Node> Rosbag2Transport::setup_node(std::string node_prefix)
{
if (!transport_node_) {
transport_node_ = std::make_shared<Rosbag2Node>("rosbag2");
transport_node_ = std::make_shared<Rosbag2Node>(node_prefix + "_rosbag2");
}
return transport_node_;
}
Expand All @@ -90,7 +90,7 @@ void Rosbag2Transport::play(
try {
reader_->open(storage_options, {"", rmw_get_serialization_format()});

auto transport_node = setup_node();
auto transport_node = setup_node(play_options.node_prefix);

Player player(reader_, transport_node);
player.play(play_options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rosbag2_transport_record(PyObject * Py_UNUSED(self), PyObject * args, PyObject *
"uri",
"storage_id",
"serialization_format",
"node_prefix",
"all",
"no_discovery",
"polling_interval",
Expand All @@ -41,14 +42,16 @@ rosbag2_transport_record(PyObject * Py_UNUSED(self), PyObject * args, PyObject *
char * uri = nullptr;
char * storage_id = nullptr;
char * serilization_format = nullptr;
char * node_prefix = nullptr;
bool all = false;
bool no_discovery = false;
uint64_t polling_interval_ms = 100;
PyObject * topics = nullptr;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|bbKO", const_cast<char **>(kwlist),
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssss|bbKO", const_cast<char **>(kwlist),
&uri,
&storage_id,
&serilization_format,
&node_prefix,
&all,
&no_discovery,
&polling_interval_ms,
Expand All @@ -62,6 +65,7 @@ rosbag2_transport_record(PyObject * Py_UNUSED(self), PyObject * args, PyObject *
record_options.all = all;
record_options.is_discovery_disabled = no_discovery;
record_options.topic_polling_interval = std::chrono::milliseconds(polling_interval_ms);
record_options.node_prefix = std::string(node_prefix);

if (topics) {
PyObject * topic_iterator = PyObject_GetIter(topics);
Expand Down Expand Up @@ -93,14 +97,22 @@ rosbag2_transport_play(PyObject * Py_UNUSED(self), PyObject * args, PyObject * k
rosbag2_transport::PlayOptions play_options{};
rosbag2_transport::StorageOptions storage_options{};

static const char * kwlist[] = {"uri", "storage_id", "read_ahead_queue_size", nullptr};
static const char * kwlist[] = {
"uri",
"storage_id",
"node_prefix",
"read_ahead_queue_size",
nullptr
};

char * uri;
char * storage_id;
char * node_prefix;
size_t read_ahead_queue_size;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss|k", const_cast<char **>(kwlist),
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|k", const_cast<char **>(kwlist),
&uri,
&storage_id,
&node_prefix,
&read_ahead_queue_size))
{
return nullptr;
Expand All @@ -109,6 +121,7 @@ rosbag2_transport_play(PyObject * Py_UNUSED(self), PyObject * args, PyObject * k
storage_options.uri = std::string(uri);
storage_options.storage_id = std::string(storage_id);

play_options.node_prefix = std::string(node_prefix);
play_options.read_ahead_queue_size = read_ahead_queue_size;

rosbag2_transport::Rosbag2Transport transport;
Expand Down