Exemple #1
0
 void Update()
 {
     if (interpolator == null &&
         glove.IsLinked &&
         glove.GetInterpolationProfile(out interpolator))
     {
         poses = LoadProfiles(interpolator);
         Debug.Log($"Connected {handName} glove");
     }
 }
Exemple #2
0
        // Update is called once per frame
        void Update()
        {
            // load old calibration if existing
            if (interpolator == null &&
                hand.IsLinked &&
                hand.GetInterpolationProfile(out interpolator))
            {
                poses = LoadProfiles();
                Debug.Log($"Connected {(isRight ? "right" : "left")} Hand");
            }

            // only start the calibration, if the SenseGlove could be found and the calibrating flag was set
            if (calibrating && hand.IsLinked)
            {
                switch (currentStep)
                {
                // 1. show instruction
                case Step.ShowInstruction:
                {
                    virtualHand.SetActive(true);
                    ShowInstruction();
                    break;
                }

                // 2. wait
                case Step.Wait:
                {
                    calibrationParams.waitTimer.LetTimePass(Time.deltaTime);
                    poseStore.Clear();
                    break;
                }

                // 3. dwell
                case Step.Dwell:
                {
                    if (TutorialSteps.Instance.audioManager.IsAudioPlaying())
                    {
                        break;
                    }
                    calibrationParams.dwellTimer.LetTimePass(Time.deltaTime);
                    completionWidget.active   = true;
                    completionWidget.text     = "calibrating";
                    completionWidget.progress = calibrationParams.dwellTimer.GetFraction();

                    poseStore.AddPose(GetCurrentPoseValues());
                    float error = poseStore.ComputeError();
                    if (error > calibrationParams.maxError)
                    {
                        const string warningText = "Finger position changed too much, retry";
                        Debug.LogWarning(warningText);

                        poseStore.Clear();
                        calibrationParams.dwellTimer.ResetTimer();
                    }
                    break;
                }

                // 3.5 finish calibration & init testing phase
                case Step.TestInit:
                {
                    hand.SaveHandCalibration();
                    virtualHand.SetActive(false);
                    Debug.Log($"Saved Calibration Profiles for {lrName} hand");

                    TutorialSteps.Instance.audioManager.ScheduleAudioClip(audioClips.test, queue: false);
                    TutorialSteps.PublishNotification($"{lrName} thumbs up to continue", audioClips.test.length + testParams.dwellTime);
                    handAnimator.SetInteger("handState", (int)Pose.ThumbUp);

                    currentStep = Step.Test;
                    goto case Step.Test;
                }

                // 4. test calibration
                case Step.Test:
                {
                    if (TutorialSteps.Instance.audioManager.IsAudioPlaying())
                    {
                        break;
                    }
                    PoseBuffer buffer = new PoseBuffer(bufferSize: 2);
                    buffer.AddPose(poseValues[(int)Pose.ThumbUp]);
                    buffer.AddPose(GetCurrentPoseValues());
                    float error = buffer.ComputeError();
                    testParams.dwellTimer.LetTimePass(Time.deltaTime);
                    if (error > testParams.maxError)
                    {
                        testParams.dwellTimer.ResetTimer();
                    }

                    completionWidget.text     = "hold";
                    completionWidget.active   = true;
                    completionWidget.progress = testParams.dwellTimer.GetFraction();
                    break;
                }

                // 5. calibration done
                case Step.Done:
                {
                    calibrating             = false;
                    completionWidget.active = false;
                    doneCallbacks.Call(currentStep);
                    break;
                }

                default: break;
                }
            }
        }