Can't get messages from publisher on Android

asked 2020-06-12 14:00:25 -0500

carlv gravatar image

Hi, I'm using the code from the android_tutorial_pubsub on android studio and for some reason, after getting a topic on Ubuntu publishing messages, I can't get them on android even though I succeeded while trying to connect the app to the MASTER URI.

Here's the code:

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

import org.ros.address.InetAddressFactory;
import org.ros.android.MessageCallable;
import org.ros.android.RosActivity;
import org.ros.android.view.RosTextView;
import org.ros.node.NodeConfiguration;
import org.ros.node.NodeMainExecutor;
  public class MainActivity extends RosActivity {

  private RosTextView<std_msgs.String> rosTextView;

  public MainActivity() {

    super("Pubsub Tutorial", "Pubsub Tutorial");
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    rosTextView = (RosTextView<std_msgs.String>) findViewById(R.id.text);
    rosTextView.setTopicName("test");
    rosTextView.setMessageType(std_msgs.String._TYPE);
    rosTextView.setMessageToStringCallable(new MessageCallable<String, std_msgs.String>() {
      @Override
      public String call(std_msgs.String message) {
        return "MSG: " + message.getData();
      }
    });
  }


  @Override
  protected void init(NodeMainExecutor nodeMainExecutor) {

    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(getRosHostname());
    nodeConfiguration.setMasterUri(getMasterUri());
    nodeConfiguration.setNodeName("test");
    nodeMainExecutor.execute(rosTextView, nodeConfiguration);
  }
}

I'm using VMWare player to run the /test topic and I'm using a SSH tunnel to connect my phone to it, which has worked in the past in tutorials like controlling the turtle from TurtleSim.

What am I missing? Thanks in advance.

edit retag flag offensive close merge delete