From aca6689a5a27f16fb7eda5fc20ef92519deaeb10 Mon Sep 17 00:00:00 2001 From: mark-toma Date: Thu, 5 May 2016 02:17:51 -0400 Subject: [PATCH 1/5] Ignores MATLAB autosave files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7ba2255..393243d 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ Temporary Items # MEX-file binaries *.mex* +*.asv From de03079c56662868eb780f85105e28f2e05112c6 Mon Sep 17 00:00:00 2001 From: mark-toma Date: Thu, 5 May 2016 02:19:42 -0400 Subject: [PATCH 2/5] Adds MATLAB help for MEX function myo_2c_sfunc --- myo_2c_sfunc.m | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 myo_2c_sfunc.m diff --git a/myo_2c_sfunc.m b/myo_2c_sfunc.m new file mode 100644 index 0000000..94e4da7 --- /dev/null +++ b/myo_2c_sfunc.m @@ -0,0 +1,34 @@ +% MYO_2C_SFUNC(NUM) Poll Myo for NUM samples +% This MEX function collects Myo data by polling with best-effort +% approach to collect NUM samples. Data is returned in a single struct +% output variable. +% +% Usage: +% F = myo_2c_sfunc() +% Returns one data sample from Myo in output struct F. +% +% F = myo_2c_sfunc(num) +% Same as above, but returns num samples in scalar output struct F. +% Note that if input num is not provided, the default is 1. +% +% Inputs +% num (optional) +% Number of samples to collect from Myo. The default value is 1. +% +% Outputs +% F +% Structure containing vectors of Myo data samples with the following +% fields +% F.Roll TODO +% F.Pitch TODO +% F.Yaw TODO +% F.accData TODO +% F.gyroData TODO +% F.emgData TODO +% F.onArm TODO +% F.isUnlocked TODO +% F.onWhichArm TODO +% F.whichPose TODO +% F.eCounter TODO +% F.aCounter TODO +% F.gCounter TODO From e8b0c20cf9adefd6e4e205c4b4eb7239f341da51 Mon Sep 17 00:00:00 2001 From: mark-toma Date: Thu, 5 May 2016 02:43:54 -0400 Subject: [PATCH 3/5] Adds input num Allows caller to specify number of samples desired. Checks value type and value. --- myo_2c_sfunc.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/myo_2c_sfunc.cpp b/myo_2c_sfunc.cpp index 2ac3253..4fef0ae 100644 --- a/myo_2c_sfunc.cpp +++ b/myo_2c_sfunc.cpp @@ -9,6 +9,9 @@ #include #include "myo_class2a.hpp" +#define NUM_DEF 1 +#define NUM_MAX 12000UL + DataCollector dataCollector; @@ -46,7 +49,26 @@ mxArray *create_fill_EMG (const std::array emgData) void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { - + long int num = NUM_DEF; // default value for input num + + // handle optional input num + if ( nrhs>0 ) { // user input value for num + // check for valid input type and size + if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || + !(mxGetM(prhs[0])==1 && mxGetM(prhs[0])==1) ) + mexErrMsgTxt("Input num must be a real numeric scalar."); + // get the input value + num = *mxGetPr(prhs[0]); // implicit cast to integer value + // check for valid input value + if (num<1 || num>NUM_MAX) + mexErrMsgTxt("Input num is out of range."); + } + + // check number of output arguments + if(nlhs > 1){ + mexErrMsgTxt("Too many output arguments."); + } + myo::Hub hUb("com.example.hello-myo"); hUb.addListener(&dataCollector); myo::Myo* mYo = hUb.waitForMyo(10); @@ -80,7 +102,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) plhs[0] = mxCreateStructMatrix (1, 1, frame_fields, frame_field_names); int counter=0; - int mRow=12000; + int mRow=num;//12000; const mwSize dims[]={mRow,1}; const mwSize dimsV[]={mRow,3}; @@ -100,14 +122,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mxArray *mxaCounter = mxCreateNumericArray (2, dims, mxDOUBLE_CLASS, mxREAL); mxArray *mxgCounter = mxCreateNumericArray (2, dims, mxDOUBLE_CLASS, mxREAL); - /* Check for proper number of input and output arguments */ - if (nrhs !=0) { - mexErrMsgTxt("No input argument required."); - } - if(nlhs > 1){ - mexErrMsgTxt("Too many output arguments."); - } - + // int counter=1; // // Finally we enter our main loop. From e8d3f03d22a76f2f60fadaf8ef4ada046cb519ce Mon Sep 17 00:00:00 2001 From: mark-toma Date: Thu, 5 May 2016 02:44:35 -0400 Subject: [PATCH 4/5] Adds calling syntax for input num Also shows tests for unexpected use error cases on input num. --- test_matMyo.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test_matMyo.m b/test_matMyo.m index 7c8a33a..a9404a8 100644 --- a/test_matMyo.m +++ b/test_matMyo.m @@ -2,9 +2,20 @@ clear clc - f=myo_2c_sfunc ; - + % f=myo_2c_sfunc; % default one sample + % f=myo_2c_sfunc(1); % explicit one sample + f=myo_2c_sfunc(10000); + +% Input error cases +% [~,~] = myo_2c_sfunc; % too many outputs +% myo_2c_sfunc({}); % bad data type +% myo_2c_sfunc(''); % bad data type +% myo_2c_sfunc(struct); % bad data type +% myo_2c_sfunc(0); % bad value +% myo_2c_sfunc(-1); % bad value +% myo_2c_sfunc(1e8); % bad value + %% [~, ind]=unique(f.eCounter); From cedb909752cb9a47137d37cb61a096128c8d0507 Mon Sep 17 00:00:00 2001 From: mark-toma Date: Thu, 5 May 2016 02:45:34 -0400 Subject: [PATCH 5/5] Ignores mex binaries --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 393243d..70a9c40 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ Temporary Items *.mex* *.asv +*.mexw64