ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question

Revision history [back]

The problem is that you have defined subscribers in a local namespace. Thus j1_sub and j2_sub are destroyed immediately after setTest() function returns. So make them members of the class to make it work.

The problem is that you have defined subscribers in a local namespace. Thus j1_sub and j2_sub are destroyed immediately after setTest() function returns. So make them members of the class to make it work.work. Same with the TimeSynchronizer.

The problem is that you have defined subscribers in a local namespace. Thus j1_sub and j2_sub are destroyed immediately after setTest() function returns. So make them members of the class to make it work. Same with the TimeSynchronizer.


EDIT:

Here is one of the possible implementations:

class SynchronizerTest
{
  boost::shared_ptr<Subscriber<geometry_msgs::PoseStamped> > j1_sub;
  boost::shared_ptr<Subscriber<geometry_msgs::PoseStamped> > j2_sub;
  boost::shared_ptr<TimeSynchronizer<geometry_msgs::PoseStamped, geometry_msgs::PoseStamped> > sync;

...

  void setTest()
  {
    j1_sub.reset(new Subscriber<geometry_msgs::PoseStamped>(*n_, "/SynchronizerTest1", 10));
    j2_sub.reset(new Subscriber<geometry_msgs::PoseStamped>(*n_, "/SynchronizerTest2", 10));
    sync.reset(new TimeSynchronizer<geometry_msgs::PoseStamped, geometry_msgs::PoseStamped>(*j1_sub, *j2_sub, 10));
    sync->registerCallback(boost::bind(&SynchronizerTest::handelerSynchronizerTest, this, _1, _2));
    ROS_INFO("Test set");
  }

...

}

The problem is that you have defined subscribers in a local namespace. Thus j1_sub and j2_sub are destroyed immediately after setTest() function returns. So make them members of the class to make it work. Same with the TimeSynchronizer.


EDIT:

Here is one of the possible implementations:

class SynchronizerTest
{
  boost::shared_ptr<Subscriber<geometry_msgs::PoseStamped> > j1_sub;
  boost::shared_ptr<Subscriber<geometry_msgs::PoseStamped> > j2_sub;
  boost::shared_ptr<TimeSynchronizer<geometry_msgs::PoseStamped, geometry_msgs::PoseStamped> > sync;

...

  void setTest()
  {
    j1_sub.reset(new Subscriber<geometry_msgs::PoseStamped>(*n_, Subscriber<geometry_msgs::PoseStamped>(n, "/SynchronizerTest1", 10));
    j2_sub.reset(new Subscriber<geometry_msgs::PoseStamped>(*n_, Subscriber<geometry_msgs::PoseStamped>(n, "/SynchronizerTest2", 10));
    sync.reset(new TimeSynchronizer<geometry_msgs::PoseStamped, geometry_msgs::PoseStamped>(*j1_sub, *j2_sub, 10));
    sync->registerCallback(boost::bind(&SynchronizerTest::handelerSynchronizerTest, this, _1, _2));
    ROS_INFO("Test set");
  }

...

}