Skip Master Chooser
I am developing an android app with rosjava, and I am setting the Master URI programatically. Therefore, the Master Chooser screen does nothing for me. Is there a way I can skip it totally?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
I am developing an android app with rosjava, and I am setting the Master URI programatically. Therefore, the Master Chooser screen does nothing for me. Is there a way I can skip it totally?
Thanks to Kazuto for the lead, but there are a few issues with his answer. I was able to solve them with the included code. First, I changed startMasterChooser in RosActivity.java to public, and then pasted this code into my activity:
@Override
public void startMasterChooser() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String masterURI = prefs.getString("masterURI", "http://192.168.1.113:11311");
Intent data = new Intent();
data.putExtra("ROS_MASTER_URI", masterURI);
onActivityResult(0, RESULT_OK, data);
}
Alternatively, you can just hardcode the masterURI...I chose to have it as a preference. Hopefully changing the RosActivity code doesn't have any effect on future work.
I think this is better solution because it can work well without adding a new global variable.
Master Chooser is called in the startMasterChooser() method, and this method is public. So you can override it in your original activity class.
For example:
@Override
public void startMasterChooser() {
URI uri;
try {
uri = new URI(ROS_MASTER_URI);
} catch (URISyntaxException e) {
throw new RosRuntimeException(e);
}
nodeMainExecutorService.setMasterUri(uri);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
CustomActivity.this.init(nodeMainExecutorService);
return null;
}
}.execute();
}
ROS_MASTER_URI is your fixed URI.
CustomActivity is your original activity class.
Few issues. First, startMasterChooser is private. You have to change that in the gingerbread package. Second, nodeMainExecutor cannot be accessed this way. More changes would have to be made the RosActivity file. Instead, you can do what I did...see my solution.
Oh, you are right, I forget changing my RosActivity class and making nodeMainExecutorService global before, I'm sorry! Actually, my program works well with above codes.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2013-02-21 02:12:14 -0500
Seen: 1,094 times
Last updated: Feb 25 '13
Converting/importing existing ROS code to rosjava
Adding an image publishing node to the android_tutorial_image_transport
Laserscan subscription delay! rosjava on android
using java-actionlib on android doesn't work
Android Problem Subscribing to a custom message
Simple Publisher and Subscriber for rosjava
android_tutorial_image_transport crashed in android [closed]
Show map and robot in VisualizationView at the same time on Android