예제 #1
0
    /// <summary>
    /// this is the state machine that controls the interaction
    /// </summary>
    public void InteractionStateUpdate()
    {
        if (!GraspStateController.IsActive)
        {
            this.Started = false;
            return;
        }

        if (GraspStateController.Verbose)
        {
            UnityEngine.Debug.Log("timer called, in state = " + CurrentInteractionState.InteractionStage.ToString() + "...");
        }
        switch (this.CurrentInteractionState.InteractionStage)
        {
        case InteractionStage.STARTUP:
            if (GraspStateController.Verbose)
            {
                UnityEngine.Debug.Log("startup...");
            }

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

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

        case InteractionStage.TARGET_PRESENTATION:
            // just paranoia, it is highly unlikely that something like this happens
            if (this.Target.GetComponent <GraspableObject>().IsGrabbed())
            {
                GraspController[] hands = GameObject.FindObjectsOfType <GraspController>();

                foreach (GraspController hand in hands)
                {
                    hand.requestRelease();
                }
            }
            // disable the pose check
            this.HandPoseController.setControllerMode(PoseController.PoseControllerMode.IDLE);
            GraspableObject graspable = this.Target.GetComponent <GraspableObject>();
            graspable.ResetVariables();
            // TODO: display the bottle either upright or upside down, depending on the
            // bottleOrientationMode string, you can use the InitialTargetPosition variable
            // and the ResetPositionAndOrientation of the Graspable script

            // TODO: enable the physics of the bottle

            if (this.bottleOrientationMode == "upright")
            {
                graspable.ResetPositionAndOrientation(0.0f, this.InitialTargetPosition);
                if (GraspStateController.Verbose)
                {
                    Debug.Log("upright target...");
                }
            }
            else if (this.bottleOrientationMode == "upsidedown")
            {
                graspable.ResetPositionAndOrientation(180.0f, this.InitialTargetPosition);
                if (GraspStateController.Verbose)
                {
                    Debug.Log("rotated target...");
                }
            }

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

            this.CurrentInteractionState.InteractionStage = InteractionStage.GRASPING_INTERACTION;
            // enable range check
            this.InteractionState      = Interactioncontroller.InteractionStates.NONE;
            this.CheckInteractionState = true;
            this.RangeCheck.clearMonitor();
            // TODO: add the target to the monitor, have a look at the EffectorRangeCheck script
            this.RangeCheck.monitorObject(this.Target);


            if (Verbose)
            {
                Debug.Log("current interaction state: " + CurrentInteractionState.InteractionStage);
            }
            break;

        case InteractionStage.GRASPING_INTERACTION:
            if (GraspStateController.Verbose)
            {
                Debug.Log("response state...");
            }
            this.CheckInteractionState = false;

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

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

                this.PoseCheckTimeStamp = -1L;
            }
            this.CurrentInteractionState.InteractionStage = InteractionStage.WAITING;
            StartCoroutine(this.FeedbackInterval());

            break;
        }
    }
    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;
        }
    }
예제 #3
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;
        }
    }