Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Biquad HIDScope biquadFilter mbed BiQuad4th_order
main.cpp
00001 #include "mbed.h" 00002 #include "HIDScope.h" 00003 #include "BiQuad.h" 00004 #include "BiQuad4.h" 00005 #include "FilterDesign.h" 00006 #include "FilterDesign2.h" 00007 00008 // This part of the code is used for filtering the two EMG signals and determining if the robot has to move. 00009 00010 //Define objects 00011 AnalogIn emg1_raw( A0 ); 00012 AnalogIn emg2_raw( A1 ); 00013 DigitalOut ledr(LED_RED); 00014 DigitalOut ledg(LED_GREEN); 00015 00016 Ticker sample_EMGtoHIDscope; //Used to send to hidscope 00017 HIDScope scope(4); //Number of channels which needs to be send to the HIDScope 00018 00019 int need_to_move_1; // Does the robot needs to move in the first direction? 00020 int need_to_move_2; // Does the robot needs to move in the second direction? 00021 double EMG_calibrated_max_1 = 2.00000; // Maximum value of the first EMG signal found in the calibration state. 00022 double EMG_calibrated_max_2 = 2.00000; // Maximum value of the second EMG signal found in the calibration state. 00023 00024 float threshold_EMG = 0.25; // Threshold on 25 percent of the maximum EMG 00025 00026 double emg1_filtered = 0.00; 00027 double emg2_filtered = 0.00; 00028 00029 00030 // Sample: samples the EMG and sends it to HIDScope 00031 void sample() 00032 { 00033 emg1_filtered = FilterDesign(emg1_raw.read()); 00034 emg2_filtered = FilterDesign2(emg2_raw.read()); 00035 00036 scope.set(0, emg1_raw.read()); // Raw EMG 1 send to scope 0 00037 scope.set(1, emg1_filtered); // Filtered EMG 1 send to scope 1 00038 scope.set(2, emg2_raw.read()); // Raw EMG 2 send to scope 2 00039 scope.set(3, emg2_filtered); // Filtered EMG 2 send to scope 3 00040 scope.send(); // Send the data to the computer 00041 } 00042 00043 int main() 00044 { 00045 // Attach the 'sample' function to the timer 'sample_timer'. Frequency is 50 Hz. 00046 sample_EMGtoHIDscope.attach(&sample, 0.02f); 00047 00048 while(1) { 00049 if (emg1_filtered >= (threshold_EMG*EMG_calibrated_max_1)){ 00050 need_to_move_1 = 1; // The robot does have to move 00051 ledr = 1; // Red LED off 00052 ledg = 0; // Green LED on 00053 } 00054 else { 00055 need_to_move_1 = 0; // If the robot does not have to move 00056 ledr = 0; // Red LED on 00057 ledg = 1; // Green LED off 00058 } 00059 00060 if(emg2_filtered >= threshold*EMG_calibrated_max_2){ 00061 need_to_move_2 = 1; 00062 ledr = 0; 00063 ledg = 1; 00064 } 00065 else { 00066 need_to_move_2 = 0; 00067 ledr = 1; 00068 ledg = 0; 00069 } 00070 } 00071 }
Generated on Tue Jul 26 2022 02:50:20 by
1.7.2