Exemple #1
0
            public void emgWorker()
            {
                float[] data = new float[2];
                while (running)
                {
                    try
                    {
                        //Demultiplex the data and save for UI display
                        for (int sn = 0; sn < 16; ++sn)
                        {
                            emgData[sn] = reader.ReadSingle();
                        }

                        m_LSLOutlet.push_sample(emgData); //sends emg data to LSL Lab Recorder

                        ThreadPool.QueueUserWorkItem(Validator.evaluate, emgData);

                        /*
                         * This would be the optimal placement for controller
                         *
                         * Eg.
                         * ThreadPool.QueueUserWorkItem
                         */

                        ++count;
                    }
                    catch
                    {
                        //ignore timeouts, but force a check of the running flag
                    }
                }
            }
Exemple #2
0
 public void SendTrigger(int pressed)
 {
     if (isStreaming)
     {
         triggerBuffer[0] = pressed;
         lslTriggerOutlet.push_sample(triggerBuffer);
     }
 }
Exemple #3
0
 /// <summary>
 /// Sends float data
 /// </summary>
 /// <param name="value"></param>
 public void SendData(float[] value)
 {
     if (value.Length == lslChannelCount)
     {
         floatSample = value;
         lslOutlet.push_sample(floatSample);
     }
     else
     {
         Debug.LogError("You are trying to assign an incorrect sample size.");
     }
 }
            //Sliding Window Method + weights
            static public void sliding_rms(Object info)
            {
                float[] data = filter.process((float[])info);
                lock (locker)
                {
                    //get the absolute value of the data
                    data = new float[2] {
                        Math.Abs(data[0]), Math.Abs(data[1])
                    };

                    //add newest data to the top of the queue
                    outputQueue.Enqueue(data);
                    //remove oldest data from bottom of queue when full
                    if (outputQueue.Count > weights.Length)
                    {
                        data = outputQueue.Dequeue();
                    }

                    output[0] = 0;
                    output[1] = 0;
                    int i = 0;
                    foreach (float[] q in outputQueue)
                    {
                        output[0] += weights[i] * q[0];
                        output[1] += weights[i] * q[1];
                        i++;
                    }
                }

                m_LSLOutlet.push_sample(output);
            }
        /// <summary>
        ///
        /// </summary>
        internal override void RunLSL()
        {
            // set the meta data of the stream
            liblsl.StreamInfo info = new liblsl.StreamInfo(
                this.streamName, this.type, channelCount, nominalState,
                liblsl.channel_format_t.cf_float32, this.sourceID);

            // make the LSL outlet object based on the stream info
            liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);

            // this array will hold the data being sent each time
            float[] data = new float[arrayLength];

            // while
            while (this.keepThreadRunning)
            {
                // get the data
                data = dataGenerator.GetFloatArrayData();

                // send the data out into the stream
                outlet.push_sample(data);

                // wait until the next piece of info is needed
                System.Threading.Thread.Sleep(this.delayInMiliseconds);
            }
        }
        private void pushSample()
        {
            int offset = -1;

            if (StreamRotationAsQuaternion)
            {
                var rotation = sampleSource.rotation;

                currentSample[++offset] = rotation.x;
                currentSample[++offset] = rotation.y;
                currentSample[++offset] = rotation.z;
                currentSample[++offset] = rotation.w;
            }
            if (StreamRotationAsEuler)
            {
                var rotation = sampleSource.rotation.eulerAngles;

                currentSample[++offset] = rotation.x;
                currentSample[++offset] = rotation.y;
                currentSample[++offset] = rotation.z;
            }
            if (StreamPosition)
            {
                var position = sampleSource.position;

                currentSample[++offset] = position.x;
                currentSample[++offset] = position.y;
                currentSample[++offset] = position.z;
            }

            outlet.push_sample(currentSample, liblsl.local_clock());
        }
        static void Main(string[] args)
        {
            // create stream info and outlet
            liblsl.StreamInfo   info   = new liblsl.StreamInfo("Tobii", "Gaze", 3, 60, liblsl.channel_format_t.cf_double64, "eye_tracker");
            liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);
            InitializeHost();
            ConsoleKeyInfo keyinfo;
            //Console.WriteLine(sample.ToString());
            Program p = new Program();

            do
            {
                keyinfo = Console.ReadKey();

                while (!Console.KeyAvailable)
                {
                    p.CreateAndVisualizeLightlyFilteredGazePointStream();
                    //Console.WriteLine(time_st + "  " + eye_x+ "  " + eye_y);
                    //Console.WriteLine(p.sample[0].ToString() + "  " + p.sample[1].ToString() + "  " + p.sample[2].ToString());
                    outlet.push_sample(p.sample);
                    System.Threading.Thread.Sleep(10);
                }
            }while (keyinfo.Key != ConsoleKey.Spacebar);
            DisableConnectionWithTobiiEngine();
        }
Exemple #8
0
    // Update is called once per frame
    void Update()
    {
        float dTheta;

        for (int i = 0; i < 3 * 5; i++)
        {//for each joints make it closer to the targeting pos
            if (Math.Abs(fingersJoints[i] - fingersJoints_target[i]) > 1)
            {
                dTheta = (fingersJoints[i] < fingersJoints_target[i]) ? incMax : -incMax;
                fingersTf[i].Rotate(0.0f, 0.0f, -dTheta);
                fingersJoints[i] += dTheta;
            }
        }
        if (isConnected)
        {
            outlet.push_sample(fingersJoints);//publish the position
            Debug.Log(string.Format("Sending ..."));
            Debug.Log(string.Format("[ {0} , {1} , {2} || {3} , {4} , {5} || {6} , {7} , {8} || {9} , {10} , {11} || {12} , {13} , {14} ]",
                                    fingersJoints[0], fingersJoints[1], fingersJoints[2], fingersJoints[3], fingersJoints[4], fingersJoints[5], fingersJoints[6], fingersJoints[7],
                                    fingersJoints[8], fingersJoints[9], fingersJoints[10], fingersJoints[11], fingersJoints[12], fingersJoints[13], fingersJoints[14]));

            /*
             * only take some of the joint angle
             * simpleJoints[0] = fingersJoints[0];
             * simpleJoints[1] = fingersJoints[1];
             * for(int i = 1; i<5; i++)
             * simpleJoints[i] = fingersJoints[i*3];
             * outlet.push_sample(simpleJoints);//publish the position
             */
        }
    }
Exemple #9
0
    void ReportPose()
    {
        string[] rowDataTemp = new string[10];
        rowDataTemp[0] = DateTime.UtcNow.ToString("hh.mm.ss.ffffff");
        rowDataTemp[1] = car.transform.position.x.ToString();
        rowDataTemp[2] = car.transform.position.y.ToString();
        rowDataTemp[3] = car.transform.position.z.ToString();
        rowDataTemp[4] = car.transform.eulerAngles.x.ToString();
        rowDataTemp[5] = car.transform.eulerAngles.y.ToString();
        rowDataTemp[6] = car.transform.eulerAngles.z.ToString();
        rowDataTemp[7] = gasInput.ToString();
        rowDataTemp[8] = breakInput.ToString();
        rowDataTemp[9] = steerInput.ToString();
        sb.AppendLine(string.Join(",", rowDataTemp));


        Inputs();
        //TODO: edit here for Lab Stream Layer code.
        //Debug.Log("gas, break, steer: " + gasInput + "," + breakInput + "," + steerInput);

        float [] rowDataTempFloat = new float[11];
        rowDataTempFloat[0]  = (float)(new TimeSpan(DateTime.Now.Ticks)).TotalMilliseconds;
        rowDataTempFloat[1]  = car.transform.position.x;
        rowDataTempFloat[2]  = car.transform.position.y;
        rowDataTempFloat[3]  = car.transform.position.z;
        rowDataTempFloat[4]  = car.transform.eulerAngles.x;
        rowDataTempFloat[5]  = car.transform.eulerAngles.y;
        rowDataTempFloat[6]  = car.transform.eulerAngles.z;
        rowDataTempFloat[7]  = (float)gasInput;
        rowDataTempFloat[8]  = (float)breakInput;
        rowDataTempFloat[9]  = (float)steerInput;
        rowDataTempFloat[10] = splashScreenStatus();

        outlet.push_sample(rowDataTempFloat);
    }
    private void pushSample()
    {
        if (outlet == null)
        {
            return;
        }
        else
        {
            /* if (Vector3.Magnitude(firstDevice.velocity) > 1)
             *              Debug.Log("Position:" +firstDevice.transform.pos);
             *      if (Vector3.Magnitude(firstDevice.angularVelocity) > 1)
             *              Debug.Log("Rotation"+firstDevice.transform.rot);*/
            // reuse the array for each sample to reduce allocation costs
            // currently only for right-hand device
            currentSample[0] = head.transform.position.x;
            currentSample[1] = head.transform.position.y;
            currentSample[2] = head.transform.position.z;
            currentSample[3] = head.transform.rotation.x;
            currentSample[4] = head.transform.rotation.y;
            currentSample[5] = head.transform.rotation.z;
            currentSample[6] = head.transform.rotation.w;

            outlet.push_sample(currentSample, liblsl.local_clock());

            //Debug.Log(currentSample[0]+","+currentSample[1]+","+currentSample[2]);
        }
    }
Exemple #11
0
    // This is called at a fixed time step defined in project settings (Usually used for physics updates)
    void FixedUpdate()
    {
        // initial data to send
        Vector3    playerPos = GameManager.Inst.LocalPlayer.gameObject.transform.position;
        Quaternion playerRot = GameManager.Inst.LocalPlayer.gameObject.transform.rotation;

        float[] data = new float[8];
        data[0] = playerPos.x;
        data[1] = playerPos.z;
        data[2] = playerRot.eulerAngles.x;
        data[3] = playerRot.eulerAngles.y;
        data[4] = playerRot.eulerAngles.z;
        data[5] = 0f;
        data[6] = 0f;
        data[7] = 0f;

        GameObject arrow = GameObject.Find("Arrow");

        if (arrow != null)
        {
            data[5] = arrow.transform.eulerAngles.x;
            data[6] = arrow.transform.eulerAngles.y;
            data[7] = arrow.transform.eulerAngles.z;
        }
        outlet.push_sample(data);
    }
 /// <summary>
 /// Push marker sample to LSL network
 /// </summary>
 public void Write(int value, long epochNow)
 {
     sample[0] = epochNow;
     sample[1] = value;
     sample[2] = epochNow;
     //  time stamp
     lslOutlet.push_sample(sample);
 }
Exemple #13
0
 public void pushSample()
 {
     if (outlet == null)
     {
         return;
     }
     currentSample = sampleSource.GetComponent <BallManager>().sendInfo;
     outlet.push_sample(currentSample, liblsl.local_clock());
 }
Exemple #14
0
    // http://wiki.unity3d.com/index.php?title=FramesPerSecond
    public void Update()
    {
        deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
        float fps = 1.0f / deltaTime;

        currentSample[0] = fps;

        outlet.push_sample(currentSample);
    }
Exemple #15
0
 public void SendSound(int sourceID, int soundID)
 {
     if (isStreaming)
     {
         soundBuffer[0] = sourceID;
         soundBuffer[1] = soundID;
         lslSoundOutlet.push_sample(soundBuffer);
     }
 }
    /*public void PushMarker(GameObject obj) {
     *          if (outlet == null) return;
     *
     *          int[] data = new int[]{marker};
     *          Debug.Log ("PushMarker " + data[0].ToString());
     *          outlet.push_sample(data);
     *  }*/

    public void PushMarker()
    {
        if (outlet == null)
        {
            return;
        }

        int[] data = new int[] { marker };
        Debug.Log("PushMarker " + data[0].ToString());
        outlet.push_sample(data);
    }
        public void SendRandomSignal()
        {
            Random rnd = new Random();

            while (RUNNING_FLAG)
            {
                sample[0] = rnd.Next(0, 10);
                lslOutlet.push_sample(sample);
                Thread.Sleep(10);
            }
        }
Exemple #18
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     // If lslOutlet is sucessfully linked start sending stuff there!
     if (lslOutlet != null)
     {
         sample[0] = textField.Text;
         lslOutlet.push_sample(sample, liblsl.local_clock());
     }
     else
     {
         textField.Text = "Link Outlet Before Sending Messages!";
     }
 }
Exemple #19
0
    // Update is called once per frame
    void Update()
    {
        Vector3 pos = gameObject.transform.position;

        currentSample[0] = pos.x;
        currentSample[1] = pos.y;
        currentSample[2] = pos.z;
        Quaternion quat = gameObject.transform.rotation;

        currentSample[3] = quat.w;
        currentSample[4] = quat.x;
        currentSample[5] = quat.y;
        currentSample[6] = quat.z;
        outlet.push_sample(currentSample);
    }
Exemple #20
0
        public void FixedUpdate()
        {
            if (watch == null || outlet == null)
            {
                return;
            }

            watch.Stop();

            currentSample[0] = watch.ElapsedMilliseconds;

            watch.Reset();
            watch.Start();

            outlet.push_sample(currentSample, liblsl.local_clock());
        }
        private void pushSample()
        {
            if (outlet == null)
            {
                return;
            }
            var rotation = sampleSource.rotation;

            // reuse the array for each sample to reduce allocation costs
            currentSample[0] = rotation.x;
            currentSample[1] = rotation.y;
            currentSample[2] = rotation.z;
            currentSample[3] = rotation.w;

            outlet.push_sample(currentSample, liblsl.local_clock());
        }
Exemple #22
0
 private static void EyeCallback(ref EyeData_v2 eye_data)
 {
     eyeData   = eye_data;
     lastTime  = nextTime;
     nextTime  = eyeData.timestamp;
     buffer[0] = eyeData.timestamp;
     buffer[1] = eyeData.verbose_data.combined.eye_data.gaze_origin_mm.x;
     buffer[2] = eyeData.verbose_data.combined.eye_data.gaze_origin_mm.y;
     buffer[3] = eyeData.verbose_data.combined.eye_data.gaze_origin_mm.z;
     buffer[4] = eyeData.verbose_data.combined.eye_data.gaze_direction_normalized.x;
     buffer[5] = eyeData.verbose_data.combined.eye_data.gaze_direction_normalized.y;
     buffer[6] = eyeData.verbose_data.combined.eye_data.gaze_direction_normalized.z;
     buffer[7] = eyeData.verbose_data.left.pupil_diameter_mm;
     buffer[8] = eyeData.verbose_data.left.pupil_diameter_mm;
     soutlet.push_sample(buffer);
 }
        private void PushDataToLSL(object data)
        {
            // LSL Data Sender
            double[,] dataArray = (double[, ])data;
            double[] sample        = new double[lslChannelCount];
            int      sampleCounter = 0;

            for (int r = 0; r < rows; r++)
            {
                for (int c = 0; c < cols; c++)
                {
                    sample[sampleCounter] = dataArray[r, c];
                    sampleCounter++;
                }
            }
            lslOutlet.push_sample(sample);
        }
    void LateUpdate()
    {
        if (outlet == null)
        {
            return;
        }

        var rotation = sampleSource.rotation;

        // reuse the array for each sample to reduce allocation costs
        currentSample[0] = rotation.x;
        currentSample[1] = rotation.y;
        currentSample[2] = rotation.z;
        currentSample[3] = rotation.w;

        outlet.push_sample(currentSample, LSLTimeSync.Instance.UpdateTimeStamp);
    }
        /// <summary>
        /// The acquisition thread.
        /// Acquires data from the Unicorn and sends it to LSL.
        /// </summary>
        private void AcquisitionThread_DoWork()
        {
            try
            {
                //Initialize Unicorn acquisition members
                uint     numberOfAcquiredChannels = _device.GetNumberOfAcquiredChannels();
                byte[]   receiveBuffer            = new byte[FrameLength * sizeof(float) * numberOfAcquiredChannels];
                GCHandle receiveBufferHandle      = GCHandle.Alloc(receiveBuffer, GCHandleType.Pinned);
                float[]  receiveBufferFloat       = new float[receiveBuffer.Length / sizeof(float)];

                //Start acquisition
                _device.StartAcquisition(false);
                _acquisitionRunning = true;
                UpdateUIElements(DeviceStates.Acquiring);

                //acquisition loop
                while (_acquisitionRunning)
                {
                    //get data
                    _device.GetData(FrameLength, receiveBufferHandle.AddrOfPinnedObject(), (uint)(receiveBuffer.Length / sizeof(float)));

                    //convert byte array to float array for LSL
                    for (int j = 0; j < receiveBuffer.Length / sizeof(float); j++)
                    {
                        receiveBufferFloat[j] = BitConverter.ToSingle(receiveBuffer, j * sizeof(float));
                    }

                    // send sample via LSL
                    _lslOutlet.push_sample(receiveBufferFloat);
                }
            }
            finally
            {
                try
                {
                    _device.StopAcquisition();
                }
                catch
                {
                    _device.Dispose();
                    _device = null;
                    UpdateUIElements(DeviceStates.NotConnected);
                }
            }
        }
        static void Main(string[] args)
        {
            // create stream info and outlet
            liblsl.StreamInfo   inf  = new liblsl.StreamInfo("Test1", "Markers", 1, 0, liblsl.channel_format_t.cf_string, "giu4569");
            liblsl.StreamOutlet outl = new liblsl.StreamOutlet(inf);

            Random rnd = new Random();

            string[] strings = new string[] { "Test", "ABC", "123" };
            string[] sample  = new string[1];
            for (int k = 0; ; k++)
            {
                // send a marker and wait for a random interval
                sample[0] = strings[k % 3];
                outl.push_sample(sample);
                System.Threading.Thread.Sleep(rnd.Next(1000));
            }
        }
    // Update is called once per frame
    void FixedUpdate()
    {
        var eyeTrackingData = TobiiXR.GetEyeTrackingData(TobiiXR_TrackingSpace.World);

        currentSample[0]  = eyeTrackingData.Timestamp;
        currentSample[1]  = eyeTrackingData.ConvergenceDistance;
        currentSample[2]  = System.Convert.ToSingle(eyeTrackingData.ConvergenceDistanceIsValid);
        currentSample[3]  = eyeTrackingData.GazeRay.Origin.x;
        currentSample[4]  = eyeTrackingData.GazeRay.Origin.y;
        currentSample[5]  = eyeTrackingData.GazeRay.Origin.z;
        currentSample[6]  = eyeTrackingData.GazeRay.Direction.x;
        currentSample[7]  = eyeTrackingData.GazeRay.Direction.y;
        currentSample[8]  = eyeTrackingData.GazeRay.Direction.z;
        currentSample[9]  = System.Convert.ToSingle(eyeTrackingData.GazeRay.IsValid);
        currentSample[10] = System.Convert.ToSingle(eyeTrackingData.IsLeftEyeBlinking);
        currentSample[11] = System.Convert.ToSingle(eyeTrackingData.IsRightEyeBlinking);
        outlet.push_sample(currentSample);
    }
Exemple #28
0
        public void FixedUpdate()
        {
            // Get eye tracking data in world space
            var eyeTrackingData = TobiiXR.GetEyeTrackingData(TobiiXR_TrackingSpace.World);

            // Check if gaze ray is valid
            if (eyeTrackingData.GazeRay.IsValid)
            {
                // The origin of the gaze ray is a 3D point
                var rayOrigin = eyeTrackingData.GazeRay.Origin;

                // The direction of the gaze ray is a normalized direction vector
                var rayDirection = eyeTrackingData.GazeRay.Direction;

                currentSample[0] = rayDirection.x;
                currentSample[1] = rayDirection.y;
                currentSample[2] = rayDirection.z;
                outlet.push_sample(currentSample);
            }
        }
        private void sample()
        {
            int offset = -1;

            if (StreamRotationAsQuaternion)
            {
                var rotation = sampleSource.rotation;

                currentSample[++offset] = rotation.x;
                currentSample[++offset] = rotation.y;
                currentSample[++offset] = rotation.z;
                currentSample[++offset] = rotation.w;
            }
            if (StreamRotationAsEuler)
            {
                var rotation = sampleSource.rotation.eulerAngles;

                currentSample[++offset] = rotation.x;
                currentSample[++offset] = rotation.y;
                currentSample[++offset] = rotation.z;
            }
            if (StreamPosition)
            {
                var position = sampleSource.position;

                currentSample[++offset] = position.x;
                currentSample[++offset] = position.y;
                currentSample[++offset] = position.z;

                if (cube.material.color == onColour)
                {
                    currentSample[++offset] = 1f;
                }
                else
                {
                    currentSample[++offset] = 0f;
                }
            }

            outlet.push_sample(currentSample, liblsl.local_clock());
        }
        static void Main(string[] args)
        {
            Random rnd = new Random();

            // create stream info and outlet
            liblsl.StreamInfo   info   = new liblsl.StreamInfo("TestCSharp", "EEG", 8, 100, liblsl.channel_format_t.cf_float32, "sddsfsdf");
            liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);
            float[]             data   = new float[8];
            while (true)
            {
                // generate random data and send it
                for (int k = 0; k < data.Length; k++)
                {
                    data[k] = rnd.Next(-100, 100);
                }
                outlet.push_sample(data);
                System.Threading.Thread.Sleep(10);
            }

            System.Console.ReadKey();
        }