Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Primi passi con Tango

Primi passi con Tango

Cos'è Project Tango di Google? Introduzione alla sdk in Java per Android

Michelantonio Trizio

November 24, 2016
Tweet

More Decks by Michelantonio Trizio

Other Decks in Technology

Transcript

  1. onCreate() ... // Create a new Tango Configuration and enable

    the MotionTracking API mConfig = new TangoConfig(); mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT); ...
  2. mTango.connectListener(framePairs, new OnTangoUpdateListener() { @Override public void onTangoEvent(final TangoEvent event)

    { if (event.eventKey.equals(TangoEvent.DESCRIPTION_FISHEYE_OVER_EXPOSED) { // handle the Fisheye camera issue } if (event.eventKey.equals(TangoEvent.DESCRIPTION_TOO_FEW_FEATURES_TRACKED) // handle having too few features } // ... } }
  3. 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 } // TODO: Define other overrides });
  4. // 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;
  5. new Thread(new Runnable() { final int pollingUpdatePeriodMilliseconds = 66; @Override

    public void run() { while (true) { try { Thread.sleep(pollingUpdatePeriodMilliseconds); final TangoPoseData queryPoseStartDevice = mTango.getPoseAtTime(0.0, frames_of_reference); } catch (TangoErrorException e) { e.printStackTrace(); } } } }).start();
  6. onCreate() ... // Create a new Tango Configuration with Depth

    Perception API enabled mConfig = new TangoConfig(); mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT); mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true); ...
  7. private void logPointCloud(TangoPointCloudData pointCloudData) { StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append("Point count: " + pointCloudData.numPoints); stringBuilder.append(". Average depth (m): " + calculateAveragedDepth(pointCloudData.points, pointCloudData.numPoints)); Log.i(TAG, stringBuilder.toString()); } private float calculateAveragedDepth(FloatBuffer pointCloudBuffer, int numPoints) { float totalZ = 0; float averageZ = 0; if (numPoints != 0) { int numFloats = 4 * numPoints; for (int i = 2; i < numFloats; i = i + 4) { totalZ = totalZ + pointCloudBuffer.get(i); } averageZ = totalZ / numPoints; } return averageZ; }
  8. onCreate() ... // Create a new Tango Configuration with Depth

    Perception API enabled mConfig = new TangoConfig(); mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT); mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_LEARNINGMODE, true); ...
  9. ArrayList<String> fullUUIDList = new ArrayList<String>(); // Returns a list of

    ADFs with their UUIDs fullUUIDList = mTango.listAreaDescriptions(); // Load the latest ADF if ADFs are found. if (fullUUIDList.size() > 0) { mConfig.putString(TangoConfig.KEY_STRING_AREADESCRIPTION, fullUUIDList.get(fullUUIDList.size() - 1)); }
  10. final ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>(); framePairs.add(new TangoCoordinateFramePair( TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, 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 } // TODO: Define other overrides });
  11. final ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>(); framePairs.add(new TangoCoordinateFramePair( TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE));

    // 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 } // TODO: Define other overrides });
  12. @Override public void onPoseAvailable(TangoPoseData pose) { if (pose.baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION

    && pose.targetFrame == TangoPoseData.COORDINATE_FRAME_DEVICE) { // Process new ADF to device pose data. } else if (pose.baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION && pose.targetFrame == TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE) { // Process new localization. }