Beispiel #1
0
 private void rangeCheckHandler(GameObject checkedObject)
 {
     if (GraspTrainingController.Verbose)
     {
         UnityEngine.Debug.Log(checkedObject.name + " left bounds...");
     }
     this.InteractionState = SampleTrialController.InteractionStates.OUT_OF_BOUNDS;
     this.cancelAndResetTrial();
 }
Beispiel #2
0
    private void checkResponseIntervalTime()
    {
        long deltaTime = SampleTrialController.Millis - this.TargetOnsetTime;

        //if possible interaction time has passed and there was no interaction or if possible speech response time is over, set InteractionState to TIME_OUT
        if (deltaTime >= SampleTrialController.ResponseIntervalLength && (!this.Target.GetComponent <GraspableObject>().HasBeenGrasped()))
        {
            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("trial time out...");
            }
            this.InteractionState = SampleTrialController.InteractionStates.TIME_OUT;
        }
    }
Beispiel #3
0
    private void checkTargetDestruction(GameObject gameObject)
    {
        if (!GraspTrainingController.IsActive)
        {
            return;
        }

        if (this.InteractionState == SampleTrialController.InteractionStates.NONE && this.CurrentTrialState.TrialState == TrainingStates.RESPONSE)
        {
            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("target destroyed...");
            }
            this.InteractionState = SampleTrialController.InteractionStates.TARGET_DESTROYED;
        }
    }
Beispiel #4
0
    private void checkTargetPosition(GameObject gameObject, bool validOrientation)
    {
        if (!GraspTrainingController.IsActive)
        {
            return;
        }

        if (this.InteractionState == SampleTrialController.InteractionStates.NONE && this.CurrentTrialState.TrialState == TrainingStates.RESPONSE)
        {
            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("target in position...");
            }
            this.InteractionState = validOrientation ? SampleTrialController.InteractionStates.IN_BOX : SampleTrialController.InteractionStates.WRONG_ORIENTATION;
        }
    }
    private void checkVerbalResponseIntervalTime()
    {
        if (this.StimulationOnset == -1L)
        {
            return;
        }

        long deltaTime = SampleTrialController.Millis - (this.StimulationOnset);

        // allow grasping before speech...
        if ((deltaTime >= SpeechTrainingController.VerbalResponseIntervalLength && this.messageObtained == false))
        {
            if (SpeechTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("verbal trial time out: " + deltaTime + " (" + (this.StimulationOnset) + ") " + "...");
            }
            this.InteractionState = SampleTrialController.InteractionStates.VERBAL_TIME_OUT;
        }
    }
    public void TrialUpdate()
    {
        if (!SpeechTrainingController.IsActive)
        {
            this.Started = false;
            return;
        }

        if (SpeechTrainingController.Verbose)
        {
            UnityEngine.Debug.Log("timer called, in state = " + CurrentTrialState.TrialState.ToString() + "...");
        }
        switch (this.CurrentTrialState.TrialState)
        {
        case TrainingStates.STARTUP:
            if (SpeechTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("startup...");
            }

            this.HandPoseController.resetInitialPoseChecks();
            this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.CHECK);
            this.FeedbackDisplay.text = "";
            if (SpeechTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("startup done...");
            }
            break;

        case TrainingStates.INIT:

            this.CurrentCongruencyCondition = "";
            this.CorrectResponse            = false;
            this.StimulationOnset           = -1L;
            this.VerbalResponseTime         = -1L;

            this.CurrentTrialState.TrialState      = TrainingStates.FIXATION;
            this.FixationObject.transform.position = this.InitialTargetPosition;

            if (SpeechTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("dummy fixation interval");
            }
            StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate));
            break;

        case TrainingStates.FIXATION:
            this.CurrentTrialState.TrialState      = TrainingStates.SOA;
            this.FixationObject.transform.position = new Vector3(0, -10, 0);
            StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate));

            // stimulation
            int   stimulationTime = UnityEngine.Random.Range(-150, 150);
            float timeout         = (CurrentTrialState.getSleepInterval() + stimulationTime) * .001f;
            StartCoroutine(this.TimeBasedStimulation(timeout));
            break;

        case TrainingStates.SOA:
            this.messageObtained = false;
            if (this.Target.GetComponent <GraspableObject>().IsGrabbed())
            {
                GraspController[] hands = GameObject.FindObjectsOfType <GraspController>();

                foreach (GraspController hand in hands)
                {
                    hand.requestRelease();
                }
            }

            this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.IDLE);
            GraspableObject graspable = this.Target.GetComponent <GraspableObject>();
            graspable.ResetVariables();

            bool rotate = UnityEngine.Random.value > .5f;

            graspable.ResetPositionAndOrientation(rotate ? 180.0f : 0.0f, this.InitialTargetPosition);
            if (rotate)
            {
                if (SpeechTrainingController.Verbose)
                {
                    Debug.Log("rotated target...");
                }
                //  this.Target.transform.Rotate(new Vector3(180.0f, 0.0f, 0.0f));
                //  this.Target.transform.position = this.InitialTargetPosition;
            }
            else
            {
                if (SpeechTrainingController.Verbose)
                {
                    Debug.Log("upright target...");
                }
                // this.Target.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f));
                // this.Target.transform.position = this.InitialTargetPosition;
            }

            this.Target.GetComponent <Rigidbody>().isKinematic = false;
            // edit JL
            this.Target.GetComponent <Rigidbody>().useGravity = true;

            this.CurrentTrialState.TrialState = TrainingStates.RESPONSE;
            // enable range check
            this.InteractionState      = SampleTrialController.InteractionStates.NONE;
            this.CheckInteractionState = true;
            if (SpeechTrainingController.Verbose)
            {
                Debug.Log("Current Trial State: " + CurrentTrialState.TrialState);
            }
            break;

        case TrainingStates.RESPONSE:
            if (SpeechTrainingController.Verbose)
            {
                Debug.Log("response state...");
            }
            this.CheckInteractionState = false;
            //method that saves the interaction in the TrialData
            // no verbal reponse...
            if (this.VerbalResponseTime == -1L)
            {
                this.InteractionState = SampleTrialController.InteractionStates.VERBAL_TIME_OUT;
            }

            if (this.VerbalResponseTime != -1L && !this.CorrectResponse)
            {
                this.InteractionState = SampleTrialController.InteractionStates.VERBAL_WRONG_RESPONSE;
            }

            if (this.InteractionState != SampleTrialController.InteractionStates.IN_BOX)
            {
                this.cancelTrial();
            }
            else
            {
                this.FeedbackDisplay.text = this.positiveFeedbackTemplates[UnityEngine.Random.Range(0, this.positiveFeedbackTemplates.Length - 1)];

                this.deactivateTarget();
                this.InteractionState = SampleTrialController.InteractionStates.NONE;
                // clear monitor
                this.messageObtained = false;

                this.PoseCheckTimeStamp = -1L;
            }

            this.CurrentCongruencyCondition = "";
            this.CorrectResponse            = false;
            this.StimulationOnset           = -1L;
            this.VerbalResponseTime         = -1L;
            this.LastErrorCode = "none";

            this.CurrentTrialState.TrialState = TrainingStates.WAITING;
            StartCoroutine(this.FeedbackInterval());

            break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!this.Started && SpeechTrainingController.IsActive)
        {
            this.Started                      = true;
            this.PoseCheckTimeStamp           = -1L;
            this.CurrentTrialState.TrialState = TrainingStates.STARTUP;
            this.TrialUpdate();
        }
        // check pose
        if (this.Started && SpeechTrainingController.IsActive && this.CurrentTrialState.TrialState == TrainingStates.STARTUP)
        {
            this.checkInitialPose();
        } // check response state

        // fixation check
        if (this.Started && SpeechTrainingController.IsActive && this.CurrentTrialState.TrialState == TrainingStates.FIXATION)
        {
            if (SpeechTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("fixation check...");
            }
            if (!this.HandPoseController.checkInitialPose())
            {
                this.InteractionState = SampleTrialController.InteractionStates.LEFT_POSITION_DURING_FIXATION;
                this.cancelAndResetTrial();
            }
            if (this.HandPoseController.checkInitialPose())
            {
                this.TrialUpdate();
            }
            else
            {
                if (SpeechTrainingController.Verbose)
                {
                    UnityEngine.Debug.Log("fixation not yet completed");
                }
            }
        }

        // soa + response check
        if (this.Started && SpeechTrainingController.IsActive && (this.CurrentTrialState.TrialState == TrainingStates.SOA || this.CurrentTrialState.TrialState == TrainingStates.RESPONSE))
        {
            if (SpeechTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("soa check...");
            }
            if (!this.HandPoseController.checkInitialPose())
            {
                this.InteractionState = SampleTrialController.InteractionStates.LEFT_POSITION_DURING_FIXATION;
                this.cancelAndResetTrial();
            }
        }

        //check hand trajectory
        if (this.Started && SpeechTrainingController.IsActive && this.CurrentTrialState.TrialState != TrainingStates.STARTUP && this.CurrentTrialState.TrialState != TrainingStates.FIXATION)
        {
            // cancel trial
            if (this.CurrentHandID != this.HandControllerReference.currentRightHandID && this.CurrentTrialState.TrialState == TrainingStates.RESPONSE)
            {
                this.cancelAndResetTrial();
            }
        }

        //checkInteractionState = true after fixation
        if (this.Started && SpeechTrainingController.IsActive && this.CheckInteractionState)
        {
            this.checkWordRecognition();
            this.checkVerbalResponseIntervalTime();

            if (this.InteractionState != SampleTrialController.InteractionStates.NONE)
            {
                this.TrialUpdate();
                // just paranoia
                this.CheckInteractionState = false;
            }
        }
    }
Beispiel #8
0
    public void TrialUpdate()
    {
        if (!GraspTrainingController.IsActive)
        {
            this.Started = false;
            return;
        }

        if (this.CurrentTrialState.TrialState == TrainingStates.RESPONSE && SampleTrialController.Millis - this.TargetOnsetTime < 1000L)
        {
            return;
        }

        if (GraspTrainingController.Verbose)
        {
            UnityEngine.Debug.Log("timer called, in state = " + CurrentTrialState.TrialState.ToString() + "...");
        }
        switch (this.CurrentTrialState.TrialState)
        {
        case TrainingStates.STARTUP:
            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("startup...");
            }

            this.HandPoseController.resetInitialPoseChecks();
            this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.CHECK);
            this.FeedbackDisplay.text = "";

            if (this.variableMapping)
            {
                this.OffsetController.DriftFactor = this.master.visualOffsets[UnityEngine.Random.Range(0, this.master.visualOffsets.Length)];
            }
            else
            {
                this.OffsetController.DriftFactor = 0.0f;
            }

            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("startup done...");
            }
            break;

        case TrainingStates.INIT:
            this.CurrentTrialState.TrialState      = TrainingStates.FIXATION;
            this.FixationObject.transform.position = this.InitialTargetPosition;
            this.master.GraspTrainingTrialStart();

            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("dummy fixation interval");
            }
            StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate));
            break;

        case TrainingStates.FIXATION:
            this.CurrentTrialState.TrialState      = TrainingStates.SOA;
            this.FixationObject.transform.position = new Vector3(0, -10, 0);
            if (this.variableMapping)
            {
                this.OffsetController.ApplyDrift = true;
            }
            else
            {
                this.OffsetController.ApplyDrift = false;
            }
            StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate));
            break;

        case TrainingStates.SOA:
            if (this.Target.GetComponent <GraspableObject>().IsGrabbed())
            {
                GraspController[] hands = GameObject.FindObjectsOfType <GraspController>();

                foreach (GraspController hand in hands)
                {
                    hand.requestRelease();
                }
            }

            this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.IDLE);
            GraspableObject graspable = this.Target.GetComponent <GraspableObject>();
            graspable.ResetVariables();

            if (this.bottleOrientationMode == "upright")
            {
                graspable.ResetPositionAndOrientation(0.0f, this.InitialTargetPosition);
                if (GraspTrainingController.Verbose)
                {
                    Debug.Log("upright target...");
                }
                //  this.Target.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f));
                //  this.Target.transform.position = this.InitialTargetPosition;
            }
            else if (this.bottleOrientationMode == "upsidedown")
            {
                graspable.ResetPositionAndOrientation(180.0f, this.InitialTargetPosition);
                if (GraspTrainingController.Verbose)
                {
                    Debug.Log("rotated target...");
                }
                // this.Target.transform.Rotate(new Vector3(180.0f, 0.0f, 0.0f));
                //  this.Target.transform.position = this.InitialTargetPosition;
            }
            else if (this.bottleOrientationMode == "random")
            {
                if (UnityEngine.Random.value > .5f)
                {
                    graspable.ResetPositionAndOrientation(180.0f, this.InitialTargetPosition);
                    if (GraspTrainingController.Verbose)
                    {
                        Debug.Log("rotated target...");
                    }
                    //  this.Target.transform.Rotate(new Vector3(180.0f, 0.0f, 0.0f));
                    //  this.Target.transform.position = this.InitialTargetPosition;
                }
                else
                {
                    graspable.ResetPositionAndOrientation(0.0f, this.InitialTargetPosition);
                    if (GraspTrainingController.Verbose)
                    {
                        Debug.Log("upright target...");
                    }
                    //   this.Target.transform.Rotate(new Vector3(0.0f, 0.0f, 0.0f));
                    //  this.Target.transform.position = this.InitialTargetPosition;
                }
            }
            else
            {
                UnityEngine.Debug.Log("unknown orientation mode: " + this.bottleOrientationMode + "...");
            }

            this.Target.GetComponent <Rigidbody>().isKinematic = false;
            // edit JL
            this.Target.GetComponent <Rigidbody>().useGravity = true;

            this.CurrentTrialState.TrialState = TrainingStates.RESPONSE;
            // enable range check
            this.InteractionState      = SampleTrialController.InteractionStates.NONE;
            this.CheckInteractionState = true;
            this.RangeCheck.clearMonitor();
            this.RangeCheck.monitorObject(this.Target);
            this.TargetOnsetTime = SampleTrialController.Millis;
            if (Verbose)
            {
                Debug.Log("Current Trial State: " + CurrentTrialState.TrialState);
            }
            break;

        case TrainingStates.RESPONSE:
            if (GraspTrainingController.Verbose)
            {
                Debug.Log("response state...");
            }
            this.CheckInteractionState       = false;
            this.OffsetController.ApplyDrift = false;

            if (this.InteractionState != SampleTrialController.InteractionStates.IN_BOX)
            {
                this.cancelTrial();
                // reset trial state...
                //this.CurrentTrialState.TrialState = TrainingStates.STARTUP;
                //StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate));
            }
            else
            {
                this.FeedbackDisplay.text = this.positiveFeedbackTemplates[UnityEngine.Random.Range(0, this.positiveFeedbackTemplates.Length - 1)];

                this.deactivateTarget();
                this.InteractionState = SampleTrialController.InteractionStates.NONE;
                // clear monitor
                this.RangeCheck.clearMonitor();

                this.PoseCheckTimeStamp = -1L;

                //this.CurrentTrialState.TrialState = TrainingStates.STARTUP;
                //StartCoroutine(CoroutineTimer.Start(CurrentTrialState.getSleepInterval() * .001f, this.TrialUpdateDelegate));
            }
            this.CurrentTrialState.TrialState = TrainingStates.WAITING;
            StartCoroutine(this.FeedbackInterval());

            break;
        }
    }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        if (!this.Started && GraspTrainingController.IsActive)
        {
            this.Started = true;
            this.TrainingUI.SetActive(true);
            this.PoseCheckTimeStamp           = -1L;
            this.CurrentTrialState.TrialState = TrainingStates.STARTUP;
            this.TrialUpdate();
        }
        // check pose
        if (this.Started && GraspTrainingController.IsActive && this.CurrentTrialState.TrialState == TrainingStates.STARTUP)
        {
            this.checkInitialPose();
        } // check response state

        // fixation check
        if (this.Started && GraspTrainingController.IsActive && this.CurrentTrialState.TrialState == TrainingStates.FIXATION)
        {
            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("fixation check...");
            }
            if (!this.HandPoseController.checkInitialPose())
            {
                this.InteractionState = SampleTrialController.InteractionStates.LEFT_POSITION_DURING_FIXATION;
                this.cancelAndResetTrial();
            }
            if (this.HandPoseController.checkInitialPose())
            {
                this.TrialUpdate();
            }
            else
            {
                if (GraspTrainingController.Verbose)
                {
                    UnityEngine.Debug.Log("fixation not yet completed");
                }
            }
        }

        // soa check
        if (this.Started && GraspTrainingController.IsActive && this.CurrentTrialState.TrialState == TrainingStates.SOA)
        {
            if (GraspTrainingController.Verbose)
            {
                UnityEngine.Debug.Log("soa check...");
            }
            if (!this.HandPoseController.checkInitialPose())
            {
                this.InteractionState = SampleTrialController.InteractionStates.LEFT_POSITION_DURING_FIXATION;
                this.cancelAndResetTrial();
            }
        }

        //check hand trajectory
        if (this.Started && GraspTrainingController.IsActive && this.CurrentTrialState.TrialState != TrainingStates.STARTUP && this.CurrentTrialState.TrialState != TrainingStates.FIXATION)
        {
            // cancel trial
            if (this.CurrentHandID != this.HandControllerReference.currentRightHandID && this.CurrentTrialState.TrialState == TrainingStates.RESPONSE)
            {
                this.cancelAndResetTrial();
            }
        }

        //checkInteractionState = true after fixation
        if (this.Started && GraspTrainingController.IsActive && this.CheckInteractionState)
        {
            //checks if no time out for vocal response and object interaction and if vocal response has been obtained
            this.checkResponseIntervalTime();

            if (this.InteractionState != SampleTrialController.InteractionStates.NONE)
            {
                this.TrialUpdate();
                // just paranoia
                this.CheckInteractionState = false;
            }
        }
    }