Ask Your Question
0

Android ROS Message

asked 2018-02-19 17:28:39 -0500

ByteMonster gravatar image

I'm unsure where to turn to get help for my question, so I might try my luck here.

I am trying to send a message to a ROS via an Android Application. The message is the string "Hello World". I tried to do some research and found out that I could use a MessageFactory object but I am unsure what else to do. Can someone point me in the right direction?

I am also aware that my node object has not been initialized. I tried doing some research into but haven't got found any information that can help. Any help here also would be appreciated. It is denoted by the comment "known error here".

I will post my code below, along with the packages I included.

//packages included

import org.ros.android.BitmapFromCompressedImage;
import org.ros.android.view.RosImageView;
import org.ros.android.view.VirtualJoystickView;
import org.ros.message.MessageFactory;
import org.ros.namespace.NameResolver;
import org.ros.node.Node;
import org.ros.node.NodeConfiguration;
import org.ros.node.NodeMainExecutor;


  public void executeCommand(NodeMainExecutor nodeMainExecutor){
      Node node;

      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());

          String craneTopic = "/rosout";

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

          MessageFactory factory = node.getTopicMessageFactory();// known error here
          std_msgs.String m = factory.newFromType(std_msgs.String._TYPE);

         //nodeMainExecutor.execute(, nodeConfiguration.setNodeName("android/follow_crane")); // unknown what to put here

      }catch (IOException e) {
          Toast.makeText(getApplicationContext(), "Unable to execute command",Toast.LENGTH_SHORT).show();
      }  
  }
edit retag flag offensive close merge delete

Comments

About the node object, I had no idea it had to be declared globally. That now is fixed.

ByteMonster gravatar imageByteMonster ( 2018-02-19 18:11:35 -0500 )edit

How are you planning to send the message? TCP? I hope not. Is it a websocket?

arunavanag gravatar imagearunavanag ( 2018-02-19 20:01:28 -0500 )edit

hi @arunavanag. I am sending the data via a java socket.

ByteMonster gravatar imageByteMonster ( 2018-02-19 20:29:39 -0500 )edit

Great then just configure your java socket to send the wlan id and port = 9090 (rosbridge_websocket default port) and send over to the respective topic.

Here these guys are sending it from Windows Unity to ROS websocket : https://github.com/soliagabriel/holoR...

arunavanag gravatar imagearunavanag ( 2018-02-19 20:59:30 -0500 )edit

Have a look at the source script (its in C#). On the other end just launch rosbridge_websocket, and run your node which has the same topic name.

Also you may wanna see the rosbridge messaging protocol: https://github.com/biobotus/rosbridge...

arunavanag gravatar imagearunavanag ( 2018-02-19 21:01:17 -0500 )edit

Here is rosbridge suite installation if you already dont have it : http://wiki.ros.org/rosbridge_suite

arunavanag gravatar imagearunavanag ( 2018-02-19 21:06:15 -0500 )edit

@arunavanag: I believe you missed that the OP is trying to use ROS Android. That is a regular client library for ROS 1. No need to run to rosbridge_suite immediately.

gvdhoorn gravatar imagegvdhoorn ( 2018-02-20 01:56:22 -0500 )edit

My bad, I got it wrong.

arunavanag gravatar imagearunavanag ( 2018-02-20 01:59:03 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-02-20 15:50:16 -0500

jubeira gravatar image

updated 2018-02-21 06:32:02 -0500

Hi @ByteMonster,

To publish messages, you need to create and execute a node. Within the context of the node execution, you can get a publisher and start doing what you want. I'd definitely not go the way of Java sockets in this case; you can use RosJava.

I've created a minimal example app to show the point. You can take a look here: https://github.com/jubeira/ros_androi... , and in particular, at the main activity.

Note that the nodes you create should extend AbstractNodeMain, and the user code should always be in its onStart method. The ConnectedNode received by that method will provide you with methods to create publishers and so on.

Hope it helps!

Edit: You can also take a look at the 'official' code samples in Android Core. The most basic example there is this one: https://github.com/rosjava/android_co... , which is just a bit more advanced than the one I posted above.

edit flag offensive delete link more

Comments

@ByteMonster were you able to solve your problem?

jubeira gravatar imagejubeira ( 2018-02-21 06:32:24 -0500 )edit

@juberia I was able to use your example as launching platform to solve my problem. I think it is done, I just need to test it. However I did come across an error in the ROSjava. If can't figure it out I will post another question on the forum

ByteMonster gravatar imageByteMonster ( 2018-02-21 19:45:57 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-02-19 17:28:39 -0500

Seen: 519 times

Last updated: Feb 21 '18