Android ROS Message crash
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();
}
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.
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.
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.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?@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.
I don't understand why you need all that socket open / close code. Did you try debugging with logcat?