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

ROS subscriber shutdown() not doing anything when the topic is in the private namespace. Intentional? or Not?

asked 2019-08-07 08:21:39 -0600

samKys gravatar image

Hello all,

Ran into an interesting use case/issue that I cannot sort out if it's an intentional implementation or a C++ thing that I'm not understanding?

Scenario: I want to subscribe to a camera_info topic and grab only the first message to get the camera parameters.

Relevant code:

.h file

class OnPtCldColor
{
  public:
  //-- Constructor/Destructor --//
  OnPtCldColor(ros::NodeHandle n);
  ~OnPtCldColor();

  // Camera intrinsic parameters
  Eigen::Affine3f k_;
  void imageInfoCallback(const sensor_msgs::CameraInfoPtr& msg);

private:
  //-- Subscriber --//
  ros::Subscriber camInfo_sub_;
};

.cpp file

//-- Constructor --//
OnPtCldColor::OnPtCldColor(ros::NodeHandle n)
{
  // Some setup code here.....
  camera_params_loaded_ = false;
  //-- subscribe to the camera info
  camInfo_sub_ = n.subscribe("/right/camera_info", 1, &OnPtCldColor::imageInfoCallback, this);
}

// Some code and other functions

//-------------------- Camera Info parameters to get FOV etc. ----------------------//
// This is only called once and then shutdown....
void OnPtCldColor::imageInfoCallback(const sensor_msgs::CameraInfoPtr& msg)
{
  // Specified in documentation for K to only contain 9 elements, so....
  for (int i = 0; i < 9; i++)
  {
    k_.matrix()(int((i-i%3)/3.0),i%3) = msg->K.at(i);
  }

  camera_params_loaded_ = true;
  // Done with data, we assume it doesn't change between node launches....

    ROS_WARN(" Info received. Info sub is shutdown now....");
    camInfo_sub_.shutdown();
}

Now for the problem The above code works fine... but if I change the subscriber to be this: camInfo_sub_ = n.subscribe("/camera_info", 1, &OnPtCldColor::imageInfoCallback, this);

And in the launch file do this:

  <node pkg="online_mapping" type="ptcld_color" name="ptcld_color" clear_params="true" output="screen">
    <remap from="/ptcld_color/camera_info" to="/right/camera_info" />
  </node>

The camInfo_sub_.shutdown() call does nothing even if I run the subscriber destructor, camInfo_sub_.~Subscriber()

Questions

1) Is this intentional for private namespace remapped topics?
2) Am I doing something "illegal" or weird in terms of coding practice?
3) Thoughts? Suggestions?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-08-07 08:44:50 -0600

samKys gravatar image

Ok, found out I just did something very dumb....

I had two subscribers accidentally to the same callback and I only was shutting down one of them. The other kept running. closing question as it is solved.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-08-07 08:21:39 -0600

Seen: 1,601 times

Last updated: Aug 07 '19