没有调用回调

时间:2017-08-29 10:01:48

标签: google-project-tango

我正在用Tango编写一个应用程序并得到一个奇怪的bug 我的程序成功连接到探戈服务,我已经设置了一个回调“mTango.connectListener(framePairs,new Tango.TangoUpdateCallback(){...});”但我无法得到任何探戈数据因为回调有从来没有被叫过 这是我的主要代码

 private void bindTangoService() {
    Log.d(TAG, "正在绑定Tango 服务");
    if (mIsConnected) {
        return;
    }
    mTango = new Tango(mContext, new Runnable() {
        @Override
        public void run() {
            synchronized (TangoAR.this) {
                try {
                    mConfig = setupTangoConfig(mTango, false, false);
                    mTango.connect(mConfig);
                    startupTango();
                    TangoSupport.initialize(mTango);
                    mIsConnected = true;
                    onRotationUpdated(Util.getDisplayRotation(mContext));
                    makeToast("tango 连接成功");
                    Log.d(TAG, "tango 连接成功");
                } catch (TangoOutOfDateException e) {
                    makeToast("TangoOutOfDateException");
                } catch (Throwable e) {
                    makeToast(e.getMessage());
                }
            }
        }
    });
}

private TangoConfig setupTangoConfig(Tango tango, boolean isLearningMode, boolean isLoadAdf) {
    Log.d(TAG, "setupTangoConfig");
    TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
    //在tango连接后使用相机必须使用true
    config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, false);
    //motion
    config.putBoolean(TangoConfig.KEY_BOOLEAN_MOTIONTRACKING, true);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_AUTORECOVERY, true);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true);
    //depth
    config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true);
    config.putInt(TangoConfig.KEY_INT_DEPTH_MODE, TangoConfig.TANGO_DEPTH_MODE_POINT_CLOUD);//使用点云,不使用老版本的TANGO_DEPTH_MODE_XYZ_IJ

    //area learning
    if (isLearningMode) {
        //区域学习需要权限授权
        if (checkAndRequestTangoPermissions(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE)) {
            Log.d(TAG, "PERMISSIONTYPE_ADF_LOAD_SAVE 开启");
            config.putBoolean(TangoConfig.KEY_BOOLEAN_LEARNINGMODE, true);
        }
    }
    if (isLoadAdf) {
        //加载ADF
        ArrayList<String> fullUuidList;
        fullUuidList = tango.listAreaDescriptions();
        if (fullUuidList.size() > 0) {
            config.putString(TangoConfig.KEY_STRING_AREADESCRIPTION,
                    fullUuidList.get(fullUuidList.size() - 1));
        }
    }
    return config;
}

private void startupTango() {
    Log.d(TAG, "startupTango");
    ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<>();
    //设置参考系,0,0,0点为tango服务启动时设备的位置,测量目标为设备的位置
    Log.d(TAG, "startup");
    framePairs.add(new TangoCoordinateFramePair(
            TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
            TangoPoseData.COORDINATE_FRAME_DEVICE));
    Log.d(TAG, "startup-listener");
    mTango.connectListener(framePairs, new Tango.TangoUpdateCallback() {
        @Override
        public void onPoseAvailable(final TangoPoseData pose) {
            //motion
            Log.d(TAG, "onPoseAvailable");
            //获取手机新的状态
            mTangoTime = pose.timestamp;
            TangoPoseData poseData = TangoSupport.getPoseAtTime(
                    mTangoTime,
                    TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
                    TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
                    TangoSupport.ENGINE_OPENGL,
                    TangoSupport.ENGINE_OPENGL,
                    mDisplayRotation);
            if (poseData.statusCode == TangoPoseData.POSE_VALID) {
                mTangoPoseData = poseData;
            }
        }

        @Override
        public void onPointCloudAvailable(TangoPointCloudData pointCloud) {
            //记录当扫描到到的深度信息
            mPointCloudManager.updatePointCloud(pointCloud);
            Log.d(TAG, "depth size:" + pointCloud.numPoints);
        }

        @Override
        public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
            Log.d(TAG, "onXyzIjAvailable");
        }

        @Override
        public void onFrameAvailable(int cameraId) {
            Log.d(TAG, "onFrameAvailable");
        }

        @Override
        public void onTangoEvent(TangoEvent event) {
            Log.d(TAG, event.eventValue);
        }
    });
    Log.d(TAG, "startup-listener-end");
}


mTango.connect(mConfig);成功执行,没有任何例外 我被这个问题困扰了三天。我需要一个英雄。谢谢大家 注意:后置摄像头不能用于探戈,因为我在其他地方使用它。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。对我来说,解决方案是请求权限:

startActivityForResult(
    Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING),
    Tango.TANGO_INTENT_ACTIVITYCODE);