Skip to content
This repository was archived by the owner on Mar 2, 2018. It is now read-only.

Commit e4ea49e

Browse files
committed
Merge pull request #52 from googlesamples/release-capella
Release capella
2 parents fdfd71c + 15b6584 commit e4ea49e

File tree

21 files changed

+335
-372
lines changed

21 files changed

+335
-372
lines changed

AreaLearningJava/app/src/main/java/com/projecttango/experiments/javaarealearning/AreaLearningActivity.java

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818

1919
import com.google.atap.tangoservice.Tango.OnTangoUpdateListener;
2020
import com.google.atap.tangoservice.Tango;
21-
import com.google.atap.tangoservice.TangoAreaDescriptionMetaData;
2221
import com.google.atap.tangoservice.TangoConfig;
2322
import com.google.atap.tangoservice.TangoCoordinateFramePair;
2423
import com.google.atap.tangoservice.TangoErrorException;
2524
import com.google.atap.tangoservice.TangoEvent;
26-
import com.google.atap.tangoservice.TangoException;
2725
import com.google.atap.tangoservice.TangoInvalidException;
2826
import com.google.atap.tangoservice.TangoOutOfDateException;
2927
import com.google.atap.tangoservice.TangoPoseData;
@@ -34,7 +32,6 @@
3432
import android.content.Intent;
3533
import android.content.pm.PackageInfo;
3634
import android.content.pm.PackageManager.NameNotFoundException;
37-
import android.os.AsyncTask;
3835
import android.os.Bundle;
3936
import android.util.Log;
4037
import android.view.MotionEvent;
@@ -43,14 +40,14 @@
4340
import android.widget.TextView;
4441
import android.widget.Toast;
4542

46-
import java.text.DecimalFormat;
47-
import java.util.ArrayList;
48-
4943
import com.projecttango.tangoutils.TangoPoseUtilities;
5044

5145
import org.rajawali3d.surface.IRajawaliSurface;
5246
import org.rajawali3d.surface.RajawaliSurfaceView;
5347

48+
import java.text.DecimalFormat;
49+
import java.util.ArrayList;
50+
5451
/**
5552
* Main Activity class for the Area Learning API Sample. Handles the connection to the Tango service
5653
* and propagation of Tango pose data to OpenGL and Layout views. OpenGL rendering logic is
@@ -60,7 +57,7 @@ public class AreaLearningActivity extends Activity implements View.OnClickListen
6057
SetADFNameDialog.CallbackListener, SaveAdfTask.SaveAdfListener {
6158

6259
private static final String TAG = AreaLearningActivity.class.getSimpleName();
63-
private static final int SECONDS_TO_MILLI = 1000;
60+
private static final int SECS_TO_MILLISECS = 1000;
6461
private Tango mTango;
6562
private TangoConfig mConfig;
6663
private TextView mTangoEventTextView;
@@ -102,6 +99,9 @@ public class AreaLearningActivity extends Activity implements View.OnClickListen
10299
private double mAdf2DevicePreviousPoseTimeStamp;
103100
private double mAdf2StartPreviousPoseTimeStamp;
104101

102+
private double mPreviousPoseTimeStamp;
103+
private double mTimeToNextUpdate = UPDATE_INTERVAL_MS;
104+
105105
private boolean mIsRelocalized;
106106
private boolean mIsLearningMode;
107107
private boolean mIsConstantSpaceRelocalize;
@@ -113,9 +113,10 @@ public class AreaLearningActivity extends Activity implements View.OnClickListen
113113
private SaveAdfTask mSaveAdfTask;
114114

115115
private TangoPoseData[] mPoses;
116-
private static final int UPDATE_INTERVAL_MS = 100;
117-
private static final DecimalFormat mThreeDecimalFormat = new DecimalFormat("00.000");
118-
private static final Object mSharedLock = new Object();
116+
private static final double UPDATE_INTERVAL_MS = 100.0;
117+
private static final DecimalFormat FORMAT_THREE_DECIMAL = new DecimalFormat("00.000");
118+
119+
private final Object mSharedLock = new Object();
119120

120121
@Override
121122
protected void onCreate(Bundle savedInstanceState) {
@@ -140,8 +141,6 @@ protected void onCreate(Bundle savedInstanceState) {
140141
mStart2DevicePoseCount = 0;
141142
mAdf2DevicePoseCount = 0;
142143
mAdf2StartPoseCount = 0;
143-
144-
startUIThread();
145144
}
146145

147146
/**
@@ -405,7 +404,6 @@ public void onPoseAvailable(TangoPoseData pose) {
405404
// UI loop doesn't interfere while Pose call back is updating
406405
// the data.
407406
synchronized (mSharedLock) {
408-
float[] translation = pose.getTranslationAsFloats();
409407
// Check for Device wrt ADF pose, Device wrt Start of Service pose,
410408
// Start of Service wrt ADF pose(This pose determines if device
411409
// the is relocalized or not).
@@ -421,7 +419,7 @@ public void onPoseAvailable(TangoPoseData pose) {
421419
// Calculate time difference between current and last available Device wrt
422420
// ADF pose.
423421
mAdf2DevicePoseDelta = (pose.timestamp - mAdf2DevicePreviousPoseTimeStamp)
424-
* SECONDS_TO_MILLI;
422+
* SECS_TO_MILLISECS;
425423
mAdf2DevicePreviousPoseTimeStamp = pose.timestamp;
426424
if (mIsRelocalized) {
427425
updateRenderer = true;
@@ -438,7 +436,7 @@ public void onPoseAvailable(TangoPoseData pose) {
438436
// Calculate time difference between current and last available Device wrt
439437
// SS pose.
440438
mStart2DevicePoseDelta = (pose.timestamp - mStart2DevicePreviousPoseTimeStamp)
441-
* SECONDS_TO_MILLI;
439+
* SECS_TO_MILLISECS;
442440
mStart2DevicePreviousPoseTimeStamp = pose.timestamp;
443441
if (!mIsRelocalized) {
444442
updateRenderer = true;
@@ -456,7 +454,7 @@ public void onPoseAvailable(TangoPoseData pose) {
456454
// Calculate time difference between current and last available SS wrt ADF
457455
// pose.
458456
mAdf2StartPoseDelta = (pose.timestamp - mAdf2StartPreviousPoseTimeStamp)
459-
* SECONDS_TO_MILLI;
457+
* SECS_TO_MILLISECS;
460458
mAdf2StartPreviousPoseTimeStamp = pose.timestamp;
461459
if (pose.statusCode == TangoPoseData.POSE_VALID) {
462460
mIsRelocalized = true;
@@ -467,6 +465,24 @@ public void onPoseAvailable(TangoPoseData pose) {
467465
}
468466
}
469467
}
468+
469+
final double deltaTime = (pose.timestamp - mPreviousPoseTimeStamp) * SECS_TO_MILLISECS;
470+
mPreviousPoseTimeStamp = pose.timestamp;
471+
mTimeToNextUpdate -= deltaTime;
472+
473+
if (mTimeToNextUpdate < 0.0) {
474+
mTimeToNextUpdate = UPDATE_INTERVAL_MS;
475+
476+
runOnUiThread(new Runnable() {
477+
@Override
478+
public void run() {
479+
synchronized (mSharedLock) {
480+
updateTextViews();
481+
}
482+
}
483+
});
484+
}
485+
470486
if (updateRenderer) {
471487
mRenderer.updateDevicePose(pose, mIsRelocalized);
472488
}
@@ -527,42 +543,6 @@ private void showSetADFNameDialog() {
527543
setADFNameDialog.show(manager, "ADFNameDialog");
528544
}
529545

530-
/**
531-
* Create a separate thread to update Log information on UI at the specified interval of
532-
* UPDATE_INTERVAL_MS. This function also makes sure to have access to the mPoses atomically.
533-
*/
534-
private void startUIThread() {
535-
new Thread(new Runnable() {
536-
@Override
537-
public void run() {
538-
while (true) {
539-
try {
540-
Thread.sleep(UPDATE_INTERVAL_MS);
541-
runOnUiThread(new Runnable() {
542-
@Override
543-
public void run() {
544-
try {
545-
synchronized (mSharedLock) {
546-
547-
if (mPoses == null) {
548-
return;
549-
} else {
550-
updateTextViews();
551-
}
552-
}
553-
} catch (NullPointerException e) {
554-
e.printStackTrace();
555-
}
556-
}
557-
});
558-
} catch (InterruptedException e) {
559-
e.printStackTrace();
560-
}
561-
}
562-
}
563-
}).start();
564-
}
565-
566546
/**
567547
* Updates the text view in UI screen with the Pose. Each pose is associated with Target and
568548
* Base Frame. We need to check for that pair and update our views accordingly.
@@ -571,34 +551,31 @@ private void updateTextViews() {
571551
// Allow clicking of the save button only when Tango is localized to the current ADF.
572552
mSaveAdfButton.setEnabled(mIsRelocalized);
573553

574-
if (mPoses[0] != null
575-
&& mPoses[0].baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
554+
if (mPoses[0] != null && mPoses[0].baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
576555
&& mPoses[0].targetFrame == TangoPoseData.COORDINATE_FRAME_DEVICE) {
577-
mAdf2DeviceTranslationTextView.setText(TangoPoseUtilities.getTranslationString(mPoses[0], mThreeDecimalFormat));
578-
mAdf2DeviceQuatTextView.setText(TangoPoseUtilities.getQuaternionString(mPoses[0], mThreeDecimalFormat));
556+
mAdf2DeviceTranslationTextView.setText(TangoPoseUtilities.getTranslationString(mPoses[0], FORMAT_THREE_DECIMAL));
557+
mAdf2DeviceQuatTextView.setText(TangoPoseUtilities.getQuaternionString(mPoses[0], FORMAT_THREE_DECIMAL));
579558
mAdf2DevicePoseStatusTextView.setText(TangoPoseUtilities.getStatusString(mPoses[0]));
580559
mAdf2DevicePoseCountTextView.setText(Integer.toString(mAdf2DevicePoseCount));
581-
mAdf2DevicePoseDeltaTextView.setText(mThreeDecimalFormat.format(mAdf2DevicePoseDelta));
560+
mAdf2DevicePoseDeltaTextView.setText(FORMAT_THREE_DECIMAL.format(mAdf2DevicePoseDelta));
582561
}
583562

584-
if (mPoses[1] != null
585-
&& mPoses[1].baseFrame == TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE
563+
if (mPoses[1] != null && mPoses[1].baseFrame == TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE
586564
&& mPoses[1].targetFrame == TangoPoseData.COORDINATE_FRAME_DEVICE) {
587-
mStart2DeviceTranslationTextView.setText(TangoPoseUtilities.getTranslationString(mPoses[1], mThreeDecimalFormat));
588-
mStart2DeviceQuatTextView.setText(TangoPoseUtilities.getQuaternionString(mPoses[1], mThreeDecimalFormat));
565+
mStart2DeviceTranslationTextView.setText(TangoPoseUtilities.getTranslationString(mPoses[1], FORMAT_THREE_DECIMAL));
566+
mStart2DeviceQuatTextView.setText(TangoPoseUtilities.getQuaternionString(mPoses[1], FORMAT_THREE_DECIMAL));
589567
mStart2DevicePoseStatusTextView.setText(TangoPoseUtilities.getStatusString(mPoses[1]));
590568
mStart2DevicePoseCountTextView.setText(Integer.toString(mStart2DevicePoseCount));
591-
mStart2DevicePoseDeltaTextView.setText(mThreeDecimalFormat.format(mStart2DevicePoseDelta));
569+
mStart2DevicePoseDeltaTextView.setText(FORMAT_THREE_DECIMAL.format(mStart2DevicePoseDelta));
592570
}
593571

594-
if (mPoses[2] != null
595-
&& mPoses[2].baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
572+
if (mPoses[2] != null && mPoses[2].baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
596573
&& mPoses[2].targetFrame == TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE) {
597-
mAdf2StartTranslationTextView.setText(TangoPoseUtilities.getTranslationString(mPoses[2], mThreeDecimalFormat));
598-
mAdf2StartQuatTextView.setText(TangoPoseUtilities.getQuaternionString(mPoses[2], mThreeDecimalFormat));
574+
mAdf2StartTranslationTextView.setText(TangoPoseUtilities.getTranslationString(mPoses[2], FORMAT_THREE_DECIMAL));
575+
mAdf2StartQuatTextView.setText(TangoPoseUtilities.getQuaternionString(mPoses[2], FORMAT_THREE_DECIMAL));
599576
mAdf2StartPoseStatusTextView.setText(TangoPoseUtilities.getStatusString(mPoses[2]));
600577
mAdf2StartPoseCountTextView.setText(Integer.toString(mAdf2StartPoseCount));
601-
mAdf2StartPoseDeltaTextView.setText(mThreeDecimalFormat.format(mAdf2StartPoseDelta));
578+
mAdf2StartPoseDeltaTextView.setText(FORMAT_THREE_DECIMAL.format(mAdf2StartPoseDelta));
602579
}
603580
}
604581
}
1.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)