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

Service in Android

asked 2013-02-21 10:16:08 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi everybody!

I started to use the ROS recently. I'm trying to call a Service in Android. The Service is running on rospy. Right now I have the server working well. The client (Android) has been implemented using two different modes:

  • public class Client extends AbstractNodeMain: generates an exception that I do not understand why.
  • public class Client implements NodeMain: there is no exception, but it also does not communicate with the server.

Someone can help me? Hope for help! Thanks.. Paulo

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-02-21 10:51:30 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi Paulo

The following code worked for me in implementing a ServiceClient in Android. Note that HMMv2/get_Joint_State.srv is a custom service of mine.

In the OnStart(ConnectedNode node) method (but before you implement a cancellable loop:

final ServiceClient<HMMv2.get_Joint_StateRequest, HMMv2.get_Joint_StateResponse> client;


            try 
            {
                client = node.newServiceClient("HMMv2Cont/JointState", HMMv2.get_Joint_State._TYPE);

            } 
            catch (ServiceNotFoundException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                throw new RosRuntimeException(e);
            }

            final HMMv2.get_Joint_StateRequest request=client.newMessage();

            request.setJointName("joints");

Then in the Cancellable loop, loop() function the code to call the service is:

client.call(request, new ServiceResponseListener<HMMv2.get_Joint_StateResponse>()    {

                                @Override
                            public void onFailure(RemoteException arg0) 
                            {
                                Log.d("Jointrequest Client", "failed to call service");
                                throw new RosRuntimeException(arg0);
                                // TODO Auto-generated method stub

                            }

                            @Override
                            public void onSuccess(HMMv2.get_Joint_StateResponse message) 
                            {
                                                           //do something with the response
                                hPos.set(0, 0, (message.getJointState().getPosition()[0]-512)*Math.PI/512);             



                            }

                                });

hope this example helps you. I think the main issue I found in implementing this was the declaration of a final ServiceClient types. But I've used this format a couple of times and it works.

cheers Peter

edit flag offensive delete link more

Comments

1

I have something similar. But when I run, an error occurs:

02-23 17:07:52.778: E/AndroidRuntime(671): org.ros.exception.RosRuntimeException: Connection exception: paulofonseca-PC:37008 02-23 17:07:52.778: E/AndroidRuntime(671): at org.ros.internal.transport.tcp.TcpClient.connect(TcpClient.java:109

paulofinseca gravatar image paulofinseca  ( 2013-02-23 05:44:26 -0600 )edit

check your logcat and see where in your program the exception is thrown. The reference you give only specifies a library file (TcpClient.java) but if you can scroll down you should see your file name with a line number. This should give some clue as to what is causing this exception.

PeterMilani gravatar image PeterMilani  ( 2013-02-24 10:17:45 -0600 )edit

I have the same issue : org.ros.exception.RosRuntimeException: Connection exception: ubuntu:38403 at org.ros.internal.transport.tcp.TcpClient.connect(TcpClient.java:109) Have you find a solution?

thomasL gravatar image thomasL  ( 2014-05-22 09:07:23 -0600 )edit
0

answered 2014-07-27 09:13:06 -0600

thomasL gravatar image

It might be an issue with Network configuration : NetworkSetup. See the paragraph "Setting a name explicitly".

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2013-02-21 10:16:08 -0600

Seen: 1,513 times

Last updated: Jul 27 '14