Android ROS Message
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();
}
}
About the node object, I had no idea it had to be declared globally. That now is fixed.
How are you planning to send the message? TCP? I hope not. Is it a websocket?
hi @arunavanag. I am sending the data via a java socket.
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...
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...
Here is rosbridge suite installation if you already dont have it : http://wiki.ros.org/rosbridge_suite
@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.My bad, I got it wrong.