问题描述
我正在使用Myo臂带在WPF中开发一个项目,到目前为止,该臂带可以识别设备已连接并更新文本框的信息,但是当我设置事件处理程序以识别姿势是否触发事件时
I'm developing a project in WPF using a Myo arm band which works so far in recognizing the device has connected and updates info to the textbox, but when I set up the event handler for recognizing if a pose is triggered the event never fires.
我通过使用设备摆姿势并握住它们来调试此问题,还在此行上设置了一个断点 pose.Triggered + = Pose_Triggered;
和姿势触发事件的开始。
I debugged this by making poses with the device and holding them, also I set a break point on this line pose.Triggered += Pose_Triggered;
and the start of the pose triggered event.
断点在第一行触发,但不触发实际事件的断点 private void Pose_Triggered(object sender,PoseEventArgs e)
The break point triggers on the first line where the but it doesn't trigger the breakpoint on the actual event private void Pose_Triggered(object sender, PoseEventArgs e)
这是C#包装程序正在为该项目使用:
This is the C# wrapper I'm using for the project: https://github.com/tayfuzun/MyoSharp
有人知道活动姿势时为何不触发事件吗?
Does anyone know why the event doesn't trigger although the poses are being made?
pose_triggered
被调用并发生以下事件:
This is the method where pose_triggered
is called and the event:
// listen for when the Myo connects
hub.MyoConnected += (sender, e) =>
{
this.Dispatcher.Invoke((Action)(() =>
{
statusTbx.Text = "Myo has connected! " + e.Myo.Handle;
e.Myo.Vibrate(VibrationType.Short);
// unlock the Myo so that it doesn't keep locking between our poses
e.Myo.Unlock(UnlockType.Hold);
// setup for the pose we want to watch for
var pose = HeldPose.Create(e.Myo, Pose.Fist);
pose.Triggered += Pose_Triggered;
e.Myo.OrientationDataAcquired += Myo_OrientationDataAcquired;
}));
};
触发事件的代码:
private void Pose_Triggered(object sender, PoseEventArgs e)
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
//need to measure abduction of arm from 0 to 180 degrees.
poseStatusTbx.Text = "{0} arm Myo holding pose {1}" + e.Myo.Arm + e.Myo.Pose;
pitch = pitchCentre;
}));
}
以下是该类的完整代码:
Here is the complete code for the class: http://hastebin.com/xinirugufo.cs
推荐答案
我比较了和您的。您忘了叫 pose.Start()
吗?
I compare the sample code from GitHub and your. Did you forget to call pose.Start()
?
var pose = HeldPose.Create(e.Myo, Pose.Fist);
pose.Interval = TimeSpan.FromSeconds(0.5);
pose.Start(); //this???
pose.Triggered += Pose_Triggered;
这篇关于使用Myo臂带调用姿势触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!