Example #1
0
 private void rangeCheckHandler(GameObject checkedObject)
 {
     if (GraspStateController.Verbose)
     {
         UnityEngine.Debug.Log(checkedObject.name + " left bounds...");
     }
     this.InteractionState = Interactioncontroller.InteractionStates.OUT_OF_BOUNDS;
     this.cancelAndResetInteractionSequence();
 }
Example #2
0
    private void checkTargetDestruction(GameObject gameObject)
    {
        if (!GraspStateController.IsActive)
        {
            return;
        }

        if (this.InteractionState == Interactioncontroller.InteractionStates.NONE && this.CurrentInteractionState.InteractionStage == InteractionStage.GRASPING_INTERACTION)
        {
            if (GraspStateController.Verbose)
            {
                UnityEngine.Debug.Log("target destroyed...");
            }
            this.InteractionState = Interactioncontroller.InteractionStates.TARGET_DESTROYED;
        }
    }
Example #3
0
    private void checkTargetPosition(GameObject gameObject, bool validOrientation)
    {
        if (!GraspStateController.IsActive)
        {
            return;
        }

        if (this.InteractionState == Interactioncontroller.InteractionStates.NONE && this.CurrentInteractionState.InteractionStage == InteractionStage.GRASPING_INTERACTION)
        {
            if (GraspStateController.Verbose)
            {
                UnityEngine.Debug.Log("target in position...");
            }
            this.InteractionState = validOrientation ? Interactioncontroller.InteractionStates.IN_BOX : Interactioncontroller.InteractionStates.WRONG_ORIENTATION;
        }
    }
Example #4
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;
        }
    }