2015-01-31 92 views
1

我正在存儲一個WPF應用程序中的類型雙變量傳感器的讀數,來自Thalmic Lab的Myo傳感器的degreeOutput。存儲在變量中的值隨着用戶移動手臂而不斷變化,但是我希望在人物姿勢不是不斷變化的值時,將運動中某個點的度數讀數存儲起來。如何保存不斷變化的變量的當前值?

在我當前的實現中,我觸發painfulArcStartTbx中顯示的degreeOutput的值來表示我想要測量的弧的起始值,但這不符合計劃。

取而代之的是,當握住拳頭時,度數值輸出到文本框,但是不斷變化。

我希望只有在握拳之後沒有任何閱讀時才輸出初始閱讀。

圓弧的末端讀數應該在拳頭姿勢鬆開後輸出,但是我得到的結果與上面相同。

有沒有人有任何建議,我可以如何才能存儲當前價值的拳頭舉行點和當前價值的拳頭姿勢是放手?

這就是度輸出處理方法:

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; 

       } 




      })); 

     } 

回答

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; 

      } 




     })); 

    } 
+0

那麼我會用雙?但那正是我剛纔輸入的內容。 – 2015-01-31 21:58:53

+0

@TonyHopkinson給出這一行:'App.Current.Dispatcher.Invoke'這是一個RT應用程序,所以在應用程序體系結構我不會這樣做,這需要在虛擬機上是'ObservableProperty',但是OP沒有提供超出必要性的許多信息,所以。 – zaitsman 2015-01-31 22:01:40

+0

@zaitsman我現在就來測試一下,但是痛苦的ArcEndTbx應該在剛剛停止握拳姿勢後存儲讀取的度數值,我認爲在上面的代碼末尾將會是一個不斷變化的值,因爲您將它設置爲'degreeOutput' – 2015-01-31 22:07:48