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

We see this in your code:

//ros::Publisher sensor_pub;
ros::Publisher sensor_pub1;
ros::Publisher sensor_pub2;

[..]

int main(int argc, char** argv)
{
  [..]

  ros::Publisher sensor_pub1 = nh.advertise<geometry_msgs::WrenchStamped>("/sensor_ati", 1000);
  ros::Publisher sensor_pub2 = nh.advertise<geometry_msgs::PoseArray>("/sensor_ndi", 1000);

  [..]
}

The issue here is that you first declare two variables in the global scope, but then never initialise them.

This is because the two lines in main(..) that advertise(..) the topics assign the result of NodeHandle::advertise<..>(..) to two function scope variables with the same name, causing sensor_pub1 and sensor_pub2 in the global scope to never be initialised.

Your callback(..) in the end tries to call publish(..) on the uninitialised Publisher, leading to the error you show (and which probably makes sense now: Call to publish() on an invalid Publisher).