private void setTangoListeners() {
// Select coordinate frame pairs
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE));
private void setTangoListeners() {
// Select coordinate frame pairs
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE));
// Add a listener for Tango pose data
mTango.connectListener(framePairs, new OnTangoUpdateListener() {
@Override
public void onPoseAvailable(TangoPoseData pose) {
// Format Translation and Rotation data
final String translationMsg = String.format(sTranslationFormat,
pose.translation[0], pose.translation[1],
pose.translation[2]);
final String rotationMsg = String.format(sRotationFormat,
pose.rotation[0], pose.rotation[1], pose.rotation[2],
pose.rotation[3]);
// Output to LogCat
String logMsg = translationMsg + " | " + rotationMsg;
Log.i(TAG, logMsg);
final double deltaTime = (pose.timestamp - mPreviousTimeStamp)
* SECS_TO_MILLISECS;
mPreviousTimeStamp = pose.timestamp;
mTimeToNextUpdate -= deltaTime;
// Throttle updates to the UI based on UPDATE_INTERVAL_MS.
if (mTimeToNextUpdate < 0.0) {
mTimeToNextUpdate = UPDATE_INTERVAL_MS;
// Display data in TextViews. This must be done inside a
// runOnUiThread call because
// it affects the UI, which will cause an error if performed
// from the Tango
// service thread
runOnUiThread(new Runnable() {
@Override
public void run() {
mRotationTextView.setText(rotationMsg);
mTranslationTextView.setText(translationMsg);
}
});
}
}
The above code gives us translation and rotation coordinate in 3D. As we move or change the orientation of tango tablet the mtango. setclicklistener is called and the inside code run and update the coordinates..
What I am not able to understand is that how is the coordinate is getting updated when setclicklistener
is called? can anyone explain me the working of the code inside the onposeavailable()
?
Well, setTangoListener()
is only called once, but when doing so you instantiate a listener where you override the onPoseAvailable()
function, which in turn will be called everytime the listener detects that the Tango has updated its pose with a TangoPoseData
object (pose
) as argument containing the latest pose data.
So the actual changing of the pose information is done in the tango core and accessible for you through the pose
argument in the listener. Therefore, when you access the translation and rotation it will already be updated.
So you are right in the fact that the pose is never updated within the onPoseAvailable()
function since it is already done when it is called. The only thing that happens inside onPoseAvailable()
is that you read the rotation and translation values and put them in strings that can be displayed through first LogCat. Thereafter it checks how long time has passed since last update and if it is time for it updates the textViews (would be difficult to read if you updated it everytime a new pose is available).
I hope it helps :)