Ask Your Question

Service in ROSJAVA. How to start a ServiceServer

asked 2012-02-01 00:01:50 -0500

Markus Eich gravatar image

I have the problem of generating a service with ros java. I ended up with modifying the pubsub example. I read the javadoc and I ended at the node.newServiceServer part. I started to write my first service with empty request and empty response.

  ServiceServer<org.ros.message.std_msgs.Empty, org.ros.message.std_msgs.Empty> server = node.newServiceServer("callme",)

According to the javadoc, the params are

  • Type Parameters:
    • RequestType - type for the request
    • ResponseType - type for the response
  • Parameters:
    • serviceName - the name of the service
    • serviceType - the type of the service (e.g. "test_ros/AddTwoInts")
    • responseBuilder - called for every request to build a response

Now I am lost. What is the serviceType and what the responseBuilder?????? Can anyone complete my simple line if I want to have a simple service printing "hello world" if the service /callme is called? Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-02-02 02:42:40 -0500

damonkohler gravatar image

The class names are all full qualified here, but you could of course import them so that it wouldn't be necessary (making the code more compact).

ServiceServer<org.ros.message.std_msgs.Empty, org.ros.message.std_msgs.Empty> server = node.newServiceServer(
    "callme", "std_srvs/Empty",
    new ServiceResponseBuilder<org.ros.service.std_srvs.Empty.Request, org.ros.service.std_srvs.Empty.Response>() {
      public org.ros.service.std_srvs.Empty.Response build(org.ros.service.std_srvs.Empty.Request request) throws ServiceException {
        org.ros.service.std_srvs.Empty.Response response = new org.ros.service.std_srvs.Empty.Response();
        // ...
        return response;
edit flag offensive delete link more


I imported org.ros.service.*. But the problem is that I cannot resolve org.ros.service.std_srvs.Empty.Response or org.ros.service.std_srvs.Empty.Response. How can I generate and import this messages? The only part I can find is org.ros.service.roscpp... but no ros.service.std_srvs. Any ideas?

Markus Eich gravatar image Markus Eich  ( 2012-02-13 02:32:19 -0500 )edit

Did you add a dependency on std_srvs to your manifest.xml? After adding the dependency, you'll also need to run rosmake.

damonkohler gravatar image damonkohler  ( 2012-02-20 00:15:37 -0500 )edit

Yes, That solved the problem. Thanx,

Markus Eich gravatar image Markus Eich  ( 2012-02-21 03:18:45 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-02-01 00:01:50 -0500

Seen: 1,088 times

Last updated: Feb 02 '12