0
$\begingroup$

Rosanswers logo

Hi, I have a node which serves primarily as a service, but I would like it to be able to subscribe to a publisher so that I can import an array before the service is called. I tried adding the subscriber to the same nodehandle that has the service, and tried creating a second nodehandle. Either way it seems unable to receive data. Can I not have multiple services/subscribers in a node? If not, what is the best way to do this?

Here is my code in the main function, for reference

ros::NodeHandle servNode;

ros::NodeHandle subNode;

SteeringCaller steerCall;

steerCall.haveX = false; steerCall.haveBoth = false;

ros::Subscriber sub = subNode.subscribe<std_msgs::Float64MultiArray>("path", 5000, &SteeringCaller::savePath, &steerCall);

ros::ServiceServer service = servNode.advertiseService("steering_control", &SteeringCaller::calcSteering, &steerCall);


Originally posted by explorerbot on ROS Answers with karma: 1 on 2013-07-18

Post score: 0


Original comments

Comment by Georg on 2013-07-18:
This is too few information. Actually you can have multple publishers, subscribers and services in the same node. If you look at nodes like camera1394, you will see that they do this a lot. Actually, since the source code for ROS is available you can just have a look at it and learn from it!

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Yes; you can have multiple publishers, subscribers, service servers and service clients in a single node.

You aren't calling ros::spin() or ros::spinOnce() anywhere in the code sample you're given; this may be part of the problem.

Can you please update your question with the entire file you're having problems with?


Originally posted by ahendrix with karma: 47576 on 2013-07-18

This answer was ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.