美文网首页
ros android_core学习笔记

ros android_core学习笔记

作者: 虚无一代 | 来源:发表于2019-03-30 19:54 被阅读0次

本笔记以app的页面为导向逐步介绍连接master——启动服务的过程

1. 连接master

当前活动继承了RosActivity类:
public class MainActivity extends RosActivity
和获取master的uri有关的都在RosActivity类中,因此只关注该类中的代码:

  1. 首先,启动了onStart()
  2. 然后启动了bindNodeMainExecutorService()方法
  3. 在bindNodeMainExecutorService内部,建立了服务:NodeMainExecutorService
    同时,绑定了客户端nodeMainExecutorServiceConnection
  4. nodeMainExecutorServiceConnection内部,如果满足一系列要求,并且此时还没有获得masterUri,就会启动startMasterChooser()方法。如果已经有了,就会调用init()抽象方法。
  5. startMasterChooser()方法内部就会通过startActivityForResult调用MasterChooser的实例masterChooserActivity得到其result。
  6. 对该result的处理是在OnActivityResultCallback内部进行的,会启动master

2. 发布消息

获得MasterUri之后就会启动init()。由于是抽象方法,所以init方法会在你的app的MainActivity中重写:

//pubsub中的代码
  protected void init(NodeMainExecutor nodeMainExecutor) {
    //Talker类来自rosjava的tutorial
    talker = new Talker();

    // At this point, the user has already been prompted to either enter the URI
    // of a master to use or to start a master locally.

    // The user can easily use the selected ROS Hostname in the master chooser
    // activity.
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(getRosHostname());
    nodeConfiguration.setMasterUri(getMasterUri());
    nodeMainExecutor.execute(talker, nodeConfiguration);
    // The RosTextView is also a NodeMain that must be executed in order to
    // start displaying incoming messages.
    nodeMainExecutor.execute(rosTextView, nodeConfiguration);
  }

相关文章

网友评论

      本文标题:ros android_core学习笔记

      本文链接:https://www.haomeiwen.com/subject/gsksbqtx.html