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

You need to provide more of your code. However, it appears to me that you misunderstand subscriptions.

That is, a topic is associated with a particular type of message; for instance, a geometry_msgs::Point. The callback for a particular subscriber processes the specified type of message declared when the subscriber is instantiated (through a NodeHandle). Typically, the code looks like this:

// this is NOT valid code!!! (e.g., no main()!)
ros::Subscriber m_sub;
ros::NodeHandle nh;
...
void pointCallback(const geometry_msgs::Point &point) {
   // do something with point message
}
...
// topic: /some_point, message type: geometry_msgs::Point
// queue size: 1, callback method: pointCallback
m_sub = nh.subscribe<geometry_msgs::Point>("/some_point", 1, &pointCallback);
...
// begin processing messages
ros::spin();

It appears that you want to process two Points on one topic. ROS doesn't work that way.

You have multiple solutions, though. You could:

  • Create two subscribers (each with a callback) and process the points as you receive them (you likely want to synchronize them)
  • Look into the Message Filters package (likely, ApproximateTime)
  • Create a publisher for a new message type containing both Points (left as an exercise for the poster)
  • Some other solution

If that doesn't help, again: post more of your code so that what you are attempting is (more) clear.