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

I think you take things too "serious".

  1. Why dereference pointer, you can also do clientPtr->call(srv). You don't have to use a ptr at all.
  2. You don't have to call ros::spin(), you can also use ros::spinOnce(), so you will have your main loop to call the service.

I think the answer to your primary question is clear, Yes they can have / be both!

There are several tutorials which describe the background, I dont think a all in one tutorial is needed.

Look at this tutorial for the ros main-loop behaviour: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

Look at this tutorial for the server-client stuff: http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29

If putting both together you take things too "serious".will have a basic understanding to find the solution for your problem. Of course you can also use Nodelet's but they are more C++ object oriented style, so there you don't have a main-loop anymore, you can only use callbacks which includes timer callbacks desribed here:

http://wiki.ros.org/roscpp/Overview/Timers

And now some notes regarding your code:

  1. Why dereference pointer, you can also do clientPtr->call(srv). You don't have to use a ptr at all.
  2. You don't have to call ros::spin(), you can also use ros::spinOnce(), so you will have your main loop to call the service.

I think the answer to your primary question is clear, Yes they can have / be both!

There are several tutorials which describe the background, I dont think a all in one tutorial is needed.

Look at this tutorial for the ros main-loop behaviour: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

Look at this tutorial for the server-client stuff: http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29

If putting both together you will have a basic understanding to find the solution for your problem. Of course you can also use Nodelet's but they are more C++ object oriented style, so there you don't have a main-loop anymore, you can only use callbacks which includes timer callbacks desribed here:

http://wiki.ros.org/roscpp/Overview/Timers

And now some notes regarding your code:

  1. Why dereference pointer, you can also do clientPtr->call(srv). You don't have to use a ptr at all.
  2. You don't have to call ros::spin(), you can also use ros::spinOnce(), so you will have your main loop to call the service.
  3. Make sure that you know when and how often you want to call the service. Everytime you got a incoming message (subscribed topic callback), every frame in your main loop (inside spinOnce main-loop), or maybe every x seconds (Timer callbacks). And this are only the synchronious ones.