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

strange question(Callbacks are not called) #104

Open
yangzhiqian opened this issue Aug 29, 2017 · 0 comments
Open

strange question(Callbacks are not called) #104

yangzhiqian opened this issue Aug 29, 2017 · 0 comments

Comments

@yangzhiqian
Copy link

yangzhiqian commented Aug 29, 2017

I'm writing an app with Tango and getting a strange bug.
My program successfully connected to the tango service,and i have setup a callback with "mTango.connectListener(framePairs, new Tango.TangoUpdateCallback() {...});",but i can not get any tango datas because the callback have never been called.
here is my main code
` private void bindTangoService() {
Log.d(TAG, "正在绑定Tango 服务");
if (mIsConnected) {
return;
}
mTango = new Tango(mContext, new Runnable() {
@OverRide
public void run() {
synchronized (TangoAR.this) {
try {
TangoSupport.initialize();
if (mConfig == null) {
mConfig = setupTangoConfig(mTango, false, false);
}
mTango.connect(mConfig);
startupTango();
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 (mView.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;
            mTangoPoseData = TangoSupport.getPoseAtTime(
                    mTangoTime,
                    TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
                    TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
                    TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
                    TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
                    mDisplayRotation);
            if (mTangoPoseData.statusCode == TangoPoseData.POSE_VALID) {
                //更新地球位置(实际改变的opengl中camera的位置)
                mRenderer.onPoseUpdated(mTangoPoseData);
                mView.updatePose(mTangoPoseData);
                Log.d(TAG, "setupRenderer-onPoseUpdated");
            }
        }

        @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");
}`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant