Example #1
0
    private static Vector2 movementToVector(MovementDirection movement, Thalmic.Myo.Arm conductingArm)
    {
        if (conductingArm == Thalmic.Myo.Arm.Unknown)
        {
            return(Vector2.zero);
        }

        switch (movement)
        {
        case MovementDirection.DOWN:
            return(Vector2.down);

        case MovementDirection.INWARDS:
            return((conductingArm == Thalmic.Myo.Arm.Right) ? Vector2.left : Vector2.right);

        case MovementDirection.OUTWARDS:
            return((conductingArm == Thalmic.Myo.Arm.Right) ? Vector2.right : Vector2.left);

        case MovementDirection.UP:
            return(Vector2.up);

        default:
            return(Vector2.zero);
        }
    }
Example #2
0
    public void setArm(Thalmic.Myo.Arm conductingArm)
    {
        if (conductingArm == currentArm)
        {
            return;
        }
        currentArm = conductingArm;

        RectTransform transform = GetComponent <RectTransform> ();

        if (conductingArm == Thalmic.Myo.Arm.Left)
        {
            // UI aligned left
            transform.anchorMin = new Vector2(0f, 0f);
            transform.anchorMax = new Vector2(0f, 1f);
            transform.pivot     = new Vector2(0f, 0.5f);
        }
        else
        {
            // UI aligned right
            transform.anchorMin = new Vector2(1f, 0f);
            transform.anchorMax = new Vector2(1f, 1f);
            transform.pivot     = new Vector2(1f, 0.5f);
        }

        GetComponentInChildren <MovementIndicator>().setArm(conductingArm);
    }
    void Update()
    {
        lock (_lock) {
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;
            if (_myoQuaternion != null)
            {
                transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
            }
            if (_myoAccelerometer != null)
            {
                accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null)
            {
                gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            if (isPaired && streamEmg == Thalmic.Myo.Result.Success)
            {
                emg = _myo.emgData;
            }

            pose     = _myoPose;
            unlocked = _myoUnlocked;
        }
    }
Example #4
0
    void Update()
    {
        lock (_lock)
        {
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;
            //Felix

            /*if (_myoQuaternion != null)
             * {
             *  transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
             * }*/
            if (_myoAccelerometer != null)
            {
                accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null)
            {
                gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            //pose = _myoPose;

            //Felix
            if (Player != null && Player.Replaying && Player.FrameCount > 0)
            {
                MyoData mData = Player.GetCurrentFrame();
                pose = mData.Pose;
                transform.localRotation = mData.Quaternion;
                if (Player != null && !Player.Focus)
                {
                    Player.SetFocus(true);
                }
            }
            else
            {
                pose = _myoPose;
                if (armSynced && _myoQuaternion != null)
                {
                    transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X,
                                                             -_myoQuaternion.W);
                    if (Player != null && !Player.Focus)
                    {
                        Player.SetFocus(true);
                    }
                }
                else if (Player != null)
                {
                    Player.SetFocus(false);
                }
            }
            unlocked = _myoUnlocked;
        }
    }
Example #5
0
 void Update() {
     lock (_lock) {
         armRecognized = _myoArmRecognized;
         arm = _myoArm;
         xDirection = _myoXDirection;
         if (_myoQuaternion != null) {
             transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
         }
         if (_myoAccelerometer != null) {
             accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
         }
         if (_myoGyroscope != null) {
             gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
         }
         pose = _myoPose;
     }
 }
Example #6
0
    void Update()
    {
        lock (_lock) {
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;

            /*   if (_myoQuaternion != null) {
             *     transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
             * }
             * if (_myoAccelerometer != null) {
             *     accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
             * }*/
            /* if (_myoGyroscope != null) {
             *   gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
             * }*/
            pose     = _myoPose;
            unlocked = _myoUnlocked;
        }
    }
Example #7
0
 void Update()
 {
     lock (_lock) {
         armRecognized = _myoArmRecognized;
         arm           = _myoArm;
         xDirection    = _myoXDirection;
         if (_myoQuaternion != null)
         {
             transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
         }
         if (_myoAccelerometer != null)
         {
             accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
         }
         if (_myoGyroscope != null)
         {
             gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
         }
         pose = _myoPose;
     }
 }
    public void setArm(Thalmic.Myo.Arm conductingArm)
    {
        if (conductingArm == currentArm)
        {
            return;
        }
        currentArm = conductingArm;

        RectTransform transform = GetComponent <RectTransform> ();

        if (conductingArm == Thalmic.Myo.Arm.Left)
        {
            // Mirrored
            transform.localScale = imageScaling * new Vector2(-1f, 1f);
        }
        else
        {
            // Not mirrored
            transform.localScale = imageScaling * new Vector2(1f, 1f);
        }
    }
Example #9
0
	void Update() {
		lock (_lock) {
			armSynced = _myoArmSynced;
			arm = _myoArm;
			xDirection = _myoXDirection;
			if (_myoQuaternion != null) {
				transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
			}
			if (_myoAccelerometer != null) {
				accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
			}
			if (_myoGyroscope != null) {
				gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
			}
//			if (isPaired && streamEmg == Thalmic.Myo.Result.Success) {
//				emg = _myo.emgData;
//			}

			pose = _myoPose;
			unlocked = _myoUnlocked;
		}
	}
Example #10
0
    public int[] Update()
    {
        // Line for mapping motion to avatar elbow
        ClientRoutine_Sitting.elbowMyo = GetComponent <Transform>().rotation; //Supinate z, Internal rotation y, Bicep x,

        lock (_lock) {                                                        // The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section.
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;
            if (_myoQuaternion != null)
            {
                transform.localRotation = new UnityEngine.Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
            }
            if (_myoAccelerometer != null)
            {
                accelerometer = new UnityEngine.Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null)
            {
                gyroscope = new UnityEngine.Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            if (isPaired && streamEmg == Thalmic.Myo.Result.Success)
            {
                emg = _myo.emgData;

                /*
                 * UnityEngine.Debug.Log("Size of raw emg array (ThalmicMyo): " + emg.Length);
                 * UnityEngine.Debug.Log("Timestamp: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                 * UnityEngine.Debug.Log("---------------------------------------------");
                 */
            }

            pose     = _myoPose;
            unlocked = _myoUnlocked;
        }
        return(emg);
    }
Example #11
0
    void Update()
    {
        lock (_lock) {
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;
            if (_myoQuaternion != null)
            {
                transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
            }
            if (_myoAccelerometer != null)
            {
                accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null)
            {
                gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            if (isPaired && streamEmg == Thalmic.Myo.Result.Success)
            {
                emg = _myo.emgData;

                //print ("EMG stream received: " + emg.Length); // 8

                if (emg.Length == 8)
                {
                    //print (emg[0] + " " + emg[1] + " " + emg[2] + " " + emg[3] + " " + emg[4] + " " + emg[5] + " " + emg[6] + " " + emg[7]);
                    //Savecsv();

                    /*
                     *
                     * string filePath = @"Saved_data.csv";
                     * string delimiter = ",";
                     *
                     * string[][] output = new string[][]{
                     *      new string[]{emg[0].ToString()},
                     *      new string[]{emg[1].ToString()},
                     *      new string[]{emg[2].ToString()},
                     *      new string[]{emg[3].ToString()},
                     *      new string[]{emg[4].ToString()},
                     *      new string[]{emg[5].ToString()},
                     *      new string[]{emg[6].ToString()},
                     *      new string[]{emg[7].ToString()},
                     *      new string[]{"end"}
                     * };
                     * int length = output.GetLength(0);
                     * StringBuilder sb = new StringBuilder();
                     * for (int index = 0; index < length; index++)
                     *      sb.AppendLine(string.Join(delimiter, output[index]));
                     *
                     * File.WriteAllText(filePath, sb.ToString());
                     */
                }
                //foreach (int emgval in emg) { // doesn't work
                //	print ("emgval" + emgval);
                //}
            }

            pose     = _myoPose;
            unlocked = _myoUnlocked;
        }
    }
Example #12
0
    void Update() {
        lock (_lock) {
            armSynced = _myoArmSynced;
            arm = _myoArm;
			xDirection = XDirection.TowardWrist;//_myoXDirection;
            if (_myoQuaternion != null) {
                transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
            }
            if (_myoAccelerometer != null) {
                accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null) {
                gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            pose = _myoPose;
            unlocked = _myoUnlocked;

			/// Our code
			Vector3 rot = transform.localRotation.eulerAngles;
			float horizontalRotate = rot.z;
			float verticalRotate = rot.y;

			if (horizontalRotate > 180) {
				horizontalRotate = 360 - horizontalRotate;
			}
			if (verticalRotate > 180) {
				verticalRotate = 360 - verticalRotate;
			}
			if (Mathf.Abs(verticalRotate) < 5) {
				verticalRotate = 0;
			}
			if (Mathf.Abs (horizontalRotate) < 5) {
				horizontalRotate = 0;
			}
			print ("rotation is " + horizontalRotate + ", " + verticalRotate);

			// comment
			if (pose == Pose.Fist)
			{
				print ("Detected Fist pose");

				paintbrush.GetComponent<PaintBrushScript>().setPainting (true);
			}

			if (numUpdates < startRuns) {
				sumX += horizontalRotate;
				sumY += verticalRotate;
				print ("Collecting data " + numUpdates + ": " + sumX + ", " + sumY);

				// else
			} else if (numUpdates == startRuns) {
				startingX = sumX / startRuns;
				startingY = sumY / startRuns;
				print ("averaging " + startingX + ", " + startingY + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

			} else {
				Vector3 vel = new Vector3 (horizontalRotate, verticalRotate, 0);
				vel.x -= startingX;
				vel.y -= startingY;

				vel = vel * velScale;
				paintbrush.GetComponent<Rigidbody> ().velocity = vel;

				print ("Velocity is " + vel.x + ", " + vel.y + ", " + vel.z);
			}
			numUpdates++; 
        }
    }
 void myo_OnArmUnsync(object sender, Thalmic.Myo.MyoEventArgs e)
 {
     lock (_lock) {
         _myoArmSynced = false;
         _myoArm = Arm.Unknown;
         _myoXDirection = XDirection.Unknown;
     }
 }
 void myo_OnArmSync(object sender, Thalmic.Myo.ArmSyncedEventArgs e)
 {
     lock (_lock) {
         _myoArmSynced = true;
         _myoArm = e.Arm;
         _myoXDirection = e.XDirection;
     }
 }
 void Update()
 {
     armSynced = _myoArmSynced;
     if (armSynced)
     {
         syncText.text = "Myo is synced!";
     }
     else
     {
         syncText.text = "Perform the sync motion.";
     }
     arm = _myoArm;
     xDirection = _myoXDirection;
     if (_myoQuaternion != null) {
         transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
     }
     if (_myoAccelerometer != null) {
         accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
     }
     if (_myoGyroscope != null) {
         gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
     }
     pose = _myoPose;
     if ((pose == Pose.Fist) && (armSynced)) {
         fistText.text = "Curl or Punch";
     }
     else
     {
         fistText.text = "Make sure the myo is synced and make a fist!";
     }
     unlocked = _myoUnlocked;
 }
 void myo_OnArmSync(object sender, Thalmic.Myo.ArmSyncedEventArgs e)
 {
     lock (_lock) {
         _myoArmSynced = true;
         _myoArm = e.Arm;
         _myoXDirection = e.XDirection;
         accelerometer = new Vector3(0,0,0);
     }
 }
Example #17
0
    void Update()
    {
        lock (_lock)
        {
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;
            if (_myoQuaternion != null)
            {
                transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
            }
            if (_myoAccelerometer != null)
            {
                accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null)
            {
                gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            unlocked = _myoUnlocked;

            // Récupération de l'ancienne pose.
            lastPose = pose;
            // Récupération de la pose courant.
            pose = _myoPose;

            // Calibration de la position du Myo lorsque le joueur écarte les doigts.
            if (pose == Pose.FingersSpread && !hasAlreadyCalibrate)
            {
                OrientationYI       = myo.transform.forward.y;
                OrientationZI       = myo.transform.forward.z;
                hasAlreadyCalibrate = true;

                Debug.Log($"Initialisation des valeurs de l'orientation X({OrientationZI}) et Y({OrientationYI})");
            }

            if (pose == Pose.DoubleTap)
            {
                // Si le joueur fait 2 double tap à la suite --> rejouer.
                if (hasDoubleTap && lastPose == Pose.Rest)
                {
                    Replay();
                }
                hasDoubleTap = true;
            }
            else if (pose != Pose.Rest)
            {
                hasDoubleTap = false;
            }

            // Si le joueur n'a pas encore joué.
            if (!hasAlreadyPlayed)
            {
                // Si la position du joueur est le poing
                if (pose == Pose.Fist)
                {
                    // Si l'accélération maximale est égale à 0 et donc que le joueur n'est pas entrain de lancer --> Début du lancer
                    if (AccelXMax == 0f)
                    {
                        // Vibration indiquant au joueur que le lancer à commencé.
                        _myo.Vibrate(VibrationType.Short);
                    }

                    // Si la position courante Y du myo est supérieure à la position Y initiale lors de la calibration --> Lancer le jeu.
                    if (myo.transform.forward.y > OrientationYI)
                    {
                        AvantLancer();
                    }
                    // Récupération
                    if (AccelXMax < _myoAccelerometer.X)
                    {
                        AccelXMax = _myoAccelerometer.X;
                    }
                }
                // Sinon, si l'accélération maximale est supérieure à 0, et donc que le joueur est dans un lancé => le joueur a finit son lancé donc on lance le jeu.
                else if (AccelXMax > 0f)
                {
                    AvantLancer();
                }
                // Si le joueur est en extension: déplacement de la boule vers la droite
                else if (pose == Pose.WaveOut && lastPose != Pose.WaveOut)
                {
                    if (ball.transform.position.x > -0.4f)
                    {
                        ball.transform.Translate(new Vector3(-0.1f, 0f, 0f));
                    }
                }

                // Si le joueur est en flexion: déplacement de la boule vers la gauche
                else if (pose == Pose.WaveIn && lastPose != Pose.WaveIn)
                {
                    if (ball.transform.position.x < 0.4f)
                    {
                        ball.transform.Translate(new Vector3(0.1f, 0f, 0f));
                    }
                }
            }
        }
    }