0
$\begingroup$

Rosanswers logo

Folks,

I am subscribing to a compressed image published (or republished) by image_proc (it takes my rgb_raw, and publishes rectified rgb and mono images, including compressed versions). But when I subscribe to the compressed images (rgb or mono), I get these messages:

[ERROR] [1479358743.735774954]: Tried to advertise a service that is already advertised in this node [/v_control_node/compressed/set_parameters]

This is my subscriber:

camera_track_sub_ = it_.subscribeCamera("/camera/rgb/image_rect", 2,
&MyNodeClass::ImageCb, this,
image_transport::TransportHints("compressed"));
// I assume TransportHints converts "/camera/rgb/image_rect" to "/camera/rgb/image_rect/compressed"

I have ROS indigo, and Ubuntu 14.04.


Originally posted by Pototo on ROS Answers with karma: 803 on 2016-11-17

Post score: 0


Original comments

Comment by NEngelhard on 2016-11-17:
How do you subscribe?

Comment by Pototo on 2016-11-17:
#include <sensor_msgs/CompressedImage.h>
// inside my class
ros::NodeHandle nh_;
image_transport::ImageTransport it_;
image_transport::CameraSubscriber camera_track_sub_; /**< subscriber for the camera info and the image info. */

Comment by Pototo on 2016-11-17:
// Then, on my class as well
public:
MyNodeClass(int32_t id)
: it_(nh_), id_(id)

Comment by NEngelhard on 2016-11-17:
Please edit your question. And you only show the declaration for the subscriber, but no use of it.

Comment by Pototo on 2016-11-17:
camera_track_sub_ = it_.subscribeCamera("/camera/rgb/image_rect", 2,
&MyNodeClass::ImageCb, this,
image_transport::TransportHints("compressed"));
// I assume TransportHints converts "/camera/rgb/image_rect" to "/camera/rgb/image_rect/compressed"

Comment by Pototo on 2016-11-17:
After the subscriber is enabled, the callback grabs that rectified mono image message, cv_bridge converts it into sensor_msgs::image_encodings::MONO8, then I to my analysis. I don't re-publish the image at all.

Comment by NEngelhard on 2016-11-17:
Can you please add the code to the question? It's hard to read it in several parts in the comments.

Comment by Pototo on 2016-11-17:
I found the error problem. See answer below. Print Statements helped me see it

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The problem is that I shut down my subscriber when I don't need it, and re-subscribe again when I need it. But if the subscriber is already initialized, then I get the error if I call it again. I added a boolean to check if it is already initialized (if you know a image_transport method that checks for this, or how to access the private variable impl_, then let me know):

if (image_analyze == CMDTYPE_START)
{
  /* use boolean to avoid re-initializing subscriber. */
  if (already_started_ == false)
  {
    already_started_ = true;
    camera_track_sub_ = it_.subscribeCamera("/camera/rgb/image_rect", 2,
    &MyNodeClass::ImageCb, this,
    image_transport::TransportHints("compressed"));
  }
}
else if (image_analyze == CMDTYPE_STOP)
{
  already_started_ = false;
  /// shutdown already checks if the subscriber is valid.
  /// so, no need to check if it has already been shutdown
  camera_track_sub_.shutdown();
}

Originally posted by Pototo with karma: 803 on 2016-11-17

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Pototo on 2016-11-17:
How come this not happened for the non-rgb-compressed topics (such as regular rgb, compressedDepth, and non-image related topics)? I guess they forgot to add code to check rgb compressed subscribers?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.