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: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of emg_import by
main.cpp
- Committer:
- daniQQue
- Date:
- 2016-10-28
- Revision:
- 38:23601b26bb84
- Parent:
- 37:60dd2e42bf8f
- Child:
- 39:c933a6c2b730
File content as of revision 38:23601b26bb84:
//libraries
#include "mbed.h"
#include "HIDScope.h"
#include "BiQuad.h"
//Define objects
AnalogIn emg_biceps_right_in( A0 ); //analog in to get EMG in to c++
Ticker sample_timer; //ticker
HIDScope scope( 3); //open 3 channels in hidscope
DigitalOut richting_motor1(D4); //motor1 direction output
PwmOut pwm_motor1(D5); //motor1 velocity output
DigitalOut led(LED_GREEN);
//define variables
double emg_biceps_right;
double emg_filtered_high_biceps_right;
double emg_abs_biceps_right;
double emg_filtered_biceps_right;
int onoffsignal=0;
double cut_off_value=0.04; //gespecifeerd door floortje
BiQuad filterhigh(9.1497e-01, -1.8299e+00, 9.1497e-01, -1.8227e+00, 8.3718e-01); //
BiQuad filterlow ( 3.9130e-05 , 7.8260e-05 , 3.9130e-05, -1.9822e+00 , 9.8239e-01); //
BiQuad notch( 2.0083e-02 , 4.0167e-02, 2.0083e-02 , -1.5610e+00 , 6.4135e-01);
//functions which are called in ticker
void filter(){
emg_biceps_right=emg_biceps_right_in.read(); //read the emg value from the elektrodes
emg_filtered_high_biceps_right= filterhigh.step(emg_biceps_right);
double emg_filtered_notch=notch.step(emg_filtered_high_biceps_right);
emg_abs_biceps_right=fabs(emg_filtered_notch); //fabs because float
emg_filtered_biceps_right=filterlow.step(emg_abs_biceps_right);
led=!led;
if (emg_filtered_biceps_right>cut_off_value)
{onoffsignal=1;}
else
{onoffsignal=0;}
//send signals to scope
scope.set(0, emg_filtered_notch ); //set emg signal to scope in channel 1
scope.set(1, emg_abs_biceps_right);
scope.set(2, emg_filtered_biceps_right);
scope.send(); //send all the signals to the scope
}
//program
int main()
{
sample_timer.attach(&filter, 0.001); //continously execute the EMG reader and filter, it ensures that filter and sampling is executed every 1/frequency seconds
//endless loop
while(1)
{
if (onoffsignal==1)
{
richting_motor1 = 0; //motordirection (ccw)
pwm_motor1 = 1; //motorspeed 1
}
else if(onoffsignal==0)
{
richting_motor1 = 0; //motordirection (ccw)
pwm_motor1 = 0; //motorspeed 0
}
}
}
