请选择 进入手机版 | 继续访问电脑版

EMG_sensor Application1---Dry up

[复制链接]

5

主题

9

帖子

47

积分

新手上路

Rank: 1

积分
47
yuyu_morning 发表于 2017-11-13 22:31:08
3844 0
本帖最后由 yuyu_morning 于 2017-11-16 20:09 编辑

Recently saw a post about the EMG-type Head-mounted mouse, I think the sensor of the EMG is very interesting.
After in-depth understanding, I had several ideas and made two small demos with ArduinoI think it's not bad, to share with everyone
Demo1: Identify if a signal has occurred.
Demo2.etermine the strength of each signal
I'm not just talking about it,look at the pictures. (These demos I made arrcording to the example which provided by OYMOTION)


This picture is plotted using serial port drawing tool in the Arduino and the data is filtered using the provided EMG_Filter library.
Figure 1 shows the numerical changes with processed which the voltage signal detected by the EMG sensor when we make a fist.
Figure 2 shows the signal values collected by the EMG sensor when our muscles were relaxed.
Figure 3 shows the value of the fist signal minus the value of the relaxation signal.Very interesting is not it?
Here, many readers may already understand how to achieve the two ideas just mentioned!It’s right!
Here I got the data from Figure 3, determinedwhether there is a signal generated or the signal strength with the integral method.
Well, This is the hardware connection diagram, wanted to know others please referred the example.

After reading the figure and then put some code to see (code 1: Capture the number of signals!)
  1. #if defined(ARDUINO) && ARDUINO >= 100
  2. #include "Arduino.h"
  3. #else
  4. #include "WProgram.h"
  5. #endif

  6. /*Call the filter library, the data collected by the AD filter processing, filter out the frequency 50Hz
  7. *
  8. */
  9. #include "EMGFilters.h"   
  10.   
  11. //macro definitions of print debugging information            
  12. #define TIMING_DEBUG 1
  13. // defined AD acquisition channel
  14. #define sensorInputPin A0

  15. /*Enumeration definition:Data processing methods After filtering
  16.   *1.The duration of each signal(Not yet)
  17.   *2.The number of signals over a period of time
  18.   *
  19.   */

  20. enum EMGCalculatMode {
  21.   FistTimeMode = 50,
  22.   FistNumMode = 200
  23. };

  24. /*Filter processing section,detailed please redirect to the library of EMG_Fliter
  25. *
  26. */
  27. EMGFilters myFilter;
  28. SAMPLE_FREQUENCY sampleRate = SAMPLE_FREQ_500HZ;
  29. NOTCH_FREQUENCY humFreq = NOTCH_FREQ_50HZ;

  30. /*threshold:value of relaxed
  31. * fistNum:variable of recording the number of signals
  32. *The program shows the situation is after measuring reference value and re-burn into it
  33.   */
  34. long threshold = 500, fistNum = 0;

  35. /*Two variables used to determine the time of signal disappear
  36. *
  37. */
  38. unsigned long timeMillis = 0, timeBeginzero = 0;

  39. /*Two integral variables used to determine whether the signal persists*/
  40. long integralData = 0, integralDataEve = 0;

  41. /*The variable of TimeStandardused to determine the signal generation and disappearance。
  42. *For example,set here for 200ms,represented if the integral value does not change more than 200ms ,
  43. *think of a signal ended
  44. */
  45. int  TimeStandard = (uint8_t)FistNumMode;

  46. /*The flag variable of time record
  47. *
  48. */
  49. bool remainFlag = false;

  50. void setup() {
  51. //Filter initialization
  52.   myFilter.init(sampleRate, humFreq, true, true, true);
  53. //Serial port settings
  54.   Serial.begin(115200);
  55. }
  56. void loop() {
  57.   int value, dataAfterFilter, envlope;
  58. //Read AD data
  59.   value = analogRead(sensorInputPin);
  60. //Filter processing
  61.   dataAfterFilter = myFilter.update(value);
  62. //Squared, remove the data of less than 0
  63.   envlope = sq(dataAfterFilter);
  64. //Set data smaller than the reference value to 0, indicating that it is in a relaxed state
  65. envlope = (envlope > threshold) ? envlope : 0;

  66. /*If the value of threshold equals zero,represented this is in the calibration process,
  67. *the following codes are not executed,only printed the signal value
  68. */
  69.   if (threshold > 0) {
  70.     /*Integral processing, continuously add the signal value,
  71.      *and compared with the previous sampling of the integral value to
  72.      *determine whether the signal continued
  73.      */
  74.     integralDataEve = integralData;
  75.     integralData += envlope;

  76.     if ((integralDataEve == integralData) && (integralDataEve != 0)) {
  77.     /*If the integral value doesn’t change and doesn’t equal zero, recorded the time;
  78.      * If the integral value starts to changed again,setted the remainFlag to true,
  79.      *and recorded time next time re-enter
  80.      */
  81.       timeMillis = millis();
  82.       if (remainFlag) {
  83.         timeBeginzero = timeMillis;
  84.         remainFlag = false;
  85.       }
  86.        /*If the integral value does not changed within 200 milliseconds, represented a fist signal is generated.
  87.         *Clear the integral value and the variable of fistNum plus one.
  88.         */
  89.       if ((timeMillis - timeBeginzero) > TimeStandard) {
  90.         integralDataEve = integralData = 0;
  91.         fistNum ++;
  92.         Serial.print("fistNum=");   Serial.println(fistNum);
  93.       }
  94.     }
  95.     else {
  96.       remainFlag = true;
  97.     }
  98.    //Print the data of debugging informations
  99.     if (TIMING_DEBUG) {
  100.       // Serial.println(envlope);
  101.       //Serial.print("fistNum=");
  102.       //Serial.println(fistNum);
  103.     }
  104.   }
  105.   else {
  106.     Serial.println(envlope);
  107.   }
  108.   delayMicroseconds(500);
  109. }
复制代码

This code is divided into two executions, the first print the signal value of the relaxed state (that is threshold),and the value is given to the threshold;The second ,checked into the serial port monitor will see  fistNum value plus 1 when you made a fist.
Is not it fun! Then there is more fun!Since each fist can be detected, the accumulated value of the signal when fist can have a better method to use it?of course!
Space limit, the second code in the second post!


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热帖滚动