Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何保存不断变化的变量的当前值?_C#_Wpf_Double_Myo - Fatal编程技术网

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

C# 如何保存不断变化的变量的当前值?,c#,wpf,double,myo,C#,Wpf,Double,Myo,我正在WPF应用程序中的类型双变量中存储传感器的度数读数,degreeOutput来自Thlamic实验室的Myo传感器。当用户移动手臂时,变量中存储的值会不断变化,但我希望在人做出拳头姿势时,存储运动中某一点的度数读数,而不是不断变化的值 在我当前的实现中,我触发degreeOutput的值以显示在PainfulArcStartBx中,以表示我要测量的弧的起始值,但这不符合计划 相反,当握紧拳头时,度值输出到文本框,但不断变化 我只想在握拳时输出初始读数,之后不输出任何读数 应该在放开第一个姿

我正在WPF应用程序中的类型双变量中存储传感器的度数读数,
degreeOutput
来自Thlamic实验室的Myo传感器。当用户移动手臂时,变量中存储的值会不断变化,但我希望在人做出
拳头
姿势时,存储运动中某一点的度数读数,而不是不断变化的值

在我当前的实现中,我触发
degreeOutput
的值以显示在
PainfulArcStartBx
中,以表示我要测量的弧的起始值,但这不符合计划

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

我只想在握拳时输出初始读数,之后不输出任何读数

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

有人对我如何只存储握拳点的当前值和松开拳头姿势的当前值有什么建议吗

这是处理度输出的方法:

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;

                }




            })); 

        }

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

       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;

            }




        })); 

    }

我会用双份的?但这就是我刚才键入的内容。@TonyHopkinson给出了这一行:
App.Current.Dispatcher.Invoke
这是一个RT应用程序,因此在应用程序架构中,我也不会使用它,这需要是VM上的一个
可观察属性
,但OP没有提供超出必要范围的更多信息,所以@zaitsman我现在要测试它,但是痛苦的arcendtbx应该在第一个姿势停止后存储度数读数的值,我认为在上面的代码中,当您将其设置为
degreeOutput