ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Can I have both a subscriber and a service in a single node?

asked 2013-07-18 08:42:30 -0500

explorerbot gravatar image

updated 2013-07-18 08:43:08 -0500

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);

edit retag flag offensive close merge delete

Comments

2

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!

Georg gravatar image Georg  ( 2013-07-18 09:49:49 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-07-18 15:29:40 -0500

ahendrix gravatar image

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?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-18 08:42:30 -0500

Seen: 1,637 times

Last updated: Jul 18 '13