Android ROS Message crash

asked 2018-02-25 23:12:44 -0500

ByteMonster gravatar image

This question is a continuation of a previous asked question that I made, posted at https://answers.ros.org/question/2831... . I tried to use the from this Github repository https://github.com/jubeira/ros_androi... . However I got a crash with no error message when I try to send a message.

The main idea of the functionality is to type a message to send to ROS via ROSJava that is collected from an Android Dialog Box . So say for example you send a message with the contents "Go here". My Android app would crash before the dialog box shows up. Can anyone give me an idea what is wrong with my code and a way to fix my issue?

In regards to the "Talker" class that class is a model class in my application.

I will post my code below.

  public void executeCommand(NodeMainExecutor nme){

      java.lang.String command = dialogBoxCommand();
      command.toLowerCase();

      Talker talker = new Talker();
      talker.setCommand(command);
      try{
          java.net.Socket socket = new java.net.Socket(getMasterUri().getHost(), getMasterUri().getPort());
          java.net.InetAddress local_network_address = socket.getLocalAddress();
          socket.close();
          NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(local_network_address.getHostAddress(), getMasterUri());
          nodeConfiguration.setNodeName("android/command");

          java.lang.String commandTopic = "/rosout";

          NameResolver appNameSpace = getMasterNameSpace();
          commandTopic = appNameSpace.resolve(commandTopic).toString();

          nme.execute(talker,nodeConfiguration);

      }catch (IOException e) {
          Toast.makeText(getApplicationContext(), "Unable to execute command",Toast.LENGTH_SHORT).show();
      }
  }

  protected java.lang.String dialogBoxCommand(){

      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setTitle("Title");

      final EditText input = new EditText(this);

      input.setInputType(InputType.TYPE_CLASS_TEXT);
      builder.setView(input);

      builder.setPositiveButton("Start Command", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              final java.lang.String command = input.getText().toString();
          }
      });
      builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              dialog.cancel();
          }
      });
      builder.show();
      return input.getText().toString();
  }
edit retag flag offensive close merge delete

Comments

ok so I realised I had to put previous two lines within the try catch statement. That is done now.The only thing is the message is not sent over.

ByteMonster gravatar imageByteMonster ( 2018-02-25 23:45:19 -0500 )edit

Now I just can't figure out why it can't send any messages to ROS. Can someone help me? I have been going at it for a while and can't figure it out.

ByteMonster gravatar imageByteMonster ( 2018-02-26 00:17:38 -0500 )edit

One thing to check: ROS nodes need to be able to resolve hostnames to IP addresses -- or only use IP addresses -- when sending msgs. If you don't have a working DNS for all hosts (ie: a local router), then try to configure ROS_IP on all hosts, and use an IP-only master URL.

gvdhoorn gravatar imagegvdhoorn ( 2018-02-26 01:39:23 -0500 )edit

What exception are you getting? Try debugging with logcat: https://developer.android.com/studio/... .

That will give you more clues. The problem may be completely unrelated to the code you posted. What does Talker do? Is it just the regular publisher from the examples?

jubeira gravatar imagejubeira ( 2018-02-26 07:40:37 -0500 )edit

@juberia The talker class is similar to the one that was in your Git repository that I linked, except it just has a get and set for a message.

I also did some testing on the code and it seems that the dialog box will show up but will not send the message. The catch statement would show an error.

ByteMonster gravatar imageByteMonster ( 2018-02-26 16:36:58 -0500 )edit

I don't understand why you need all that socket open / close code. Did you try debugging with logcat?

jubeira gravatar imagejubeira ( 2018-02-28 12:06:53 -0500 )edit