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 | ros @ Robotics Stack Exchange |
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.
Asked: 2013-02-21 02:12:14 -0500
Seen: 1,148 times
Last updated: Feb 25 '13
Rosjava + Android phone + Kinect, is it possible?
rosjava image_transport example failing
Supported Android API levels in rosjava
Android and ROS Communication over USB instead of Wifi
How to check if the Pubsub tutorial is running correctly?
How to setup developer environment for rosjava(android)