Java API Depth Perception Tutorial


In order to use depth perception, your TangoConfig must have KEY_BOOLEAN_DEPTH set to true. In the default TangoConfig, KEY_BOOLEAN_DEPTH is set to false.

try {
    mConfig = new TangoConfig();
    mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
    mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
} catch (TangoErrorException e) {
    // handle exception

Define the callback

The caller is responsible for allocating memory, which will be released after the callback function has finished.

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

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

        public void onXyzIjAvailable(TangoXyzIjData arg0) {
            byte[] buffer = new byte[xyzIj.xyzCount * 3 * 4];
            FileInputStream fileStream = new FileInputStream(
            try {
                        xyzIj.xyzParcelFileDescriptorOffset, buffer.length);
            } catch (IOException e) {
            // Do not process the buffer inside the callback because
            // you will not receive any new data while it processes

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

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

Define the onXYZijAvailable() callback. Do not do any expensive processing on the data within the callback; you will not receive new data until the callback returns.

Enviar comentarios sobre…