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

rosjava: calling rosservice fails

asked 2012-02-13 22:08:05 -0500

Markus Eich gravatar image

updated 2012-02-20 07:51:30 -0500

kwc gravatar image

Dear all,

I made my first homebrewed rosservice with Java. I have generated my custom service GetCylinders.srv

 ---
 string name
 float32 likelihood

which should return a name and a likelihood with an empty request. I have generated the service and included it in my server like this:

 import org.ros.service.reasoner_msgs.*;

   ServiceServer<org.ros.service.reasoner_msgs.GetCylinders.Request, org.ros.service.reasoner_msgs.GetCylinders.Response> server = node.newServiceServer(
        "callme", "reasoner_msgs/GetCylinders",

        new ServiceResponseBuilder<org.ros.service.reasoner_msgs.GetCylinders.Request, org.ros.service.reasoner_msgs.GetCylinders.Response>() {
          @Override
          public org.ros.service.reasoner_msgs.GetCylinders.Response build(org.ros.service.reasoner_msgs.GetCylinders.Request request) throws ServiceException {
            org.ros.service.reasoner_msgs.GetCylinders.Response response = new org.ros.service.reasoner_msgs.GetCylinders.Response();
            // ...
            response.name="CylinderA";
            response.likelihood=(float) 0.7;

            return response;
          }
        }
);

When I start the node the service /callme shows up. Well that is fine. But if I use rosservice call /callme i get an error. Have I done something wrong in the setup of the service? The error message I get is

 Traceback (most recent call last):
 File "/opt/ros/electric/ros/bin/rosservice", line 46, in <module>
rosservice.rosservicemain()
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/rosservice.py", line 731, in rosservicemain
_rosservice_cmd_call(argv)
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/rosservice.py", line 586, in _rosservice_cmd_call
service_class = get_service_class_by_name(service_name)
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/rosservice.py", line 357, in get_service_class_by_name
service_type = get_service_type(service_name)
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/rosservice.py", line 141, in get_service_type
return get_service_headers(service_name, service_uri).get('type', None)
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/rosservice.py", line 113, in get_service_headers
return roslib.network.read_ros_handshake_header(s, cStringIO.StringIO(), 2048)
 File "/opt/ros/electric/ros/core/roslib/src/roslib/network.py", line 367, in read_ros_handshake_header
raise ROSHandshakeException("connection from sender terminated before handshake header received. %s bytes were received. Please check sender for additional details."%b.tell())
 roslib.network.ROSHandshakeException: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.

Can anyone help me in solving this problem?

edit retag flag offensive close merge delete

Comments

I found out that using rosservice info /callme and rosservice args /callme give the same error. rosservice list shows /callme and rosservice uri /callme gives rosrpc://127.0.0.1:53311. Strange. Is there maybe a bug in the rosjavas service call?

Markus Eich gravatar image Markus Eich  ( 2012-02-14 02:38:03 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-03-05 07:14:38 -0500

damonkohler gravatar image
edit flag offensive delete link more
0

answered 2012-02-15 03:26:09 -0500

Markus Eich gravatar image

updated 2012-02-15 03:36:47 -0500

I wrote a little client for the caller in Java. THIS WORKS!! I did also a C++ client caller and this works as well. It seems that ROSJAVA is not compatible with the rostools, i.e. rosservice. Is this a know bug? For others who read this posting: I have included the client call methods. It would be much nicer to test small services with the rostools. Writing always clients for testing a service or a topic takes much longer.

 package service_caller;


 import org.apache.commons.logging.Log;
 import org.ros.exception.RemoteException;
 import org.ros.namespace.GraphName;
 import org.ros.node.Node;
 import org.ros.node.NodeMain;
 import org.ros.node.service.ServiceClient;
 import org.ros.node.service.ServiceResponseListener;
 import org.ros.service.reasoner_msgs.*;



 public class Caller implements NodeMain {


 @Override
 public GraphName getDefaultNodeName() {
  return new GraphName("service_caller/Caller");
  }

  @Override

  public void onStart(Node node) {
  final Log log = node.getLog();

 try{
    ServiceClient<GetCylinders.Request, GetCylinders.Response> client = node.newServiceClient("callme","reasoner_msgs/GetCylinders");
    GetCylinders.Request request=new GetCylinders.Request();        


    client.call(request, new ServiceResponseListener<GetCylinders.Response>() {                                          

        @Override
        public void onSuccess(GetCylinders.Response respone) {
            System.out.println("Success:"+respone.likelihood+","+respone.name);
            // TODO Auto-generated method stub

        }

        @Override
        public void onFailure(RemoteException arg0) {
            System.out.println("Fail!!");
            // 

        }
    });                         

}

catch(Exception ex){
    System.out.println(ex.getMessage());
};



 }

   @Override
   public void onShutdown(Node node) {
    }

   @Override
   public void onShutdownComplete(Node node) {
     }
 }
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-02-13 22:08:05 -0500

Seen: 810 times

Last updated: Mar 05 '12