ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The is that I shut down my subscriber when I don't need, and re-subscribe again. 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 avoi 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();
}

The problem is that I shut down my subscriber when I don't need, need it, and re-subscribe again. 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 avoi 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();
}

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 avoi 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();
}