create service on android
Hello!
I'm trying to create a service with rosjava on Android. However, I need to use an old rosjava version since I need the support for actionlib.
So, when I create the service server in my app, I can even see it with rxgraph on the linux machine running the roscore. However, as soon as i try to call the service via command line with "rosservice call /callme" (/callme is the name of the service) I receive following error messages:
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 734, 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.
The code is: package com.example.sandbox_ros;
import org.ros.internal.node.service.ServiceException;
import org.ros.internal.node.service.ServiceResponseBuilder;
import org.ros.namespace.GraphName;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.service.myMessages.onlyReturn;
import android.util.Log;
public class TestServiceServer implements NodeMain {
private final String TAG = "TestServiceServer";
@Override
public void onShutdown(Node arg0) {
// TODO Auto-generated method stub
}
@Override
public void onShutdownComplete(Node arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStart(Node node) {
/*ServiceServer<org.ros.message.std_msgs.Empty, org.ros.message.std_msgs.String> server = */
node.newServiceServer("/callme", "myMessages/onlyReturn", new ServiceResponseBuilder<onlyReturn.Request, onlyReturn.Response>() {
@Override
public onlyReturn.Response build(onlyReturn.Request request) throws ServiceException {
Log.i(TAG, "request: " + request.intput.data);
onlyReturn.Response response = new onlyReturn.Response();
response.output.data = "Thank you for calling! :)";
Log.i(TAG, "I have been called!");
return response;
}
});
}
@Override
public GraphName getDefaultNodeName() {
// TODO Auto-generated method stub
return null;
}
}
and the node is created with:
NodeConfiguration configuration = NodeConfiguration.newPublic(androidhostIP, uriOfROSMachine);
Date date = new Date();
configuration.setNodeName("srs_ui_loc_start" + "_" + date.getTime());
TestServiceServer testNode = new TestServiceServer();
NodeMainExecutor runner = DefaultNodeMainExecutor.newDefault();
runner.execute(testNode, configuration);
I know, I'm using something old, but I though, maybe I'm not alone? :) Or maybe someone remembers that problem from former times?
funny thing: I have implemented the add_two_ints_server on Android. When I run "rosrun rospy_tutorials add_two_ints_client 1 2" it works, I receive "1 + 2 = 3" :D So, it seems to work with python clients. I think I can live with that workaround :)