码迷,mamicode.com
首页 > 编程语言 > 详细

Google Tango Java SDK开发:Motion Tracking 运动追踪

时间:2017-07-15 23:00:40      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:please   auto   apach   error   ons   concepts   app   lis   always   

 

Java API Motion Tracking Tutorial运动追踪教程

This page describes how the Java API handles motion tracking. 该页面描述了如何使用Java API处理运动追踪。

Lifecycle 生命周期

The normal motion tracking system lifecycle consists of three states: TangoPoseData.POSE_INITIALIZINGTangoPoseData.POSE_VALID, and TangoPoseData.POSE_INVALID. In the POSE_INITIALIZING state, the system is not yet ready and pose data is not available. In the POSE_VALID state, the system is functioning normally. In the POSE_INVALID state, the system believes its estimate was invalid and needs to be reinitialized. A fourth state, POSE_UNKNOWN, is used for all other cases.

Should the pose data become POSE_INVALID, the motion tracking system can be reinitialized in two ways. If config_enable_auto_recovery was set to true, the system will immediately enter the POSE_INITIALIZINGstate. It will use the last valid pose as the starting point after recovery. IfTangoConfig.KEY_BOOLEAN_AUTORECOVERY was set to false, the system will essentially pause and always return poses as POSE_INVALID until Tango.resetMotionTracking() is called. Unlike auto recovery, this will also reset the starting point after recovery back to the origin.

The lifecycle state is recorded in the TangoPoseData object‘s statusCode.

For more information, although the page is based around the C API, please see our Device Pose concepts page.

Configuration

In order to use motion tracking, your TangoConfig must have KEY_BOOLEAN_MOTIONTRACKING set to true. If you are using the default TangoConfig as your starting point, it is already set to true.

You also have the option to set KEY_BOOLEAN_AUTORECOVERY. In the default TangoConfig, this is set to true. See the Lifecycle section for the behavior of this parameter.

Getting pose data

There are two coordinate frame pair options for basic motion tracking: device with respect to start of service, and device with respect to the previous device pose. With start of service, the device‘s pose is relative to the position where the motion tracking system initialized. You can receive pose data in both the callback and polling forms. With previous device pose, the device‘s pose is relative to its last position. Pose data is only available as a callback.

Callback-based

If you are using the callback-based approach, you must define the coordinate frame pairs you are interested in and construct your onPoseAvailable() callback.

You also have to implement onXyzIjAvailable and onTangoEvent, because the Tango.OnTangoUpdateListenerinterface requires an implementation for all three of those methods.

 
private void setTangoListeners() {
    final ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
    framePairs.add(new TangoCoordinateFramePair(
        TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
        TangoPoseData.COORDINATE_FRAME_DEVICE));

    // Listen for new Tango data
    mTango.connectListener(framePairs, new OnTangoUpdateListener() {

        @Override
        public void onPoseAvailable(final TangoPoseData pose) {
            // Process pose data from device with respect to start of service
        }

        @Override
        public void onXyzIjAvailable(TangoXyzIjData arg0) {
            // We need this callback even if we don‘t use it
        }

        @Override
        public void onTangoEvent(final TangoEvent event) {
            // This callback also has to be here
        }
    });
}

Polling-based

In the polling-based approach, you must first specify the coordinate frame pair you are interested in. For simple motion tracking, this will always be TangoPoseData.COORDINATE_FRAME_DEVICE with respect toTangoPoseData.COORDINATE_FRAME_START_OF_SERVICE.

 
// Define what motion is requested.
TangoCoordinateFramePair frames_of_reference;
frames_of_reference.baseFrame = TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE;
frames_of_reference.targetFrame = TangoPoseData.COORDINATE_FRAME_DEVICE;

Then call `Tango.getPoseAtTime() as desired. In the example below, the timestamp is set to 0.0 to get the latest pose. If you specify a specific timestamp, the system will return an interpolated pose at that exact time. Timestamps are relative to the device boot.

 
new Thread(new Runnable() {
    final int pollingUpdatePeriodMilliseconds = 66;

    @Override
    public void run() {
        while (true) {
            try {
                 Thread.sleep(pollingUpdatePeriodMilliseconds);
            } catch (InterruptedException e) {
                 e.printStackTrace();
            }
            try {
                final TangoPoseData queryPoseStartDevice =
                    mTango.getPoseAtTime(0.0, frames_of_reference);
            } catch (TangoErrorException e) {
                e.printStackTrace();
            }
        }
    }
}).start();

Google Tango Java SDK开发:Motion Tracking 运动追踪

标签:please   auto   apach   error   ons   concepts   app   lis   always   

原文地址:http://www.cnblogs.com/2008nmj/p/7185523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!