Getting Started with the Tango Java API
In this tutorial, we'll go through setting up your build environment and compiling and running your first "Hello Tango" project using the Java API, which will run sample code and display the pose data from your device.
在本教程中,我们将尝试设置你的开发环境,使用Java API编译并运行你的第一个“Hello Tango”工程。它将运行样本代码,并且展示你的设备的姿态数据。
Prerequisites提前条件
To successfully follow this guide, you will need:要成功进行该指示,你需要:
-
Experience developing Android apps. If you have never created an Android app before, you can get started with our Building Your First App tutorial.体验开发Android应用。如果你从未创建过Android应用,你可以从这里开始。
-
The sample project. This includes the Tango Java API files, which you can find in the subfolder named TangoReleaseLibs after you download the project. For download instructions, see the next section.样例程序。它包括Tango Java API文件,下载完后你能在子文件夹名为TangoReleaseLibs中发现它。下载指南请看下一节。
-
A Tango Tablet Development Kit. You can build the code without one, but you won't be able to run it.一个Tango平板开发套件。没有它你也可以生成项目,但是你没办法运行它。
Download the sample project 下载示例项目
The sample project is hosted on GitHub. You can download it as a zip file or use git to clone the repository:样例项目是在Github上保管。你可以以zip文件的形式下载或者使用git克隆该仓库:
git clone https://github.com/googlesamples/tango-examples-java.git
You should now have a directory called tango-examples-java
on your machine. Within this directory you should see a subdirectory called java_basic_examples
, which contains the code for this guide.现在你应该有一个叫tango-examples-java的目录。在该目录中你应该看到一个叫java_basic_examples的子目录。它包含本向导的代码。
Import the project into Android Studio将工程导入到Android Studio中
-
Do one of the following: 做下面中的一个:
- Open Android Studio.打开Android Studio
- If you are already in Android Studio with a project loaded, close the project.如果你已经在Android Studio中打开一个项目,那么关闭该项目。
Either action takes you to the Welcome to Android Studio screen.任何一个都会带你到Android Studio的欢迎界面。
-
Select Import Project (Eclipse ADT, Gradle, etc.). In older versions of Android Studio, this may be Import Non-Android Studio project or simply Import Project. 选择Import Project导入项目。在其他版本的Android Studio中,这可能是Import Non-Android Studio project导入非Android Studio项目或仅仅是Import Project导入项目。
-
In the Select Eclipse or Gradle Project to Import dialog, navigate to the repository you just cloned. Choose the
java_basic_examples
directory and then click OK.在导入对话框,跳转到你刚刚克隆的仓库。选择java_basic_examples目录然后单击OK。
Connect your device连接你的设备
If you haven't already connected your Tango device to your computer, you should do so now.如果你还没有连接你的Tango设备到你的计算机,你应该现在连接上。
Tango手机USB驱动C:\Users\Administrator\AppData\Local\Android\Sdk\extras\google\usb_driver
Build and run an application建立并运行一个应用
Within the basic examples project you loaded, you have a choice of several different "hello"-style apps to build and run. For this tutorial, we'll choose "Hello Motion Tracking."
在你已经加载的基本样本项目中,你有几个不同的“hello”类型的应用建立和运行。对本教程,我们选择“Hello Motion Tracking”。
-
On the toolbar, view the Run/Debug Configuration field and make sure hello_motion_tracking is the active configuration. If it is not, click the field and select it.在工具栏中,查看Run/Debug配置栏中确保hello_motion_tracking是活动配置。如果不是,请点击该区域选择它。
-
Do one of the following:做下面的一个:
- On the Run menu, click Run.在运行菜单,点击Run运行。
- On the toolbar, click the Run button (the green arrow).
-
In the Device Chooser dialog, select Choose a running device, then select your Tango tablet, and then click OK.
See logcat for the raw pose data查看logcat中的原始姿态数据
You can see logcat output automatically in the bottom part of Android Studio.你可以在Android Studio的下部看到自动输出的logcat。
If you want to see it in your terminal, type如果你想在你的终端看到,输入:
adt_path/sdk/platform-tools/adb logcat
You will see the pose data being printed in your terminal:你将看到在你的终端打印的姿态数据(平移xyz/旋转/比例尺?):
I/MainActivity( 6010): Translation: 0.020329, 0.013915, -0.008571 | Rotation: 0.581630, 0.014597, -0.021857, 0.813029
Add to your own project添加到你自己的项目中
The Tango SDK for Java components are distributed on Bintray and are available through the JCenter repository when using Maven.
支持Java组件的Tango SDK分布在Bintray中,在使用Maven时通过JCenter的仓库获取。
-
First, add
jcenter()
to yourbuild.gradle
file so Gradle can find the AARs. For example: 首先,添加jcenter()到你的build.gradle文件中,从而Gradle可以找到AAR。allprojects {
repositories {
jcenter()
}
} -
Add the appropriate dependencies to the
build.gradle
files in your modules. You can determine this by looking at the samples'build.gradle
files to see what each one needs. For example, our motion tracking sample uses: 将合适的依赖添加到你的模块中的build.gradle文件中。你可以看一下样例“build.gradle”文件看一下每一个都需要什么。例如,我们的motion tracking运动追踪样例需要:dependencies {
compile 'com.google.tango:sdk-base:LATEST_VERSION'
compile 'com.google.tango:support-base:LATEST_VERSION'
}The latest version looks like
1.51
and can be found on the downloads page. This code indicates that an application similar to the motion tracking sample needs sdk-base and support-base. This will also recursively fetch dependent libraries. 最新版本比如1.51,可以在下载页找到。该代码显示了类似于motion tracking的应用需要sdk-base和support-base两个开发包。这也会递归地获取依赖库。
Once this is done for all of the required libraries, you will be able to reference code in the Tango SDK in your app. 一旦对于所有的所需的类库都完成了,你将会能够引用Tango SDK中的代码。
If you are using your own build system, the Tango libraries are also available from the downloads page.如果你想使用你自己的编译系统,Tango类库也可以在下载页面下载。
Next steps 接下来
Now that you have learned how to set up your environment for development with the Tango Java API, proceed to the following links to learn how to use specific features of Tango in your app:你已经学会如何设置你的Tango Java API的开发环境了,继续下面的链接学习如何使用Tango特定的特征吧:
- Configure and Connect 配置和连接
- Motion Tracking 运动追踪
- Area Learning 区域学习
- Depth Perception 深度感知
- User Permissions 用户允许
Also, take a look at our code samples on Github. 然后看一下我们在Github托管的代码例子。