![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
4 directional EMG control of the XY table. Made during my bachelor end assignment.
Dependencies: C12832_lcd HIDScope mbed-dsp mbed
Diff: main.cpp
- Revision:
- 17:03f523424eb2
- Parent:
- 16:cdb6d66c2c4e
- Child:
- 18:71a01477e264
diff -r cdb6d66c2c4e -r 03f523424eb2 main.cpp --- a/main.cpp Wed Apr 29 13:15:26 2015 +0000 +++ b/main.cpp Wed Apr 29 14:57:07 2015 +0000 @@ -19,33 +19,33 @@ int main() { Enable = 0; - float setpoint = 1000; //Frequentie + float setpoint = 7000; //Frequentie float step_freq = 1; MS1 = 1; MS2 = 0; MS3 = 0; float p1; - int p2; + int dir1; - //Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer. + Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer. Step.write(0.5); // Duty cycle van 50% // Dir = Pot1; // Dir 1 is naar boven, Dir 0 naar onder. Enable = 1; while (1) { if (p1 < 0) { //Directie controle. - p2 = 0; + Dir = 0; } else if (p1 > 0) { - p2 = 1; + Dir = 1; } - p1 = Pot1.read() - 0.50; - Dir = p2; + p1 = Pot1.read() - 0.500; //Offset creëren [-0.500;0.500] + //Dir = dir1; float new_step_freq; - new_step_freq = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq); - step_freq = new_step_freq; - Step.period(1.0/step_freq); - - wait(0.01); //Hier nog ticker inbouwen + //new_step_freq = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq); + new_step_freq = (setpoint*p1*2); + step_freq = abs(new_step_freq); //Geeft een frequentie in 100 stappen. + Step.period(1.0/step_freq); + wait(0.1); //Hier nog ticker inbouwen lcd.printf("Spd %.0f Hz p1 %.2f \n", step_freq, p1); //snelheid meting op lcd, zonder decimalen }