How do I detect that localisation has occured?

2019-09-11 07:21发布

When utilising a Tango what would I use, callbacks or otherwise to detect when the devise has localised to a previously loaded ADF?

This is mainly for UI purposes in conjunction with Tango UX, telling a user to walk around an environment.

2条回答
淡お忘
2楼-- · 2019-09-11 07:52

Localization may be detected when your TangoPoseData with a frame of ADF comes back valid.

Look at the Tango Java examples of AreaLearningActivity with this simplified logic:

//tell tango to provide pose for ADF
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
        TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
        TangoPoseData.COORDINATE_FRAME_DEVICE));

//register a listener for the frames chosen
mTango.connectListener(framePairs, new OnTangoUpdateListener() {

  //listens for updates from tango pose
  public void onPoseAvailable(TangoPoseData pose) {

    //base frame of ADF provides coordinates relative to the origin of the ADF
    if (pose.baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
        && pose.targetFrame == TangoPoseData.COORDINATE_FRAME_DEVICE)

      //if the status is valid then localization has succeeded
      if(pose.statusCode == TangoPoseData.POSE_VALID){
        Log.i(TAG,"Successfully localized with ADF");
      }
    }
  }

Your config must indicate which ADF is of interest:

 config.putString(TangoConfig.KEY_STRING_AREADESCRIPTION,adfId);

This process is not easily observed from the code, but I discovered it debugging the AreaLearningActivity example. The Java API would benefit from a higher level of abstraction making the common scenario you requested more obvious and easier to use:

TangoLocalizer.builder().register(myListener).adfId(myAdfId).build();
查看更多
老娘就宠你
3楼-- · 2019-09-11 07:59

In Unity3D, you can use pose.status_code inside OnTangoPoseAvailable(TangoPoseData) for checking the checking the status (VALID/INVALID) of pose w.r.t. the coordinate frame pair defined. For Device Localization you need to set targetFrame as TANGO_COORDINATE_FRAME_DEVICE AND baseFrame as TANGO_COORDINATE_FRAME_AREA_DESCRIPTION

public void OnTangoPoseAvailable(TangoPoseData pose)
{
    // Define the frame-pair 
    if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION
        && pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE)
    {

    // Check if the pose is VALID or INVALID
        if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID)
        {
            ////......if pose is VALID
        }
        else 
        {
            ////......if pose is INVALID
        }
    }
}

You also need to load the ADF using m_tangoApplication.Startup (m_selectedADF); as well.

查看更多
登录 后发表回答