![](/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
main.cpp@14:bbef6e8956dc, 2015-04-28 (annotated)
- Committer:
- jessekaiser
- Date:
- Tue Apr 28 15:34:41 2015 +0000
- Revision:
- 14:bbef6e8956dc
- Parent:
- 13:c4e80f6e7113
Poging tot directie controle waarbij de motor opnieuw start met accelereren
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jessekaiser | 0:3acdd563582f | 1 | #include "mbed.h" |
jessekaiser | 10:7f94cd65c910 | 2 | #include "C12832_lcd.h" |
jessekaiser | 0:3acdd563582f | 3 | |
jessekaiser | 14:bbef6e8956dc | 4 | #define P_GAIN 0.999 |
jessekaiser | 11:74ae4e5e11ab | 5 | |
jessekaiser | 0:3acdd563582f | 6 | DigitalOut Dir(p21); |
jessekaiser | 0:3acdd563582f | 7 | PwmOut Step(p22); |
jessekaiser | 0:3acdd563582f | 8 | DigitalOut MS1(p27); |
jessekaiser | 0:3acdd563582f | 9 | DigitalOut MS2(p28); |
jessekaiser | 0:3acdd563582f | 10 | DigitalOut MS3(p29); |
jessekaiser | 10:7f94cd65c910 | 11 | AnalogIn Pot1(p19); |
jessekaiser | 13:c4e80f6e7113 | 12 | AnalogIn Pot2(p20); |
jessekaiser | 10:7f94cd65c910 | 13 | C12832_LCD lcd; |
jessekaiser | 0:3acdd563582f | 14 | |
jessekaiser | 10:7f94cd65c910 | 15 | BusIn Joystick(p12,p13,p14,p15,p16); |
jessekaiser | 10:7f94cd65c910 | 16 | DigitalIn Up(p15); |
jessekaiser | 10:7f94cd65c910 | 17 | DigitalIn Down(p12); |
jessekaiser | 0:3acdd563582f | 18 | int main() |
jessekaiser | 0:3acdd563582f | 19 | { |
jessekaiser | 14:bbef6e8956dc | 20 | float setpoint = 10000; //Frequentie |
jessekaiser | 14:bbef6e8956dc | 21 | float step_freq1 = 1; |
jessekaiser | 14:bbef6e8956dc | 22 | float step_freq2 = 1; |
jessekaiser | 14:bbef6e8956dc | 23 | |
jessekaiser | 4:e4341e3524dc | 24 | MS1 = 1; |
jessekaiser | 2:92a63245d11c | 25 | MS2 = 0; |
jessekaiser | 2:92a63245d11c | 26 | MS3 = 0; |
jessekaiser | 14:bbef6e8956dc | 27 | //float p1; |
jessekaiser | 14:bbef6e8956dc | 28 | int p2; |
jessekaiser | 13:c4e80f6e7113 | 29 | |
jessekaiser | 0:3acdd563582f | 30 | |
jessekaiser | 14:bbef6e8956dc | 31 | Step.period(1.); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer. |
jessekaiser | 9:649229691351 | 32 | Step.write(0.5); // Duty cycle van 50% |
jessekaiser | 14:bbef6e8956dc | 33 | Dir = Pot2; // Dir 1 is naar boven, Dir 0 naar onder. |
jessekaiser | 0:3acdd563582f | 34 | while (1) { |
jessekaiser | 14:bbef6e8956dc | 35 | |
jessekaiser | 14:bbef6e8956dc | 36 | p2 = Pot2.read(); |
jessekaiser | 14:bbef6e8956dc | 37 | float new_step_freq1; |
jessekaiser | 14:bbef6e8956dc | 38 | float new_step_freq2; |
jessekaiser | 14:bbef6e8956dc | 39 | |
jessekaiser | 14:bbef6e8956dc | 40 | if (Dir = 1){ |
jessekaiser | 14:bbef6e8956dc | 41 | step_freq2 = 1; |
jessekaiser | 14:bbef6e8956dc | 42 | new_step_freq1 = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq1); |
jessekaiser | 14:bbef6e8956dc | 43 | step_freq1 = new_step_freq1; |
jessekaiser | 14:bbef6e8956dc | 44 | Step.period(1.0/(step_freq1)); |
jessekaiser | 14:bbef6e8956dc | 45 | //lcd.printf("Snelheid : %f Hz\n", p1); |
jessekaiser | 14:bbef6e8956dc | 46 | lcd.printf("Richting : %d \n", p2); |
jessekaiser | 14:bbef6e8956dc | 47 | wait(0.01); //Hier nog ticker inbouwen |
jessekaiser | 14:bbef6e8956dc | 48 | } |
jessekaiser | 14:bbef6e8956dc | 49 | if (Dir = 0) { |
jessekaiser | 14:bbef6e8956dc | 50 | step_freq1 = 1; |
jessekaiser | 14:bbef6e8956dc | 51 | new_step_freq2 = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq2); |
jessekaiser | 14:bbef6e8956dc | 52 | step_freq2 = new_step_freq2; |
jessekaiser | 14:bbef6e8956dc | 53 | Step.period(1.0/(step_freq2)); |
jessekaiser | 14:bbef6e8956dc | 54 | //lcd.printf("Snelheid : %f Hz\n", p1); |
jessekaiser | 14:bbef6e8956dc | 55 | lcd.printf("Richting : %d \n", p2); |
jessekaiser | 14:bbef6e8956dc | 56 | wait(0.01); //Hier nog ticker inbouwen |
jessekaiser | 14:bbef6e8956dc | 57 | |
jessekaiser | 14:bbef6e8956dc | 58 | } |
jessekaiser | 14:bbef6e8956dc | 59 | |
jessekaiser | 10:7f94cd65c910 | 60 | |
jessekaiser | 0:3acdd563582f | 61 | } |
jessekaiser | 0:3acdd563582f | 62 | } |