Ask Your Question
0

using java-actionlib on android doesn't work

asked 2012-01-10 01:36:19 -0500

markkre gravatar image

updated 2012-01-11 18:10:58 -0500

Hello ROS community!

I have following set-up:

  • an Ubuntu in a Virtual Box (running in Windows 7) (192.168.0.72)
  • an Android Device (192.168.0.68)

Network setup:

  • Host Operating System (Windows 7, IP=192.168.0.59 via DHCP) is connected via LAN to the company network.
  • Virtual Box Network settings: Bridged Adapter
  • Ubuntu in Virtual Box has 192.168.0.72 (DHCP)
  • Android Device is connected via WLAN (DHCP) to the company network
  • I can ping all devices from Windows 7 and Ubuntu

I want to run the Fibonacci tutorial from the actionlib tutorials (https://code.google.com/p/rosjava/source/browse/actionlib_java/src/tutorials/java/org/ros/actionlib/example/FibonacciActionClient.java">click). When both, the client and the server, run on Ubuntu, everything works.

As soon as the client runs on android, it doesn't work anymore. The client says "Waiting for action server to start". This is the client code:

package org.ros.android.tutorial.pubsub;

import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;

import org.ros.actionlib.example.RunFibonacciSimpleActionClient;
import org.ros.address.BindAddress;
import org.ros.node.DefaultNodeRunner;
import org.ros.node.NodeConfiguration;
import org.ros.node.NodeRunner;
import org.ros.tutorials.pubsub.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

    /**
     * @author damonkohler@google.com (Damon Kohler)
     */
    public class MainActivity extends Activity {

      @SuppressWarnings("static-access")
        public MainActivity() {
            System.setProperty("java.net.preferIPv6Addresses", "false");
        }

      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      }

        @Override
        protected void onResume() {
            super.onResume();

            String masterUri = "http://192.168.0.72:11311";
            String host = "192.168.0.68";
            URI uri = null;
            try {
                uri = new URI(masterUri);
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            NodeConfiguration configuration = NodeConfiguration.newPublic(host, uri);

            //NodeConfiguration configuration = NodeConfiguration.newPrivate();
            configuration.setNodeName("fibClientNode");
            configuration.setMasterUri(uri);
            NodeRunner runner = DefaultNodeRunner.newDefault();

            RunFibonacciSimpleActionClient fibClient = new RunFibonacciSimpleActionClient();
            Log.v("topics", configuration.getMasterUri().toString());
            fibClient.run(runner, configuration);
        }

      @Override
      protected void onPause() {
        super.onPause();
      }

    }

This is the important server code:

    public static void main() {
    try {
      // user code implementing the SimpleActionServerCallbacks interface
      FibonacciSimpleActionServerCallbacks impl = new FibonacciSimpleActionServerCallbacks();

      FibonacciActionSpec spec = new FibonacciActionSpec();
      final FibonacciSimpleActionServer sas =
          spec.buildSimpleActionServer("fibonacci_server", impl, true);

    String masterUri = "http://192.168.0.72:11311";
    String host = "192.168.0.72";
    URI uri = null;
    try {
        uri = new URI(masterUri);
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

      NodeConfiguration configuration = NodeConfiguration.newPublic(host, uri);
      configuration.setNodeName("fibServerNode");

      NodeRunner runner = DefaultNodeRunner.newDefault();

      runner.run(new NodeMain() {

        @Override
        public void onStart(Node node) {
          sas.addClientPubSub(node);
        }

        @Override
        public void onShutdown(Node node) {
        }

        @Override
        public void onShutdownComplete(Node node) {
        }

      }, configuration);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

Additional information:

ubuntu@ubuntu-VirtualBox:~$ rosnode list -a http://192.168.0.68:33448 /fibClientNode http://192.168.0.72:45874 /fibServerNode http://192.168.0.72:58875/ /rosout

ubuntu@ubuntu-VirtualBox:~$ roswtf Loaded plugin tf.tfwtf No package or stack in context ================================================================================ Static checks summary:

No errors or warnings ================================================================================ Beginning tests of your ROS graph. These may take awhile... analyzing ...

(more)
edit retag flag offensive close delete

Comments

I have edited my previous question: 1.) added ip addresses at the setup description 2.) removed long comment at the beginning of the client's code. markkre ( 2012-01-10 17:24:09 -0500 )edit
I have edited the question again: added "Network setup" markkre ( 2012-01-11 18:11:38 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2012-01-16 20:11:02 -0500

markkre gravatar image

I finally found the solution for the problem! It was the android version. I used Android Froyo and I didn't get any errors, but it doesn't work. I tried it with a simulator running gingerbread and it worked for me!

Using Froyo seems to work at first glance because the nodes and topics on android device are found by roscore. But for some reason communication is not possible with Froyo. I'm using CyanogenMod now for running gingerbread on my android device, since there is no official update and the ROS communication works (tested with Fibonacci tutorial)!

edit flag offensive delete publish link more
2

answered 2012-01-10 03:48:13 -0500

ahendrix gravatar image

updated 2012-01-10 17:43:21 -0500

This is a communication problem. When you create your NodeConfiguration, you pass the IP of the master as your local node IP. You should set host to 192.168.0.68, or have you code figure it out dynamically. See: http://www.ros.org/wiki/rosjava/Overview/Nodes#NodeConfiguration

EDIT: This could also be a problem with the windows firewall blocking inbound or outbound ROS connections. Since ROS listens on dynamic ports, and connections are made in both directions, the only real solution is to disable the firewall entirely.

edit flag offensive delete publish link more

Comments

I'm not sure which NodeConfiguration you are talking about, since there are two, one for the client and one for the server. roscore runs on 192.168.0.72. the server is running on 192.168.0.72, too. And the client is running on Android Device with the IP 192.168.0.68. So, which host IP is wrong? markkre ( 2012-01-10 17:14:39 -0500 )edit
Hrm... looks like I misread your code; sorry. Edited. ahendrix ( 2012-01-10 17:41:37 -0500 )edit
If the firewall blocks, why would rosnode find the client node? But I'll see into that anyway, thx for the advice! I'll let you know as soon I have checked that. markkre ( 2012-01-10 20:09:44 -0500 )edit
no, it doesn't make a difference, switching off the Firewall. Any more ideas? Btw, I am using Android API 8. But I don't think that should be a problem, should it? markkre ( 2012-01-10 23:16:14 -0500 )edit
There could also be a more subtle problem with the way VirtualBox forwards packets between your VM and the host. What are your networking settings on the host, in VirtualBox, and in your VM? ahendrix ( 2012-01-11 12:11:14 -0500 )edit
It doesn't even work without using the virtualbox or ubuntu. That means, i run a local roscore on android with the android pubsub tutorial but the rostextview doesn't show a message. markkre ( 2012-01-12 22:40:53 -0500 )edit
Which revision of rosjava_core are you using? I think there's a bug with subscribers in one of the older revisions. See: http://answers.ros.org/question/3591/rosjava-subscriber-unreliable . ahendrix ( 2012-01-14 17:46:09 -0500 )edit
1

answered 2012-01-10 01:47:27 -0500

dornhege gravatar image

updated 2012-01-10 01:48:03 -0500

I guess it's a communication problem. You should probably also set ROS_IP on the client (to 192.168.0.68).

edit flag offensive delete publish link more

Comments

is there a way to set ROS_IP on an android device in java code? or is that done by setting the host of the nodeConfiguration? because i'm doing that: ... String host = "192.168.0.68"; ... NodeConfiguration configuration = NodeConfiguration.newPublic(host, uri); ... markkre ( 2012-01-10 17:00:23 -0500 )edit

Your Answer

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

Add Answer

[hide preview]

Stats

Asked: 2012-01-10 01:36:19 -0500

Seen: 586 times

Last updated: Jan 16 '12