Ask Your Question
2

Skip Master Chooser

asked 2013-02-21 02:12:14 -0600

dberm22 gravatar image

updated 2014-01-28 17:15:21 -0600

ngrennan gravatar image

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-02-25 04:31:26 -0600

dberm22 gravatar image

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.

edit flag offensive delete link more

Comments

I think this is better solution because it can work well without adding a new global variable.

KazutoMurase gravatar imageKazutoMurase ( 2013-02-25 05:13:30 -0600 )edit
2

answered 2013-02-21 08:41:51 -0600

KazutoMurase gravatar image

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.

edit flag offensive delete link more

Comments

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.

dberm22 gravatar imagedberm22 ( 2013-02-25 01:12:39 -0600 )edit

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.

KazutoMurase gravatar imageKazutoMurase ( 2013-02-25 05:06:21 -0600 )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

Stats

Asked: 2013-02-21 02:12:14 -0600

Seen: 911 times

Last updated: Feb 25 '13