4 directional EMG control of the XY table. Made during my bachelor end assignment.

Dependencies:   C12832_lcd HIDScope mbed-dsp mbed

main.cpp

Committer:
jessekaiser
Date:
2015-04-28
Revision:
14:bbef6e8956dc
Parent:
13:c4e80f6e7113

File content as of revision 14:bbef6e8956dc:

#include "mbed.h"
#include "C12832_lcd.h"

#define P_GAIN 0.999

DigitalOut Dir(p21);
PwmOut Step(p22);
DigitalOut MS1(p27);
DigitalOut MS2(p28);
DigitalOut MS3(p29);
AnalogIn Pot1(p19);
AnalogIn Pot2(p20);
C12832_LCD lcd;

BusIn Joystick(p12,p13,p14,p15,p16);
DigitalIn Up(p15);
DigitalIn Down(p12);
int main()
{
    float setpoint = 10000; //Frequentie 
    float step_freq1 = 1;
    float step_freq2 = 1;
   
    MS1 = 1;
    MS2 = 0;
    MS3 = 0;
    //float p1;
    int p2; 
    

    Step.period(1.); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer.
    Step.write(0.5); // Duty cycle van 50%
    Dir = Pot2; // Dir 1 is naar boven, Dir 0 naar onder.
    while (1) {
        
        p2 = Pot2.read();   
        float new_step_freq1;
        float new_step_freq2;
        
        if (Dir = 1){
        step_freq2 = 1;
        new_step_freq1 = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq1);
        step_freq1 = new_step_freq1;
        Step.period(1.0/(step_freq1));
        //lcd.printf("Snelheid : %f Hz\n", p1);
        lcd.printf("Richting : %d \n", p2); 
        wait(0.01); //Hier nog ticker inbouwen
        }
        if (Dir = 0) {
        step_freq1 = 1;
        new_step_freq2 = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq2);
        step_freq2 = new_step_freq2;
        Step.period(1.0/(step_freq2));
        //lcd.printf("Snelheid : %f Hz\n", p1);
        lcd.printf("Richting : %d \n", p2); 
        wait(0.01); //Hier nog ticker inbouwen
        
        }
        

    }
}