getting_started.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Getting started &mdash; android_core 0.1.0 documentation</title>
  7. <link rel="stylesheet" href="_static/haiku.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <link rel="stylesheet" href="_static/print.css" type="text/css" />
  10. <script type="text/javascript">
  11. var DOCUMENTATION_OPTIONS = {
  12. URL_ROOT: '',
  13. VERSION: '0.1.0',
  14. COLLAPSE_INDEX: false,
  15. FILE_SUFFIX: '.html',
  16. HAS_SOURCE: true
  17. };
  18. </script>
  19. <script type="text/javascript" src="_static/jquery.js"></script>
  20. <script type="text/javascript" src="_static/underscore.js"></script>
  21. <script type="text/javascript" src="_static/doctools.js"></script>
  22. <script type="text/javascript" src="_static/theme_extras.js"></script>
  23. <link rel="top" title="android_core 0.1.0 documentation" href="index.html" />
  24. <link rel="prev" title="Building" href="building.html" />
  25. </head>
  26. <body>
  27. <div class="header"><h1 class="heading"><a href="index.html">
  28. <span>android_core 0.1.0 documentation</span></a></h1>
  29. <h2 class="heading"><span>Getting started</span></h2>
  30. </div>
  31. <div class="topnav">
  32. <p>
  33. «&#160;&#160;<a href="building.html">Building</a>
  34. &#160;&#160;::&#160;&#160;
  35. <a class="uplink" href="index.html">Contents</a>
  36. </p>
  37. </div>
  38. <div class="content">
  39. <div class="section" id="getting-started">
  40. <span id="id1"></span><h1>Getting started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h1>
  41. <p>Before diving into ROS enabled Android application development, you should be
  42. familiar with <em class="xref std std-ref">rosjava</em> and <a class="reference external" href="http://developer.android.com/training/index.html">Android
  43. application development</a> in general. Note that any information regarding
  44. command-line adt and eclipse development is depracating - we have moved early
  45. to a gradle-<a class="reference external" href="http://wiki.ros.org/android/AndroidStudio">android studio</a> environment.</p>
  46. <div class="section" id="creating-a-new-android-application">
  47. <h2>Creating a new Android application<a class="headerlink" href="#creating-a-new-android-application" title="Permalink to this headline">¶</a></h2>
  48. <p>Refer to the <a class="reference external" href="http://wiki.ros.org/android">RosWiki</a> for tutorials.</p>
  49. </div>
  50. <div class="section" id="using-rosactivity">
  51. <span id="life-of-a-rosactivity"></span><h2>Using RosActivity<a class="headerlink" href="#using-rosactivity" title="Permalink to this headline">¶</a></h2>
  52. <p>The <a class="reference external" href="javadoc/org/ros/android/RosActivity.html#">RosActivity</a> class is the base class for all of
  53. your ROS enabled Android applications. Let&#8217;s consider the following example
  54. from the android_tutorial_pubsub package. In this example, we create a
  55. <a class="reference external" href="javadoc/org/ros/node/topic/Publisher.html#">Publisher</a> and a
  56. <a class="reference external" href="javadoc/org/ros/node/topic/Subscriber.html#">Subscriber</a> that will exchange &#8220;Hello, World&#8221;
  57. messages.</p>
  58. <p>On line 14, we extend <a class="reference external" href="javadoc/org/ros/android/RosActivity.html#">RosActivity</a>. When our
  59. <a class="reference external" href="http://developer.android.com/reference/android/app/Activity.html">activity</a> starts, the <a class="reference external" href="javadoc/org/ros/android/RosActivity.html#">RosActivity</a> super class will:</p>
  60. <ul class="simple">
  61. <li>start the <a class="reference external" href="javadoc/org/ros/android/NodeMainExecutorService.html#">NodeMainExecutorService</a> as a <a class="reference external" href="http://developer.android.com/reference/android/app/Service.html">service</a>
  62. in the <a class="reference external" href="http://developer.android.com/reference/android/app/Service.html#startForeground(int,android.app.Notification)">foreground</a>,</li>
  63. <li>launch the <a class="reference external" href="javadoc/org/ros/android/MasterChooser.html#">MasterChooser</a> activity to prompt the
  64. user to configure a master URI,</li>
  65. <li>and display an ongoing <a class="reference external" href="http://developer.android.com/reference/android/app/Notification.html">notification</a> informing the user that ROS nodes are
  66. running in the background.</li>
  67. </ul>
  68. <p>On line 22 we call the super constructor with two strings that become the title
  69. and ticker message of an Android <a class="reference external" href="http://developer.android.com/reference/android/app/Notification.html">notification</a>. The user may tap on the
  70. notification to shut down all ROS nodes associated with the application.</p>
  71. <p>Lines 28-30 should look familiar to Android developers. We load the <a class="reference external" href="http://developer.android.com/reference/android/app/Activity.html">activity</a>
  72. layout and get a reference to our
  73. <a class="reference external" href="javadoc/org/ros/android/view/RosTextView.html#">RosTextView</a> (more on that later).</p>
  74. <p>On line 42 we define the abstract method
  75. <a class="reference external" href="javadoc/org/ros/android/RosActivity.html#init(org.ros.node.NodeMainExecutor)">RosActivity.init</a>.
  76. This is where we kick off our <a class="reference external" href="javadoc/org/ros/node/NodeMain.html#">NodeMain</a>s and other
  77. business logic.</p>
  78. <p>And that&#8217;s it. <a class="reference external" href="javadoc/org/ros/android/RosActivity.html#">RosActivity</a> handles the rest of the
  79. application&#8217;s lifecycle management including:</p>
  80. <ul class="simple">
  81. <li>acquiring and releasing <a class="reference external" href="http://developer.android.com/reference/android/os/PowerManager.WakeLock.html">WakeLocks</a> and <a class="reference external" href="http://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html">WifiLocks</a>,</li>
  82. <li>binding and unbinding the <a class="reference external" href="javadoc/org/ros/android/NodeMainExecutorService.html#">NodeMainExecutorService</a>,</li>
  83. <li>and shutting down <a class="reference external" href="javadoc/org/ros/node/NodeMain.html#">NodeMain</a>s when the application exits.</li>
  84. </ul>
  85. </div>
  86. <div class="section" id="nodes-and-views">
  87. <h2>Nodes and Views<a class="headerlink" href="#nodes-and-views" title="Permalink to this headline">¶</a></h2>
  88. <p>The android_core stack provides a number of Android <a class="reference external" href="http://developer.android.com/reference/android/view/View.html">Views</a> which implement
  89. <a class="reference external" href="javadoc/org/ros/node/NodeMain.html#">NodeMain</a>. For example, let&#8217;s look at the implementation
  90. of <a class="reference external" href="javadoc/org/ros/android/view/RosTextView.html#">RosTextView</a>. The intent of this view is
  91. to display the textual representation of published messages.</p>
  92. <p>The view is configured with a topic name, message type, and a
  93. <a class="reference external" href="javadoc/org/ros/android/MessageCallable.html#">MessageCallable</a>. On line 40, in the
  94. <a class="reference external" href="javadoc/org/ros/node/NodeMain.html#onStart(Node)">NodeMain.onStart</a> method, we create a new
  95. <a class="reference external" href="javadoc/org/ros/node/topic/Subscriber.html#">Subscriber</a> for the configured topic and message
  96. type.</p>
  97. <p>When a new message arrives, we either use the configured callable to transform
  98. the incoming message to a string (line 49), or we use the default
  99. <tt class="docutils literal"><span class="pre">toString()</span></tt> method if no callable was configured (line 56). We then set the
  100. text of the view to the string representation of the incoming message.</p>
  101. <p>As with any other <a class="reference external" href="javadoc/org/ros/node/NodeMain.html#">NodeMain</a>, the
  102. <a class="reference external" href="javadoc/org/ros/android/view/RosTextView.html#">RosTextView</a> must be executed by the
  103. <a class="reference external" href="javadoc/org/ros/node/NodeMainExecutor.html#">NodeMainExecutor</a>. In the <a class="reference internal" href="#life-of-a-rosactivity"><em>Using RosActivity</em></a>
  104. example, we execute it in
  105. <a class="reference external" href="javadoc/org/ros/android/RosActivity.html#init(NodeMainExecutor)">RosActivity.init</a> and use the it to
  106. display incoming messages from the
  107. <a class="reference external" href="javadoc/org/ros/rosjava_tutorial_pubsub/Talker.html#">Talker</a> node.</p>
  108. </div>
  109. </div>
  110. </div>
  111. <div class="bottomnav">
  112. <p>
  113. «&#160;&#160;<a href="building.html">Building</a>
  114. &#160;&#160;::&#160;&#160;
  115. <a class="uplink" href="index.html">Contents</a>
  116. </p>
  117. </div>
  118. <div class="footer">
  119. &copy; Copyright 2013, Google, Inc..
  120. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
  121. </div>
  122. </body>
  123. </html>