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-06-05
Revision:
47:150924ff4b2c
Parent:
46:7a7cb589579a
Child:
48:05adf4978828

File content as of revision 47:150924ff4b2c:

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

#define P_GAIN 0.998

DigitalOut Dir1(p21);
PwmOut Step1(p22);
DigitalOut Dir2(p23);
PwmOut Step2(p24);
DigitalOut Enable2(p25);
DigitalOut Enable1(p26);
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()
{
    Enable1 = 1;
    Enable2 = 1;
    float setpoint = 1500; //Frequentie
    float step_freq1 = 1;
    float step_freq2 = 1;
    MS1 = 1;
    MS2 = 0;
    MS3 = 0;
    //Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer.
    Step1.write(0.5); // Duty cycle van 50%
    Step2.write(0.5);
    // Dir = Pot1; // Dir 1 is naar boven, Dir 0 naar onder.
    Enable1 = 0;
    Enable2 = 0;
    while (1) {
        Dir1 = 0; //0 Naar links (grote motor)
        float new_step_freq1;
        new_step_freq1 = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq1);
        step_freq1 = new_step_freq1;
        Step1.period(1.0/step_freq1);

        Dir2 = 0; //0 Naar onder (kleine motor)
        float new_step_freq2;
        new_step_freq2 = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq2);
        step_freq2 = new_step_freq2;
        Step2.period(1.0/step_freq2);

        lcd.printf("freq : %.0f, %.0f \n", step_freq1, step_freq2);
        wait(0.01); //Hier nog ticker inbouwen

    }
}