如何保存不断变化的变量的当前值?

时间:2015-01-31 21:46:41

标签: c# wpf double myo

我在来自Thalmic Lab的Myo传感器的WPF应用程序中degreeOutput存储来自传感器的度读数。存储在变量中的值随着用户移动他们的手臂而不断变化,但是当人做出fist姿势而不是不断变化的值时,我想将度读数存储在运动中的某个点上。

在我当前的实现中,我触发degreeOutput的值显示在painfulArcStartTbx中以表示我想要测量的弧的起始值,但这不起作用计划。

相反,当握住拳头时,度数值会输出到文本框,但会不断变化。

我希望只有在握拳后才能输出初始读数。

在释放第一个姿势后,应该输出弧的结束读数,但是我得到与上面相同的行为。

有没有人对如何在握拳时保存当前值以及第一个姿势放开的当前值有任何建议?

这是处理学位输出的方法:

private void Myo_OrientationDataAcquired(object sender, OrientationDataEventArgs e)
        {
           App.Current.Dispatcher.Invoke((Action)(() =>
            {

                //need to record degree reading when pose made that
                //signifies begining of painful arc.
                //then specify a second pose that signals the end of
                //painful arc and store arc reading, eg 92dg - 108dg


                //myo indicator must be facing down or degrees will be inverted.
                degreeOutput = ((e.Pitch + PITCH_MIN) * CALLIBRATION_FACTOR);

                degreeOfAbductionTbx.Text = "Degree: " + degreeOutput;

                if(e.Myo.Pose == Pose.Fist)
                {
                    //get the start reading of the painful arc
                    painfulArcStartTbx.Text = "start: " + degreeOutput;

                }
                //then get the finish reading of the painful arc
                //after the fist pose has been let go, indicating
                //end of pain in movement
                else
                {

                    painfulArcEndTbx.Text = "end: " + degreeOutput;

                }




            })); 

        }

1 个答案:

答案 0 :(得分:3)

我可能完全错了,因为我不知道传感器是什么,但似乎你遗漏了一些非常基本的东西:

       private string startingDegree;
       private string endDegree;  
       private void Myo_OrientationDataAcquired(object sender, OrientationDataEventArgs e)
    {
       App.Current.Dispatcher.Invoke((Action)(() =>
        {

            //need to record degree reading when pose made that
            //signifies begining of painful arc.
            //then specify a second pose that signals the end of
            //painful arc and store arc reading, eg 92dg - 108dg


            //myo indicator must be facing down or degrees will be inverted.
            degreeOutput = ((e.Pitch + PITCH_MIN) * CALLIBRATION_FACTOR);

            degreeOfAbductionTbx.Text = "Degree: " + degreeOutput;

            if(e.Myo.Pose == Pose.Fist)
            {
               endDegree = string.Empty;
               if(string.IsNullOrEmpty(startingDegree))
                {
                    startingDegree = "start: " + degreeOutput;
                }

                //get the start reading of the painful arc
                painfulArcStartTbx.Text = startingDegree;

            }
            //then get the finish reading of the painful arc
            //after the fist pose has been let go, indicating
            //end of pain in movement
            else
            {
                startingDegree = string.Empty;
                if(string.IsNullOrEmpty(endDegree))
                {
                    endDegree = "end: " + degreeOutput;
                }
                painfulArcEndTbx.Text = endDegree;

            }




        })); 

    }