(30 gadget day 1) MYO get started

MYO

MYO是一款类似Leap motion的新型人机交互HCI设备。它被戴在人的前臂,从而可以感知人的肌肉电流,进而识别出人的各种手势动作,比如向左向右挥手。

《(30 gadget day 1) MYO get started》

官方给出的MYO的几个用途是

  • 做展示。挥挥手就能换页,或者将Prezi的控制变成它应有的样子。
  • 控制手机。比如跑步的时候挥挥手就能切换歌曲,玩1024之类的。
  • 智能家居。打个响指就能让电视开机之类的。
  • 控制那些会跑的。现在支持了Sphero和Parrot Drone。

另一个我觉得很酷的例子是Armin Van Buuren在一次演出里使用MYO来辅助增强现场表演效果。特别有未来实时大规模交互演出的感觉。那些具体的表演视频就大家自己去搜吧。

《(30 gadget day 1) MYO get started》

我买了两个MYO腕带,下面三天我们就来想想能用它来玩点什么~(那上面的标志是在亮的,真的挺酷)

《(30 gadget day 1) MYO get started》

MYO的结构

《(30 gadget day 1) MYO get started》

整个MYO中间靠近皮肤的部分都布满了各种金属触点,所以戴起来的时候完全不在乎什么角度。充电用的是标准的Micro USB。

《(30 gadget day 1) MYO get started》

开发者视角

跟Leap motion类似,MYO提供两类输入数据:空间数据(Spatial data),手势数据(Gestural data)和唯一一种反馈接口,震动(vibration command)。

空间数据包括两个维度:方向(orientation),三维的加速度向量(acceleration vector)。
手势数据包括几种特定的手势,比如握拳等。

iOS sample

当然,MYO提供了基本所有平台的SDK(当然Windows phone除外)。开发起来最方便的还是Mac啦,windows要装一堆驱动啥的。如果只是开发应用的话,基本之用跟Android/iOS的SDK打交道就好啦。如果需要底层数据,MYO也提供C lib API。另外,还有一种用Lua写的Myo Scripts

《(30 gadget day 1) MYO get started》

跟各种Sensor的使用类似,MYO的数据是以回调传递事件的方式来提供。MYO提供三类事件,如前面所说所空间事件,手势事件,以及一些辅助类的事件(如连接,断开设备等)。

开发MYO应用的最好方式就是先运行sample程序。iOS的SDK里面包括一个Doc和叫HelloMyo的Sample程序。打开Sample,运行,玩玩就好了。(MYO SDK开发速度很快,所以如果发现Sample程序告知版本太低,则需要连上USB和蓝牙发射器进行一次升级)。

看看代码吧。

- (void)viewDidLoad {
    [super viewDidLoad];

    // Data notifications are received through NSNotificationCenter.
    // Posted whenever a TLMMyo connects
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(didConnectDevice:)
                                          name:TLMHubDidConnectDeviceNotification
                                          object:nil];
    // Posted whenever a TLMMyo disconnects.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(didDisconnectDevice:)
                                          name:TLMHubDidDisconnectDeviceNotification
                                          object:nil];
...
    // Posted when a new pose is available from a TLMMyo.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(didReceivePoseChange:)
                                          name:TLMMyoDidReceivePoseChangedNotification
                                          object:nil];

}

首先是注册各种事件,包括连接断开连接,这里有个Sync Gesture,指的是一种比较奇怪的动作(不大好描述)。应该是MYO用来给手臂肌肉电流做一个基本的base line吧。

最有用的可能就是TLMMyoDidReceivePoseChangedNotification了。一旦有新的姿势检测到,这个函数就能收到一次callback。来看这个Callback的内容。

- (void)didReceivePoseChange:(NSNotification *)notification {
    // Retrieve the pose from the NSNotification's userInfo with the kTLMKeyPose key.
    TLMPose *pose = notification.userInfo[kTLMKeyPose];
    self.currentPose = pose;

    // Handle the cases of the TLMPoseType enumeration, and change the color of helloLabel based on the pose we receive.
    switch (pose.type) {
        case TLMPoseTypeUnknown:
        case TLMPoseTypeRest:
        case TLMPoseTypeDoubleTap:
            // Changes helloLabel's font to Helvetica Neue when the user is in a rest or unknown pose.
            self.helloLabel.text = @"Hello Myo";
            self.helloLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:50];
            self.helloLabel.textColor = [UIColor blackColor];
            break;
        case TLMPoseTypeFist:
            // Changes helloLabel's font to Noteworthy when the user is in a fist pose.
            self.helloLabel.text = @"Fist";
            self.helloLabel.font = [UIFont fontWithName:@"Noteworthy" size:50];
            self.helloLabel.textColor = [UIColor greenColor];
            break;
        case TLMPoseTypeWaveIn:
            // Changes helloLabel's font to Courier New when the user is in a wave in pose.
            self.helloLabel.text = @"Wave In";
            self.helloLabel.font = [UIFont fontWithName:@"Courier New" size:50];
            self.helloLabel.textColor = [UIColor greenColor];
            break;
        case TLMPoseTypeWaveOut:
            // Changes helloLabel's font to Snell Roundhand when the user is in a wave out pose.
            self.helloLabel.text = @"Wave Out";
            self.helloLabel.font = [UIFont fontWithName:@"Snell Roundhand" size:50];
            self.helloLabel.textColor = [UIColor greenColor];
            break;
        case TLMPoseTypeFingersSpread:
            // Changes helloLabel's font to Chalkduster when the user is in a fingers spread pose.
            self.helloLabel.text = @"Fingers Spread";
            self.helloLabel.font = [UIFont fontWithName:@"Chalkduster" size:50];
            self.helloLabel.textColor = [UIColor greenColor];
            break;
    }

    // Unlock the Myo whenever we receive a pose
    if (pose.type == TLMPoseTypeUnknown || pose.type == TLMPoseTypeRest) {
        // Causes the Myo to lock after a short period.
        [pose.myo unlockWithType:TLMUnlockTypeTimed];
    } else {
        // Keeps the Myo unlocked until specified.
        // This is required to keep Myo unlocked while holding a pose, but if a pose is not being held, use
        // TLMUnlockTypeTimed to restart the timer.
        [pose.myo unlockWithType:TLMUnlockTypeHold];
        // Indicates that a user action has been performed.
        [pose.myo indicateUserAction];
    }
}

内置的手势有这些:

TLMPoseTypeDoubleTap(拇指和中指连续点击两次)
TLMPoseTypeFist(握拳)
TLMPoseTypeWaveIn(向内挥手,戴在右手就是往左挥手)
TLMPoseTypeWaveOut(向外挥手)
TLMPoseTypeFingersSpread(按理来说是类似cross finger的意思,但似乎我没咋触发过这个pose)

基本就这么点儿代码。明天我们尝试把这个跟其他功能联系起来哈。

    原文作者:fxp
    原文地址: https://segmentfault.com/a/1190000002561254
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞