Пример #1
0
    void SendControls()
    {
        scale = TFListener.scale;

        //Convert the Unity position of the hand controller to a ROS position (scaled)
        Vector3 outPos = UnityToRosPositionAxisConversion(GetComponent <Transform>().position) / scale;
        //Convert the Unity rotation of the hand controller to a ROS rotation (scaled, quaternions)
        Quaternion outQuat = UnityToRosRotationAxisConversion(GetComponent <Transform>().rotation);
        //construct the Ein message to be published
        string message = "";

        //Allows movement control with controllers if menu is disabled

        //if deadman switch held in, move to new pose
        if (controller.gripPressed)
        {
            //construct message to move to new pose for the robot end effector
            message = outPos.x + " " + outPos.y + " " + outPos.z + " " +
                      outQuat.x + " " + outQuat.y + " " + outQuat.z + " " + outQuat.w + " moveToEEPose";
            //if touchpad is pressed (Crane game), incrementally move in new direction
        }
        else if (controller.touchpadPressed)
        {
            //get the angle contact point on touch pad
            float angle = controller.GetTouchpadAxisAngle();

            //Con
            if (angle >= 45 && angle < 135) // touching right
            {
                message += " yDown ";
            }
            else if (angle >= 135 && angle < 225) // touching bottom
            {
                message += " xDown ";
            }
            else if (angle >= 225 && angle < 315) // touching left
            {
                message += " yUp ";
            }
            else //touching top
            {
                message += " xUp ";
            }
        }
        //If trigger pressed, open the gripper. Else, close gripper
        if (controller.triggerPressed)
        {
            message += " openGripper ";
        }
        else
        {
            message += " closeGripper ";
        }

        //Send the message to the websocket client (i.e: publish message onto ROS network)
        wsc.SendEinMessage(message, arm);

        //Debug.Log(arm+":"+message);
    }
Пример #2
0
// Check a single range of numbers
        void singleRange()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                Finish();
            }

            // get touch pad script
            touchpadAngle.Value = theScript.GetTouchpadAxisAngle();

            // check if touchpad is within the range
            if (touchpadAngle.Value >= startRange.Value && touchpadAngle.Value <= endRange.Value)
            {
                if (!requireTrigger.Value)
                {
                    Fsm.Event(inRange);
                }

                if (requireTrigger.Value)
                {
                    if (theScript.touchpadPressed)
                    {
                        Fsm.Event(inRange);
                    }
                }
            }

            // else if not in range, then do out of range.
            else
            {
                if (!requireTrigger.Value)
                {
                    Fsm.Event(outOfRange);
                }

                if (requireTrigger.Value)
                {
                    if (theScript.touchpadPressed)
                    {
                        Fsm.Event(outOfRange);
                    }
                }
            }
        }
Пример #3
0
 protected virtual void Update()
 {
     if (controllerEvents != null)
     {
         float touchpadAngle = controllerEvents.GetTouchpadAxisAngle();
         float angle         = ((touchpadAngle > 180) ? touchpadAngle -= 360 : touchpadAngle) + headset.eulerAngles.y;
         transform.localEulerAngles = new Vector3(0f, angle, 0f);
     }
 }
Пример #4
0
    void sendControls()
    {
        scale = TFListener.scale;

        Vector3    outPos  = UnityToRosPositionAxisConversion(tf.position) / scale;
        Quaternion outQuat = UnityToRosRotationAxisConversion(tf.rotation);

        string message = "";

        //Allows movement control with controllers if menu is disabled
        if (!menu.activeSelf)
        {
            if (controller.gripPressed)
            {
                message = outPos.x + " " + outPos.y + " " + outPos.z + " " + outQuat.x + " " + outQuat.y + " " + outQuat.z + " " + outQuat.w + " moveToEEPose";
            }
            else if (controller.touchpadPressed)
            {
                float angle = controller.GetTouchpadAxisAngle();

                if (angle >= 45 && angle < 135)                 // touching right
                {
                    message += " yDown ";
                }
                else if (angle >= 135 && angle < 225)                 // touching bottom
                {
                    message += " xDown ";
                }
                else if (angle >= 225 && angle < 315)                 // touching left
                {
                    message += " yUp ";
                }
                else                 //touching top
                {
                    message += " xUp ";
                }
            }
            if (controller.triggerPressed)
            {
                message += " openGripper ";
            }
            else
            {
                message += " closeGripper ";
            }

            wsc.SendEinMessage(message, arm);
        }
        //Debug.Log(arm+":"+message);
    }
Пример #5
0
        protected virtual void Update()
        {
            //transform.localEulerAngles = playArea.transform.localEulerAngles;

            if (controllerEvents != null)
            {
                eulerAngle = rightHandAnchor.rotation.eulerAngles;

                //eulerAngle = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).eulerAngles; //+ new Vector3(90, 0, 0);

                //Vector3 position = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);


                //Quaternion rotation = Quaternion.Euler(90, 0, 0);
                //Matrix4x4 m = Matrix4x4.Rotate(rotation);
                //transformedAngleMatrix = m.MultiplyVector(eulerAngle);

                transformedAngleM = Quaternion.Euler(90, 0, 0) * eulerAngle;

                //transform.localRotation = Quaternion.Euler(new Vector3(90, 0, 0));


                Vector2 forward2D = new Vector2(playArea.transform.forward.x, playArea.transform.forward.z).normalized;

                Vector2 destVect2D = (new Vector2(transform.position.x, transform.position.z) - new Vector2(playArea.transform.position.x, playArea.transform.position.z)).normalized;

                float baseAngle = Vector2.SignedAngle(destVect2D, forward2D);

                float correctAngle = transform.localEulerAngles.y;
                //Debug.Log(baseAngle);

                float touchpadAngle = controllerEvents.GetTouchpadAxisAngle();
                float angle         = ((touchpadAngle > 180) ? touchpadAngle -= 360 : touchpadAngle) + headset.eulerAngles.y;

                transform.eulerAngles = new Vector3(0f, (eulerAngle.z * (-sensibilityFactor)) + playArea.transform.eulerAngles.y + baseAngle, 0f);//(360 - eulerAngle.z * 3f) + playArea.transform.eulerAngles.y +

                //Debug.Log("angle of z : " + (eulerAngle.z * (-1f)) + " Transformed angle Matrix : " + (transformedAngleM.z * (-1f)) + " angle of cursor : " + transform.eulerAngles.y);

                //storedRotation = transform.localEulerAngles;
                //Debug.Log("eulerAngle of Player : " + playArea.transform.eulerAngles.y);
                //Debug.Log("eulerAngle of indicator : " + transform.eulerAngles.y);
            }
        }
    void Update()
    {
        scale = TFListener.scale;

        Vector3 deltaPos = tf.position - lastControllerPosition; //displacement of current controller position to old controller position

        lastControllerPosition = tf.position;

        Quaternion deltaRot = tf.rotation * Quaternion.Inverse(lastControllerRotation); //delta of current controller rotation to old controller rotation

        lastControllerRotation = tf.rotation;

        //message to be sent over ROs network
        message = "";


        //Allows movement control with controllers if menu is disabled
        if (controller.gripPressed)                                                 //deadman switch being pressed
        {
            lastArmPosition = lastArmPosition + deltaPos;                           //new arm position
            lastArmRotation = deltaRot * lastArmRotation;                           //new arm rotation

            if ((Vector3.Distance(new Vector3(0f, 0f, 0f), lastArmPosition)) < 1.5) //make sure that the target stays inside a 1.5 meter sphere around the robot
            {
                targetTransform.position = lastArmPosition + 0.09f * lastArmTF.up;
                //targetTransform.position = lastArmPosition;
            }
            targetTransform.rotation = lastArmRotation;

            //Vector3 outPos = UnityToRosPositionAxisConversion(lastArmTF.position + deltaPos) / scale;
            Vector3 outPos = UnityToRosPositionAxisConversion(lastArmPosition) / scale;
            //Quaternion outQuat = UnityToRosRotationAxisConversion(deltaRot * lastArmTF.rotation);
            Quaternion outQuat = UnityToRosRotationAxisConversion(lastArmRotation);

            message = outPos.x + " " + outPos.y + " " + outPos.z + " " + outQuat.x + " " + outQuat.y + " " + outQuat.z + " " + outQuat.w + " moveToEEPose";
        }
        else if (controller.touchpadPressed)
        {
            float angle = controller.GetTouchpadAxisAngle();

            if (angle >= 45 && angle < 135) // touching right
            {
                message += " yDown ";
            }
            else if (angle >= 135 && angle < 225) // touching bottom
            {
                message += " xDown ";
            }
            else if (angle >= 225 && angle < 315) // touching left
            {
                message += " yUp ";
            }
            else //touching top
            {
                message += " xUp ";
            }
        }
        if (controller.triggerPressed)
        {
            message += " openGripper ";
        }
        else
        {
            message += " closeGripper ";
        }

        Debug.Log(message);
        //Debug.Log(lastArmPosition);
    }
Пример #7
0
        void CheckColor()
        {
            if (colorLerpTime >= 1f)
            {
                oldCol        = crystalMaterial.material.color;
                colorLerpTime = 0f;
            }
            ColorLerpDEBUG(); //ONLY RUN THIS IF USING VRTK SIMULATOR. Num1, 2, 3 change colors;

            //SPELL TYPES: 0 = red, 1 = green, 2 = blue.
            if (myController.touchpadAxisChanged)
            {
                float myAngle = myController.GetTouchpadAxisAngle();
                {/*if (myController.GetTouchpadAxisAngle() <= 90 && myController.GetTouchpadAxisAngle() > 45) {
                  * //if in the center of the red and green tri
                  * if (myController.GetTouchpadAxis().x > 0) {
                  *     redAm = 1f;
                  *     spellType = 0;
                  * }
                  * else {
                  *     greenAm = 1f;
                  *     spellType = 1;
                  * }
                  * }
                  * else if (myController.GetTouchpadAxisAngle() > 90 && myController.GetTouchpadAxisAngle() < 120) {
                  * if (myController.GetTouchpadAxis().x > 0) {
                  *     //if in the half of the red and green tri
                  *     redAm = 0.5f;
                  *     greenAm = 0.25f;
                  *     spellType = 0;
                  * }
                  * redAm = 0.25f;
                  * greenAm = 0.5f;
                  * spellType = 1;
                  * }
                  * if (myController.GetTouchpadAxisAngle() >= 120 && myController.GetTouchpadAxisAngle() < 150) {
                  * blueAm = 0.5f;
                  * spellType = 2;
                  * //if in the first half of the blue tri
                  * }
                  * else if (myController.GetTouchpadAxisAngle() >= 150) {
                  * blueAm = 1f;
                  * //else if in the center of the blue tri
                  * spellType = 2;
                  * }
                  * else {
                  * blueAm = 0.25f;
                  * //else if outside of blue
                  * }*/
                 //detect if red
                 //detect if green
                 //detect if blue
                }
                if (myAngle >= 0 && myAngle < 120)
                {
                    tarCol    = Color.red;
                    spellType = 0;
                }
                if (myAngle >= 120 && myAngle < 240)
                {
                    tarCol    = Color.green;
                    spellType = 1;
                }
                if (myAngle >= 240)
                {
                    tarCol    = Color.blue;
                    spellType = 2;
                }
                tarCol.a = ogValue;
                oldCol   = crystalMaterial.material.color;
            }

            if (oldCol != tarCol)
            {
                realCol        = Color.Lerp(oldCol, tarCol, colorLerpTime);// this doesn't work because it's setting it to a value between 0 and 1.
                colorLerpTime += 0.02f;
            } // I want to put this in update, and not use oldCol as a method of judgement.

            if (myController.touchpadPressed)
            {
                if (myController.GetTouchpadAxisAngle() <= 120)
                {
                    if (myController.GetTouchpadAxis().x > 0)
                    {
                        realCol = new Color(1f, 0.25f, 0.25f, ogValue);
                    }
                    else
                    {
                        realCol = new Color(0.25f, 1f, 0.25f, ogValue);
                    }
                }
                else
                {
                    realCol = new Color(0.25f, 0.25f, 1f, ogValue);
                }
            }
            crystalMaterial.material.color = realCol;
        }
Пример #8
0
    void Update()
    {
        // calcul de la progression du fondu au noir
        float oldProgression = blackoutProgression;

        if (viewmasterObject.IsGrabbed())
        {
            float distance = 999;
            foreach (Transform anchorPoint in viewmasterObjectAnchors)
            {
                distance = Mathf.Min(distance, Vector3.Distance(anchorPoint.position, Camera.main.transform.position));
            }
            float range = maxDistance - minDistance;
            blackoutProgression = (distance - minDistance) / range;
        }
        else
        {
            blackoutProgression += Time.deltaTime;
        }
        blackoutProgression = Mathf.Clamp(blackoutProgression, 0, 1);
        Color matCol = blackoutMesh.material.color;

        matCol.a = 1 - blackoutProgression * .9f;
        blackoutMesh.material.color = matCol;

        renderCam.enabled = blackoutProgression <= 1;
        if (blackoutProgression < 1 && oldProgression >= 1)
        {
            // calcul de la position de l'image en fonction de la tête du joueur
            portraitOrientation.localPosition = renderCam.transform.localPosition + new Vector3(0, -.1f, 0);
            portraitOrientation.localRotation = Quaternion.Euler(
                portraitOrientation.localEulerAngles.x,
                renderCam.transform.localEulerAngles.y,
                portraitOrientation.localEulerAngles.z);
            // désactivation TP
            teleportHandler.enabled = false;
        }
        else if (blackoutProgression >= 1 && oldProgression < 1)
        {
            teleportHandler.enabled = true;
        }

        // calcul de la progression du fondu de l'image
        if (blackoutProgression <= 0)
        {
            canvasProgression += Time.deltaTime;
        }
        else
        {
            canvasProgression -= Time.deltaTime * 7;
        }

        canvasProgression    = Mathf.Clamp(canvasProgression, 0, 1);
        portraitsGroup.alpha = canvasProgression;

        if (blackoutProgression <= 0)
        {
            float angleBetweenPictures = 30;
            if (currentClip != null)
            {
                angleBetweenPictures = 180f / currentClip.images.Length;
            }
            // float angleBetweenPictures = 30; // à n'utiliser que si l'autre n'est pas assez intuitif

            GameObject grabbingObj = viewmasterObject.GetGrabbingObject();
            if (grabbingObj != null)
            {
                VRTK.VRTK_ControllerEvents eventCtrl = grabbingObj.GetComponent <VRTK.VRTK_ControllerEvents>();
                lastControllerActions = grabbingObj.GetComponent <VRTK.VRTK_ControllerActions>();
                if (eventCtrl != null)
                {
                    // on est en train de visionner l'image, on récupère la manette en train de tenir le VM afin de récupérer les swipes sur le pavé tactile
                    eventCtrl.axisFidelity = 5;
                    bool wasPressing = pressingButton;
                    pressingButton = eventCtrl.IsButtonPressed(VRTK.VRTK_ControllerEvents.ButtonAlias.Touchpad_Touch);
                    if (pressingButton && !wasPressing)
                    {
                        lastRotation = eventCtrl.GetTouchpadAxisAngle();
                    }
                    float trigger = eventCtrl.GetTriggerAxis();
                    if (trigger != 1)
                    {
                        ignoreTrigger = false;
                    }
                    if (trigger == 1 && !ignoreTrigger)
                    {
                        ignoreTrigger         = true;
                        autoMoveToNextPicture = true;
                        StartCoroutine(TriggerHapticCoroutine());
                    }
                    if (pressingButton && trigger == 0 && false)
                    {
                        float oldPortraitRotation = currentPortraitRotation;
                        // en train de faire un swipe
                        float currentPadRotation = eventCtrl.GetTouchpadAxisAngle();
                        if (lastRotation - currentPadRotation < 180 && lastRotation - currentPadRotation > -180)
                        {
                            currentPortraitRotation += (lastRotation - currentPadRotation) * rotateSensitivity;
                        }
                        if (lastControllerActions != null && ((int)(currentPadRotation) / 35) != ((int)(lastRotation) / 35))
                        {
                            lastControllerActions.TriggerHapticPulse(.05f);
                        }
                        if (currentPortraitRotation > angleBetweenPictures / 2 && oldPortraitRotation < angleBetweenPictures / 2)
                        {
                            StartCoroutine(TriggerHapticCoroutine());
                        }
                        if (currentPortraitRotation < -angleBetweenPictures / 2 && oldPortraitRotation > -angleBetweenPictures / 2)
                        {
                            StartCoroutine(TriggerHapticCoroutine());
                        }
                        lastRotation = currentPadRotation;
                    }
                }
            }

            if (!pressingButton || autoMoveToNextPicture)
            {
                if (autoMoveToNextPicture)
                {
                    currentPortraitRotation += Time.deltaTime * (angleBetweenPictures + .01f - currentPortraitRotation) * 10;
                }
                else
                {
                    // retour à l'image la plus proche
                    if (currentPortraitRotation > angleBetweenPictures / 2)
                    {
                        currentPortraitRotation += Time.deltaTime * (angleBetweenPictures + .01f - currentPortraitRotation) * 10;
                    }
                    else if (currentPortraitRotation < -angleBetweenPictures / 2)
                    {
                        currentPortraitRotation += Time.deltaTime * -(angleBetweenPictures + .01f + currentPortraitRotation) * 10;
                    }
                    else
                    {
                        currentPortraitRotation -= Time.deltaTime * currentPortraitRotation * 10;
                    }
                }
            }

            if (currentPortraitRotation > angleBetweenPictures)
            {
                currentPortraitRotation -= angleBetweenPictures;
                nextImage();
            }
            if (currentPortraitRotation < -angleBetweenPictures)
            {
                currentPortraitRotation += angleBetweenPictures;
                previousImage();
            }

            // rotation de l'image
            leftImageTransform.transform.localRotation      = Quaternion.Euler(0, 0, currentPortraitRotation);
            rightImageTransform.transform.localRotation     = Quaternion.Euler(0, 0, currentPortraitRotation);
            leftImageTransformNext.transform.localRotation  = Quaternion.Euler(0, 0, currentPortraitRotation + angleBetweenPictures);
            leftImageTransformPrev.transform.localRotation  = Quaternion.Euler(0, 0, currentPortraitRotation - angleBetweenPictures);
            rightImageTransformNext.transform.localRotation = Quaternion.Euler(0, 0, currentPortraitRotation + angleBetweenPictures);
            rightImageTransformPrev.transform.localRotation = Quaternion.Euler(0, 0, currentPortraitRotation - angleBetweenPictures);
        }
        else
        {
            // rotation du disque du grabbable, pas de la vue.

            GameObject grabbingObj = viewmasterObject.GetGrabbingObject();
            if (grabbingObj != null)
            {
                VRTK.VRTK_ControllerEvents eventCtrl = grabbingObj.GetComponent <VRTK.VRTK_ControllerEvents>();
                lastControllerActions = grabbingObj.GetComponent <VRTK.VRTK_ControllerActions>();
                if (eventCtrl != null)
                {
                    // on est en train de visionner l'image, on récupère la manette en train de tenir le VM afin de récupérer les swipes sur le pavé tactile
                    eventCtrl.axisFidelity = 5;
                    bool wasPressing = pressingButton;
                    pressingButton = eventCtrl.IsButtonPressed(VRTK.VRTK_ControllerEvents.ButtonAlias.Touchpad_Touch);
                    if (pressingButton && !wasPressing)
                    {
                        lastRotation = eventCtrl.GetTouchpadAxisAngle();
                    }
                    if (pressingButton && false)
                    {
                        // en train de faire un swipe
                        float currentPadRotation = eventCtrl.GetTouchpadAxisAngle();
                        if (lastRotation - currentPadRotation < 180 && lastRotation - currentPadRotation > -180)
                        {
                            currentClipRotation += (lastRotation - currentPadRotation) * rotateSensitivity;
                        }
                        if (lastControllerActions != null && ((int)(currentPadRotation) / 275) != ((int)(lastRotation) / 275))
                        {
                            triggerAnimator.SetTrigger("Trigger");
                        }
                        lastRotation = currentPadRotation;

                        viewmasterGrabbableClipRotation.transform.localRotation = Quaternion.Euler(currentClipRotation, 0, 0);
                    }
                }
            }
        }
    }
        void MakeItSo()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                Finish();
            }

            touchpadAngle.Value = theScript.GetTouchpadAxisAngle();

            // position 1 up A
            if (touchpadAngle.Value >= 0 && touchpadAngle.Value <= 45)
            {
                if (!requireTrigger.Value)
                {
                    Fsm.Event(position1);
                }

                if (requireTrigger.Value)
                {
                    if (theScript.touchpadPressed)
                    {
                        Fsm.Event(position1);
                    }
                }
            }

            // position 1 up B
            if (touchpadAngle.Value >= 315 && touchpadAngle.Value <= 360.1)
            {
                if (!requireTrigger.Value)
                {
                    Fsm.Event(position1);
                }

                if (requireTrigger.Value)
                {
                    if (theScript.touchpadPressed)
                    {
                        Fsm.Event(position1);
                    }
                }
            }

            // position 2 right - up. NOT excluding 90

            if (!excludeDefaultPos.Value)
            {
                if (touchpadAngle.Value >= 45.1 && touchpadAngle.Value <= 135)
                {
                    if (!requireTrigger.Value)
                    {
                        Fsm.Event(position2);
                    }

                    if (requireTrigger.Value)
                    {
                        if (theScript.touchpadPressed)
                        {
                            Fsm.Event(position2);
                        }
                    }
                }
            }

            // position 2 right - up. Excluding 90

            if (excludeDefaultPos.Value)
            {
                if (touchpadAngle.Value >= 45.1 && touchpadAngle.Value <= 135 && touchpadAngle.Value != 90)
                {
                    if (!requireTrigger.Value)
                    {
                        Fsm.Event(position2);
                    }

                    if (requireTrigger.Value)
                    {
                        if (theScript.touchpadPressed)
                        {
                            Fsm.Event(position2);
                        }
                    }
                }
            }

            // position 3 right - down
            if (touchpadAngle.Value >= 135.1 && touchpadAngle.Value <= 225)
            {
                if (!requireTrigger.Value)
                {
                    Fsm.Event(position3);
                }

                if (requireTrigger.Value)
                {
                    if (theScript.touchpadPressed)
                    {
                        Fsm.Event(position3);
                    }
                }
            }

            // position 4 - down
            if (touchpadAngle.Value >= 225.1 && touchpadAngle.Value <= 315)
            {
                if (!requireTrigger.Value)
                {
                    Fsm.Event(position4);
                }

                if (requireTrigger.Value)
                {
                    if (theScript.touchpadPressed)
                    {
                        Fsm.Event(position4);
                    }
                }
            }
        }