North (formerly Thalmic Labs), the creator of the Myo armband, was acquired by Google in June 2020. Myo sales ended in October 2018 and Myo software, hardware and SDKs are no longer available or supported. Learn more.

Myo Script

Myo Script Changes in Beta 7

Myo Script Changes in Beta 7

Beta 7  brought a lot of changes! Myo Script especially saw a big expansion, adding features previously only available in the full SDKs. I wanted to take the time to run through it in its own post, so lets get to it!

Coordinate System Changes

The first thing I wanted to get right up on front street is a change in behaviour. In previous betas you had figure out which way the user was wearing their Myo armband with myo.getXDirection() in order to interpret the values of myo.getPitch() and myo.getRoll(). Most of the time you wouldn't actually care about the orientation of the device though, so we decided to make that easier. We normalized getPitch and getRoll so that, from the perspective of the user wearing the armband, the values returned increase when moving their arm up and rolling clockwise, respectively. We also changed myo.getYaw() so positive was also moving clockwise (it was the other way around before).

So, toss out your old getXDirection code, and assume that up and clockwise is positive! Easy.

New Environment Variables

Rather than using the file name of your script in Application Manager (née Myo Script Manager), you can now set a scriptTitle variable, which will be shown instead. You will also want to set a scriptDetailsUrl, which should be the URL of your connector in the Myo Market. It’s going to look like this:

scriptDetailsUrl = ""  

Where the number at the end should be replaced by your application ID. You will see this in the URL as soon as you create a draft application in the Myo Market.

Acceleration and Gyroscope

A big limitation of Myo Script until this point had been lack of direct access to the accelerometer and gyroscope. We’ve fixed that in Beta 7 with the addition of myo.getGyro(), myo.getAccel(), and myo.getAccelWorld(). getGyro() returns the current angular velocity (x, y, z) of the Myo armband about it’s axes in radians per second. getAccel() will give you the acceleration of the Myo armband in gs, and getAccelWorld() does the same thing, but in the world frame of reference (ie, X and Y are parallel to the ground and Z is up). This opens up a lot of possible new gestures. Shake it!

Locking Policy

The Myo armband now has locking built in. In the standard policy (which is on by default), if you do a double tap in a supported application the armband will vibrate and unlock, allowing more poses through for a few seconds. Then it will lock again automatically after a few seconds. This is ideal for the common situation of the user wearing the armband for long periods of time, occasionally entering single commands. If that’s you, throw out your old unlock code and let us handle things for you.

Another very common situation is the user wanting to enter a sequence of commands, in which case you probably want the timer extended for a few seconds after each command. To do this, every time a pose is detected do myo.unlock(“timed”). If you have a hold gesture (like in the PowerPoint script) call myo.unlock(“hold”) (appropriately enough) when it starts, and myo.unlock(“timed”) when it’s released.

A general implementation of onPoseEdge in situations where you want new poses to extend the unlock might be something like this:

function onPoseEdge(pose, edge)  
       if (pose ~= "rest" and pose ~= "unknown") then -- hold if edge is on, timed if edge is off
          myo.unlock(edge == "off" and "timed" or "hold") 
       end -- Now handle poses as normal 

If your script should be unlocked all the time (ie, because it’s controlling a game), turn off the standard unlock policy completely with myo.setLockingPolicy(“none”).

MIDI Control

You can use Myo Script to easily send MIDI commands (to make music in something like Garage Band). How MIDI actually works is a bit beyond the scope of this article, but it’s available in the myo.midi() function. You can also now send MMC commands via the myo.midiMachineControl() function. Let us know in the comments or on Twitter if you’d like to see this explained further!

Final notes

It’s also worth noting that end users are now going expect a .myo file instead of .lua. Myo Connect is automatically set to associate with .myo files. When a user double clicks on them they get installed. Feel free to use .lua for your own development use if you want, but when you submit to the Myo Market make sure they are .myo files.

Myo Scripts are considered a type of “connector”, and should be referred to as such in the Market. The idea is that it’s a piece of software that “connects to” and allows you to control another application, but doesn't actually include the application in question. Right now Myo Scripts are the only connectors there are, but theoretically there could be more in the future.

Finally, we’re re-working our tutorials a bit to include the new changes in beta 7. The old posts will be updated, and you can look for the Myo Scripting Orientation and Gestures tutorial to resume shortly!

In the mean time, don’t forget to subscribe to this blog, follow us on Twitter, and sign up for our newsletter!

Good luck, and happy coding!

You've successfully subscribed to The Lab!