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
void callBack(const received_message_type receivedMessage)
{
  new_message_type newMessage;
  [code for conversion]
  ros::NodeHandle nh_pub;
  ros::Publisher pub = nh_pub.advertise<new_message_type>("a1", 1000);
  ...
}

you are creating a Publisher inside a callback.

That is not a good idea and will not work reliably.

void callBack(const received_message_type receivedMessage) { new_message_type newMessage; [code for conversion] ros::NodeHandle nh_pub; ros::Publisher pub = nh_pub.advertise<new_message_type>("a1", 1000); ... }

}

you are creating a Publisher inside a callback. That object is then also immediately destroyed at the end of the callback.

That is not a good idea and will not work reliably.

Setting up subscriptions takes time, and you don't give your subscribers any time to do that.

Move your ros::Publisher object to a scope which lives longer than the callback and it should start working, provided there are no other problems with your code.

You have this:

void callBack(const received_message_type receivedMessage)
 {
   new_message_type newMessage;
   [code for conversion]
   ros::NodeHandle nh_pub;
   ros::Publisher pub = nh_pub.advertise<new_message_type>("a1", 1000);
   ...
    }

}

you are creating a Publisher inside a callback. That object is then also immediately destroyed at the end of the callback.

That is not a good idea and will not work reliably.

Setting up subscriptions takes time, and you don't give your subscribers any time to do that.

Move your ros::Publisher object to a scope which lives longer than the callback and it should start working, provided there are no other problems with your code.

You have this:

void callBack(const received_message_type receivedMessage)
{
  new_message_type newMessage;
  [code for conversion]
  ros::NodeHandle nh_pub;
  ros::Publisher pub = nh_pub.advertise<new_message_type>("a1", 1000);
  ...
}

you are creating a Publisher inside a callback. That object is then also immediately destroyed at the end of the callback.

That is not a good idea and will not work reliably.

Setting up subscriptions takes time, and you don't give your subscribers any time to do that.that (as the publisher will be destroyed before the subscriber can receive any data).

Move your ros::Publisher object to a scope which lives longer than the callback and it should start working, provided there are no other problems with your code.