/// <summary>
        /// Action to start test analyzing CoP and CoM position and posture.
        /// </summary>
        override protected void StartTest()
        {
            // Be sure to only stores the current series of the test.
            LogJoints3D.Clear();
            LogTestLines.Clear();
            LogTestLines.Add("#Start test");

            if (_app.SaveJoints)
            {
                LogJoints2D.Clear();
            }

            if (_app.EnableWBB)
            {
                LogTestLines.Add("CoP:0:" + CalculatedCoPX.ToString("N5") + ":" + CalculatedCoPY.ToString("N5"));
            }

            TotalErrors = 0;
            LeftFoot    = LeftHand = RightFoot = RightHand = "";

            LogJoints3D.Add("#Start Joints3D Test");
            _kinectBV.Delay     = _app.DelayTime * 30;
            _kinectBV.IsTesting = true;
            FinishedTest        = false;
        }
        /// <summary>
        /// Start Pose Calibration storing key joints positions and kinect video clip.
        /// </summary>
        override protected void StartPoseCalibration()
        {
            PoseCalibrationDone = false;
            LogJoints3DCal.Clear();
            LogCalLines.Clear();
            ResetMessages();

            LogJoints3DCal.Add("#Start Joints3D Calibration");
            LogCalLines.Add("#Start calibration");

            if (_app.EnableWBB)
            {
                LogCalLines.Add("CoP:0:" + CalculatedCoPX.ToString("N5") + ":" + CalculatedCoPY.ToString("N5"));
            }

            _startPoseCalibration   = true;                     // flag that signals timer to count calibration seconds.
            _kinectBV.Delay         = _app.DelayTime * 30;      // Retard start of the calibration.
            _kinectBV.IsCalibrating = true;                     // flag to kinect body view
        }
Beispiel #3
0
        int updateShowImage = 0;                                        // Control delays for updating image with CoP.

        protected void UpdateStatusWii(ElapsedEventArgs e)
        {
            // Get raw values from WBB load sensors
            float rvBL = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft;
            float rvBR = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight;
            float rvTL = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft;
            float rvTR = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesRaw.TopRight;

            OWBottomLeft  = rvBL;
            OWBottomRight = rvBR;
            OWTopLeft     = rvTL;
            OWTopRight    = rvTR;

            // Get the current sensor values in KG.
            KgTotalWeight = wiiDevice.WiimoteState.BalanceBoardState.WeightKg;
            KgTopLeft     = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;
            KgTopRight    = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight;
            KgBottomLeft  = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;
            KgBottomRight = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;


            // Correct reads discounting unloaded values of each cell.
            rvBL -= zcBL;
            rvBR -= zcBR;
            rvTL -= zcTL;
            rvTR -= zcTR;

            if (rvBL < calW_BL17)
            {
                rvBL = (17 * rvBL) / (calW_BL17 - calW_BL0);
            }
            else
            {
                rvBL = (34 * rvBL) / (calW_BL34 - calW_BL0);
            }

            if (rvBR < calW_BR17)
            {
                rvBR = (17 * rvBR) / (calW_BR17 - calW_BR0);
            }
            else
            {
                rvBR = (34 * rvBR) / (calW_BR34 - calW_BR0);
            }

            if (rvTL < calW_TL17)
            {
                rvTL = (17 * rvTL) / (calW_TL17 - calW_TL0);
            }
            else
            {
                rvTL = (34 * rvTL) / (calW_TL34 - calW_TL0);
            }

            if (rvTR < calW_TR17)
            {
                rvTR = (17 * rvTR) / (calW_TR17 - calW_TR0);
            }
            else
            {
                rvTR = (34 * rvTR) / (calW_TR34 - calW_TR0);
            }

            OWTotalWeight = rvBL + rvBR + rvTR + rvTL;

            // Calculate CoP using formula
            // CoPx = (L/2) * ((TR + BR) - (TL + BL)) / TR + BR + TL + BL
            // CoPy = (W/2) * ((TL + TR) - (BL + BR)) / TR + BR + TL + BL
            // W = 238 mm and L = 433mm
            // Bartlett HL, Ting LH, Bingham JT. Accuracy of force and center of pressure measures of the Wii Balance Board. Gait Posture. 2014; 39:224–8.
            CalculatedCoPX = (433 / 2) * (((rvTR + rvBR) - (rvTL + rvBL)) / (rvBL + rvBR + rvTL + rvTR));
            CalculatedCoPY = (238 / 2) * (((rvTR + rvTL) - (rvBR + rvBL)) / (rvBL + rvBR + rvTL + rvTR));

            KgCalculatedCoPx = (433 / 2) * (((KgTopRight + KgBottomRight) - (KgTopLeft + KgBottomLeft)) / (KgBottomLeft + KgBottomRight + KgTopLeft + KgTopRight));
            KgCalculatedCoPy = (238 / 2) * (((KgTopRight + KgTopLeft) - (KgBottomRight + KgBottomLeft)) / (KgBottomLeft + KgBottomRight + KgTopLeft + KgTopRight));

            // Do not refresh image every tick.
            if (updateShowImage == 0)
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                                                                 { ShowWBBImage(); }));

                updateShowImage = 4;
            }
            else
            {
                updateShowImage--;
            }

            // Calibrate zero weight when the board is unloaded.
            if (_doZeroCalibration && i < ApplicationViewModel.MaxFramesZeroCalibration)
            {
                i++;
                LogCalZeroLines.Add("RL-0Cal:" + OWBottomLeft.ToString("F0") + ":" + OWBottomRight.ToString("F0") + ":" + OWTopLeft.ToString("F0") + ":" + OWTopRight.ToString("F0"));
                zeroWeight += KgTotalWeight;
                zcBL       += OWBottomLeft;
                zcBR       += OWBottomRight;
                zcTL       += OWTopLeft;
                zcTR       += OWTopRight;
                StatusText  = "Calibrating Zero Weight.";
            }
            else
            {
                if (_doZeroCalibration)
                {
                    ZeroCalibrationDone = true;
                    zeroWeight          = zeroWeight / ApplicationViewModel.MaxFramesZeroCalibration;
                    zcBL = zcBL / ApplicationViewModel.MaxFramesZeroCalibration;
                    zcBR = zcBR / ApplicationViewModel.MaxFramesZeroCalibration;
                    zcTL = zcTL / ApplicationViewModel.MaxFramesZeroCalibration;
                    zcTR = zcTR / ApplicationViewModel.MaxFramesZeroCalibration;

                    // Get fabricant calibration values for 0kg, 17kg and 34kg over each sensor.
                    calW_BL0 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg0.BottomLeft;
                    calW_BR0 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg0.BottomRight;
                    calW_TL0 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg0.TopLeft;
                    calW_TR0 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg0.TopRight;

                    calW_BL17 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg17.BottomLeft;
                    calW_BR17 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg17.BottomRight;
                    calW_TL17 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg17.TopLeft;
                    calW_TR17 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg17.TopRight;

                    calW_BL34 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg34.BottomLeft;
                    calW_BR34 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg34.BottomRight;
                    calW_TL34 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg34.TopLeft;
                    calW_TR34 = wiiDevice.WiimoteState.BalanceBoardState.CalibrationInfo.Kg34.TopRight;

                    string txt = "CAL0_17_34:" + calW_BL0.ToString("F0") + ":" + calW_BR0.ToString("F0") + ":" + calW_TL0.ToString("F0") + ":" + calW_TR0.ToString("F0") + ":";
                    txt += calW_BL17.ToString("F0") + ":" + calW_BR17.ToString("F0") + ":" + calW_TL17.ToString("F0") + ":" + calW_TR17.ToString("F0") + ":";
                    txt += calW_BL34.ToString("F0") + ":" + calW_BR34.ToString("F0") + ":" + calW_TL34.ToString("F0") + ":" + calW_TR34.ToString("F0");
                    LogCalZeroLines.Add(txt);

                    StatusText = "Calibrate Zero Weight FINISHED.";
                }

                _doZeroCalibration = false;
            }

            if (_startPoseCalibration && _kinectBV.Delay < 0)
            {
                LogCalLines.Add("RL:" + OWBottomLeft.ToString("F0") + ":" + OWBottomRight.ToString("F0") + ":" + OWTopLeft.ToString("F0") + ":" + OWTopRight.ToString("F0"));
                LogCalLines.Add("CoP:" + (e.SignalTime - StartCalibrationTime).TotalMilliseconds.ToString("F0") + ":" + CalculatedCoPX.ToString("N3") + ":" + CalculatedCoPY.ToString("N3"));
            }
            else if (_kinectBV.IsTesting && _kinectBV.Delay < 0)
            {
                string time = (e.SignalTime - StartTestTime).TotalMilliseconds.ToString("F0");
                LogTestLines.Add("CoP:" + time + ":" + CalculatedCoPX.ToString("N5") + ":" + CalculatedCoPY.ToString("N5"));
                LogTestLines.Add("RL:" + OWBottomLeft.ToString("F0") + ":" + OWBottomRight.ToString("F0") + ":" + OWTopLeft.ToString("F0") + ":" + OWTopRight.ToString("F0"));
                LogTestLines.Add("CoP-Kg:" + time + ":" + KgCalculatedCoPx.ToString("N5") + ":" + KgCalculatedCoPy.ToString("N5"));
                LogTestLines.Add("RL-Kg:" + KgBottomLeft.ToString("N2") + ":" + KgBottomRight.ToString("N2") + ":" + KgTopLeft.ToString("N2") + ":" + KgTopRight.ToString("N2"));
            }

            // Discount read value when board is unloaded.
            ZeroCalWeight = KgTotalWeight - zeroWeight;

            CoGX = wiiDevice.WiimoteState.BalanceBoardState.CenterOfGravity.X;
            CoGY = wiiDevice.WiimoteState.BalanceBoardState.CenterOfGravity.Y;
        }