October 29, 2014 | Projects, Technical
Finally received the Myo Gesture Control Armband! Myo is able to sense muscle activity in the wearers’ arm and uses machine learning techniques to determine what hand gestures they are performing. It can also sense position and orientation through other built in sensors (accelerometer, gyroscope, etc.). I thought I would test it out by using the captured gestures to control a Sphero 2.0 Robotic Ball. In the video below I use arm orientation, wave in and out hand gestures to move the Sphero ball in 4 directions (right, left, forward and backwards).
My development environment was Mac OS X Desktop with the Xcode compiler. The Sphero and Myo have Mac SDKs.
Below are snippets of the most relevant aspects of the code to Myo-Sphero interaction. I modified the “Hello World” Sphero App that came with the Mac SDK to include all the appropriate libraries and functions required for Myo. In the “AppDelegate.h” file I declared four system variables that would store gesture and arm orientation data.
@property int myoRoll; @property int myoPitch; @property int myoYaw;
The following function is triggered every time new arm orientation data is received. The data is stored in the system variables I declared for arm orientation.
-(void)myo:(Myo *)myo onOrientationDataWithRoll:(int)roll pitch:(int)pitch yaw:(int)yaw { myoRoll = roll; myoPitch = pitch; myoYaw = yaw; }
The function below is triggered every time a new gesture is detected from the user’s arm by Myo. I look for the “Wave In” and “Wave Out” gestures, as well as the “myoRoll” and “myoPitch” variables to determine what command to send to the Sphero ball. The values I used in the “If” statements for roll and pitch were based on trial and error.
-(void)myo:(Myo *)myo onPose:(MyoPose *)pose { poseType = pose.poseType; if (poseType == MyoPoseTypeWaveIn) { // Go left if (myoRoll >= 10 && myoPitch <= 10) [RKRollCommand sendCommandWithHeading:270.0 velocity:0.6]; else // Come back [RKRollCommand sendCommandWithHeading:180.0 velocity:0.6]; } else if (poseType == MyoPoseTypeWaveOut) { // Go right if (myoRoll >= 10 && myoPitch <= 10) [RKRollCommand sendCommandWithHeading:90.0 velocity:0.6]; else // Go forward [RKRollCommand sendCommandWithHeading:0.0 velocity:0.6]; } }
For development in other environments take a look at available SDKs for Sphero here and Myo here.