the slap

Dependencies:   Encoder HIDScope MODSERIAL TextLCD mbed-dsp mbed

Fork of The_SLAP_5_1 by Daan

Files at this revision

API Documentation at this revision

Comitter:
Daanmk
Date:
Tue Oct 21 13:35:52 2014 +0000
Child:
1:96cd4c9c5465
Commit message:
porject;

Changed in this revision

Encoder.lib Show annotated file Show diff for this revision Revisions of this file
HIDScope.lib Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-dsp.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Encoder.lib	Tue Oct 21 13:35:52 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Daanmk/code/Encoder/#9a8b76f0908c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HIDScope.lib	Tue Oct 21 13:35:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tomlankhorst/code/HIDScope/#e44574634162
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Tue Oct 21 13:35:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#180e968a751e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 21 13:35:52 2014 +0000
@@ -0,0 +1,106 @@
+/***************************************/
+/*                                     */
+/*   BRONCODE GROEP 5, MODULE 9, 2014  */
+/*       *****-THE SLAP-******         */
+/*                                     */
+/* -Dominique Clevers                  */
+/* -Rianne van Dommelen                */
+/* -Daan de Muinck Keizer              */
+/* -David den Houting                  */
+/* -Marjolein Thijssen                 */
+/***************************************/
+#include "mbed.h"
+#include "HIDScope.h"
+#include "arm_math.h"
+#include "encoder.h"
+
+#define M1_PWM PTC8 //blauw
+#define M1_DIR PTC9 //groen
+#define M2_PWM PTA5 //blauw
+#define M2_DIR PTA4 //groen
+#define TSAMP 0.005  // Sampletijd, 200Hz
+#define PI 3.1415926535897
+
+Encoder motor1(PTD2,PTD0); //geel,wit
+Encoder motor2(PTD5,PTA13);//geel,wit
+PwmOut pwm_motor1(M1_PWM);
+PwmOut pwm_motor2(M2_PWM);
+DigitalOut motordir2(M2_DIR);
+DigitalOut motordir1(M1_DIR);
+AnalogIn emg0(PTB0); //Biceps
+AnalogIn emg1(PTB1); //Triceps
+HIDScope scope(6);
+
+MODSERIAL pc (USBTX,USBRX,64,1024);
+pc.baud(115200);
+
+int const   windowsamples = 60; //aantal samples waaruit het window voor MOVAG bestaat
+
+float emg0_value_f32,filtered_emg0_notch,filtered_emg0_notch_highpass,filtered_emg0_notch_highpass_lowpass,filtered_emg0_eindsignaal_abs; //variable to store value in for biceps 
+float emg1_value_f32,filtered_emg1_notch,filtered_emg1_notch_highpass,filtered_emg1_notch_highpass_lowpass,filtered_emg1_eindsignaal_abs; //variable to store value in for triceps 
+float xpos_max,xpos_min,xneg_max,xneg_min;     //kalibratiewaardes
+
+float emg_biceps [windowsamples];
+float emg_triceps [windowsamples];
+
+void meting()
+{
+    arm_biquad_casd_df1_inst_f32 notch;
+    //constants for 50Hz notch
+    float notch_const[] = {0.9695312529087462, -0.0, 0.9695312529087462, 0.0, -0.9390625058174924};
+    //state values
+    float notch_states[4];
+    arm_biquad_casd_df1_inst_f32 highpass;
+    //constants for 20Hz highpass
+    float highpass_const[] = {0.638945525159022, -1.277891050318045, 0.638945525159022, 1.142980502539901, -0.412801598096189};
+    //state values
+    float highpass_states[4];
+    //constants for 80Hz lowpass
+    arm_biquad_casd_df1_inst_f32 lowpass;
+    float lowpass_const[] = {0.638945525159022, 1.277891050318045, 0.638945525159022, -1.142980502539901, -0.412801598096189};
+    //state values
+    float lowpass_states[4];
+ 
+    /*put raw emg value in emg_value*/
+    emg0_value_f32 = emg0.read();   
+    emg1_value_f32 = emg1.read();
+ 
+    //process emg biceps
+    arm_biquad_cascade_df1_f32(&notch, &emg0_value_f32, &filtered_emg0_notch, 1 );
+    arm_biquad_cascade_df1_f32(&highpass, &filtered_emg0_notch, &filtered_emg0_notch_highpass, 1 );
+    arm_biquad_cascade_df1_f32(&lowpass, &filtered_emg0_notch_highpass, &filtered_emg0_notch_highpass_lowpass, 1 );
+    filtered_emg0_eindsignaal_abs = fabs(filtered_emg0_notch_highpass_lowpass);  
+    emg_biceps [0]= filtered_emg0_eindsignaal_abs;
+    
+    //process emg triceps
+    arm_biquad_cascade_df1_f32(&notch, &emg1_value_f32, &filtered_emg1_notch, 1 );
+    arm_biquad_cascade_df1_f32(&highpass, &filtered_emg1_notch, &filtered_emg1_notch_highpass, 1 );
+    arm_biquad_cascade_df1_f32(&lowpass, &filtered_emg1_notch_highpass, &filtered_emg1_notch_highpass_lowpass, 1 );
+    filtered_emg1_eindsignaal_abs = fabs(filtered_emg1_notch_highpass_lowpass);  
+    emg_triceps [0]= filtered_emg1_eindsignaal_abs;
+    
+    //Movag
+    //Variabelen voor berekenen gemiddelden 
+    float avg0,avg1;
+    avg0=avg1=0;
+    
+    //Inhoud van een buffer (=gefilterd signaal) optellen
+    for(int x=0; x<windowsamples; x++) {
+        avg0 = avg0 + (emg_biceps[x]);
+        avg1 = avg1 + (emg_triceps[x]);
+    }
+    
+    //Gemiddelde berekenen en relativeren tov maximum voluntary contraction
+    avg0 = gain_biceps*avg0/windowsamples/biceps_max;
+    avg1 = gain_triceps*avg1/windowsamples/triceps_max;
+}
+
+int main()
+{
+    Ticker log_timer;
+    log_timer.attach(meting, TSAMP);
+    while(1) //Loop
+    {
+      
+    }
+}    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-dsp.lib	Tue Oct 21 13:35:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/mbed-official/code/mbed-dsp/#7a284390b0ce
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 21 13:35:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file