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

properly remap compressed topics #851

Merged
merged 3 commits into from
Jan 18, 2024
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 image_publisher/src/image_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ using namespace std::chrono_literals;
ImagePublisher::ImagePublisher(const rclcpp::NodeOptions & options)
: rclcpp::Node("ImagePublisher", options)
{
pub_ = image_transport::create_camera_publisher(this, "image_raw");
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
auto node_base = this->get_node_base_interface();
std::string topic_name = node_base->resolve_topic_or_service_name("image_raw", false);
pub_ = image_transport::create_camera_publisher(this, topic_name);

flip_horizontal_ = this->declare_parameter("flip_horizontal", false);
flip_vertical_ = this->declare_parameter("flip_vertical", false);
Expand Down
10 changes: 7 additions & 3 deletions image_view/src/disparity_view_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ namespace image_view
DisparityViewNode::DisparityViewNode(const rclcpp::NodeOptions & options)
: rclcpp::Node("disparity_view_node", options)
{
std::string topic =
rclcpp::expand_topic_or_service_name("image", this->get_name(), this->get_namespace());
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
auto node_base = this->get_node_base_interface();
std::string topic = node_base->resolve_topic_or_service_name("image", false);

if (topic == "image") {
auto topics = this->get_topic_names_and_types();

if (topics.find(topic) == topics.end()) {
RCLCPP_WARN(
this->get_logger(), "Topic 'image' has not been remapped! Typical command-line usage:\n"
"\t$ ros2 run image_view disparity_view --ros-args -r image:=<disparity image topic>");
Expand Down
8 changes: 5 additions & 3 deletions image_view/src/extract_images_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ ExtractImagesNode::ExtractImagesNode(const rclcpp::NodeOptions & options)
: rclcpp::Node("extract_images_node", options),
filename_format_(""), count_(0), _time(this->now())
{
auto topic = rclcpp::expand_topic_or_service_name(
"image", this->get_name(), this->get_namespace());
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
auto node_base = this->get_node_base_interface();
std::string topic = node_base->resolve_topic_or_service_name("image", false);

this->declare_parameter<std::string>("transport", std::string("raw"));
std::string transport = this->get_parameter("transport").as_string();
Expand All @@ -83,7 +85,7 @@ ExtractImagesNode::ExtractImagesNode(const rclcpp::NodeOptions & options)

auto topics = this->get_topic_names_and_types();

if (topics.find(topic) != topics.end()) {
if (topics.find(topic) == topics.end()) {
RCLCPP_WARN(
this->get_logger(), "extract_images: image has not been remapped! "
"Typical command-line usage:\n\t$ ros2 run image_view extract_images "
Expand Down
6 changes: 4 additions & 2 deletions image_view/src/image_saver_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ namespace image_view
ImageSaverNode::ImageSaverNode(const rclcpp::NodeOptions & options)
: rclcpp::Node("image_saver_node", options)
{
auto topic = rclcpp::expand_topic_or_service_name(
"image", this->get_name(), this->get_namespace());
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
auto node_base = this->get_node_base_interface();
std::string topic = node_base->resolve_topic_or_service_name("image", false);

// Useful when CameraInfo is being published
cam_sub_ = image_transport::create_camera_subscription(
Expand Down
8 changes: 5 additions & 3 deletions image_view/src/image_view_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ ImageViewNode::ImageViewNode(const rclcpp::NodeOptions & options)
auto transport = this->declare_parameter("image_transport", "raw");
RCLCPP_INFO(this->get_logger(), "Using transport \"%s\"", transport.c_str());

std::string topic = rclcpp::expand_topic_or_service_name(
"image", this->get_name(), this->get_namespace());
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
auto node_base = this->get_node_base_interface();
std::string topic = node_base->resolve_topic_or_service_name("image", false);

image_transport::TransportHints hints(this, transport);
pub_ = this->create_publisher<sensor_msgs::msg::Image>("output", 1);
Expand All @@ -118,7 +120,7 @@ ImageViewNode::ImageViewNode(const rclcpp::NodeOptions & options)

auto topics = this->get_topic_names_and_types();

if (topics.find(topic) != topics.end()) {
if (topics.find(topic) == topics.end()) {
RCLCPP_WARN(
this->get_logger(), "Topic 'image' has not been remapped! "
"Typical command-line usage:\n"
Expand Down
7 changes: 4 additions & 3 deletions image_view/src/stereo_view_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ StereoViewNode::StereoViewNode(const rclcpp::NodeOptions & options)
cv::setMouseCallback("right", &StereoViewNode::mouseCb, this);
cv::setMouseCallback("disparity", &StereoViewNode::mouseCb, this);

// Resolve topic names
std::string stereo_ns = rclcpp::expand_topic_or_service_name(
"stereo", this->get_name(), this->get_namespace());
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
auto node_base = this->get_node_base_interface();
std::string stereo_ns = node_base->resolve_topic_or_service_name("stereo", false);

std::string left_topic = rclcpp::expand_topic_or_service_name(
stereo_ns + "/left" + rclcpp::expand_topic_or_service_name(
Expand Down
7 changes: 5 additions & 2 deletions image_view/src/video_recorder_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ VideoRecorderNode::VideoRecorderNode(const rclcpp::NodeOptions & options)
rclcpp::shutdown();
}

auto topic = rclcpp::expand_topic_or_service_name(
"image", this->get_name(), this->get_namespace());
// For compressed topics to remap appropriately, we need to pass a
// fully expanded and remapped topic name to image_transport
auto node_base = this->get_node_base_interface();
std::string topic = node_base->resolve_topic_or_service_name("image", false);

sub_image = image_transport::create_subscription(
this, topic, std::bind(&VideoRecorderNode::callback, this, std::placeholders::_1), "raw");

Expand Down
Loading