Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 138 forks source link

Unity - Differences between methods ResetSession and Stop/Start session #302

Closed Silloty1 closed 2 years ago

Silloty1 commented 2 years ago

Hello everybody

Description

I am not sure if this is the place to ask, but I´m currently experiencing an issue and I am not sure what method to call. Indeed, during the app time, I sometimes have to Stop the ASA session, and restart it to continue the recognition of anchors. A problem that I have is that due to low connectivity, sometimes it seems like the ASA session is not started, even after recalling the awaited method RestartSession(). I wanted to know what is the exact difference between Restarting the ASA session and Stopping/Starting the session? Does it do the same? Also, does low connectivity can affect the start of a ASA session?

Thank you very much Steps to reproduce the issue Have low connectivity (Around Dowload 0.71 Mbps / Upload 0.17 Mbps). Can be reproduced with a bandwith limiter (developer option on iOS) Try to Start a Session Session not starting after calling RestartSession() method

Expected behavior Session is correctly started and anchor recognition can proceed

Thank you very much

**Development information

AR Device information (please complete the following information):

oafolabi-msft commented 2 years ago

Hi @Silloty1, thank you for the question. When you say RestartSession, do you mean reset. As stated in the documentation, calling reset, will clear all environmental data collected in the session and internal cached states. It is needed when tracking is lost.

Stop session stops the process of collecting environmental data and cancels any locate calls. It does not clear the environmental data collected so far.

Start session resumes the collection of environmental data.

In general, since Azure Spatial Anchors depends on an internet connection, low/poor connectivity can affect the system.

mrwellmann commented 2 years ago

Thanks @oafolabi-msft. I looks like you pointed us to the correct place 👍

We where looking for documentation of Microsoft.Azure.SpatialAnchors.Unity.SpatialAnchorManager and e.g. StartSessionAsync therefore we did no find it. It might be a a good idea to more clearly link the APIs in this repros README.md.

Now that I know where too look I find them at https://docs.microsoft.com/de-de/azure/spatial-anchors/ under references wich I personaly find quiet a bit hidden for something important like a API reference.

SpatialAnchorManager how it is exposed in Unity:

#region Assembly AzureSpatialAnchors.SDK.Core.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// C:\Users\MarkusWellmann\Workspace\FIREDRILL\Library\ScriptAssemblies\AzureSpatialAnchors.SDK.Core.Runtime.dll
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

namespace Microsoft.Azure.SpatialAnchors.Unity
{
    public class SpatialAnchorManager : MonoBehaviour
    {
        protected static Dictionary<string, ARAnchor> pointerToAnchors;
        protected bool isSessionStarted;
        [Header("Credentials")]
        [SerializeField]
        [Tooltip("The Client ID to use when authenticating using Azure Active Directory.")]
        protected string clientId;
        [SerializeField]
        [Tooltip("The Account Domain to use when connecting to the Azure Spatial Anchors services. This is provided by the Spatial Anchors service portal.")]
        protected string spatialAnchorsAccountDomain;
        [SerializeField]
        [Tooltip("The Account Key to use when authenticating using API Key. This is provided by the Spatial Anchors service portal.")]
        protected string spatialAnchorsAccountKey;
        [Header("Credentials")]
        [SerializeField]
        [Tooltip("The Account ID to use when authenticating using API Key. This is provided by the Spatial Anchors service portal.")]
        protected string spatialAnchorsAccountId;
        [Header("Authentication")]
        [SerializeField]
        [Tooltip("The method to use for authentication.")]
        protected AuthenticationMode authenticationMode;
        protected bool ARSessionInitialized;
        protected Camera mainCamera;
        protected ARSession arSession;
        protected ARCameraManager arCameraManager;
        protected List<AnchorLocatedEventArgs> pendingEventArgs;
        protected long lastFrameProcessedTimeStamp;
        protected SessionStatus sessionStatus;
        protected CloudSpatialAnchorSession session;
        [SerializeField]
        [Tooltip("The Tenant ID to use when authenticating using Azure Active Directory.")]
        protected string tenantId;
        [Header("Logging")]
        [SerializeField]
        [Tooltip("The log level for messages from the Spatial Anchors service.")]
        protected SessionLogLevel logLevel;

        public SpatialAnchorManager();

        public AuthenticationMode AuthenticationMode { get; set; }
        public string ClientId { get; set; }
        public bool IsLocating { get; }
        public bool IsReadyForCreate { get; }
        public bool IsSessionStarted { get; }
        public SessionLogLevel LogLevel { get; set; }
        public CloudSpatialAnchorSession Session { get; protected set; }
        public SessionStatus SessionStatus { get; }
        public string SpatialAnchorsAccountId { get; set; }
        public string SpatialAnchorsAccountKey { get; set; }
        public string SpatialAnchorsAccountDomain { get; set; }
        public string TenantId { get; set; }

        public event AnchorLocatedDelegate AnchorLocated;
        public event LocateAnchorsCompletedDelegate LocateAnchorsCompleted;
        public event SessionErrorDelegate Error;
        public event EventHandler SessionChanged;
        public event EventHandler SessionCreated;
        public event EventHandler SessionDestroyed;
        public event EventHandler SessionStopped;
        public event EventHandler SessionStarted;
        public event OnLogDebugDelegate LogDebug;
        public event SessionUpdatedDelegate SessionUpdated;

        [AsyncStateMachine(typeof(<CreateAnchorAsync>d__49))]
        [DebuggerStepThrough]
        public Task CreateAnchorAsync(CloudSpatialAnchor anchor, CancellationToken cancellationToken);
        public Task CreateAnchorAsync(CloudSpatialAnchor anchor);
        [AsyncStateMachine(typeof(<CreateSessionAsync>d__45))]
        [DebuggerStepThrough]
        public Task CreateSessionAsync();
        [AsyncStateMachine(typeof(<DeleteAnchorAsync>d__51))]
        [DebuggerStepThrough]
        public Task DeleteAnchorAsync(CloudSpatialAnchor anchor);
        public void DestroySession();
        [AsyncStateMachine(typeof(<ResetSessionAsync>d__48))]
        [DebuggerStepThrough]
        public Task ResetSessionAsync();
        [AsyncStateMachine(typeof(<StartSessionAsync>d__52))]
        [DebuggerStepThrough]
        public Task StartSessionAsync();
        public void StopSession();
        protected virtual void Awake();
        protected void CompleteARFoundationInitialization();
        [AsyncStateMachine(typeof(<EnsureValidConfiguration>d__23))]
        [DebuggerStepThrough]
        protected virtual Task<bool> EnsureValidConfiguration(bool disable, bool exception);
        [AsyncStateMachine(typeof(<GetAADTokenAsync>d__24))]
        [DebuggerStepThrough]
        protected virtual Task<string> GetAADTokenAsync();
        [AsyncStateMachine(typeof(<IsValidateConfiguration>d__26))]
        [DebuggerStepThrough]
        protected virtual Task<bool> IsValidateConfiguration();
        protected virtual void LoadConfiguration();
        protected virtual void OnAnchorLocated(object sender, AnchorLocatedEventArgs args);
        protected virtual void OnDestroy();
        protected virtual void OnError(object sender, SessionErrorEventArgs args);
        protected virtual void OnLocateAnchorsCompleted(object sender, LocateAnchorsCompletedEventArgs args);
        protected virtual void OnLogDebug(object sender, OnLogDebugEventArgs args);
        protected virtual void OnSessionChanged();
        protected virtual void OnSessionCreated();
        protected virtual void OnSessionDestroyed();
        protected virtual void OnSessionStarted();
        protected virtual void OnSessionStopped();
        protected virtual void OnSessionUpdated(object sender, SessionUpdatedEventArgs args);
        [AsyncStateMachine(typeof(<Start>d__43))]
        [DebuggerStepThrough]
        protected virtual void Start();
        protected virtual void Update();
    }
}
mrwellmann commented 2 years ago

For others to come I missed that we can actually see the the implementation of SpatialAnchorManager if we go into Packages->Azure Spatial Anchors SDK Core->Runtime->Scripts there the methods are documented, too.